Skip to content

Commit 8d65e78

Browse files
committed
docs: document task command helpers
1 parent 726bc2b commit 8d65e78

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/commands/systemd-linger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Systemd lingering setup helpers for gateway install/start flows.
2+
// Lingering keeps user services alive after logout on Linux hosts.
3+
14
import { note } from "../../packages/terminal-core/src/note.js";
25
import {
36
enableSystemdUserLinger,
@@ -11,6 +14,7 @@ export type LingerPrompter = {
1114
note: (message: string, title?: string) => Promise<void> | void;
1215
};
1316

17+
/** Ensures systemd user lingering interactively, prompting before sudo when requested. */
1418
export async function ensureSystemdUserLingerInteractive(params: {
1519
runtime: RuntimeEnv;
1620
prompter?: LingerPrompter;
@@ -89,6 +93,7 @@ export async function ensureSystemdUserLingerInteractive(params: {
8993
await prompter.note(`Run manually: sudo loginctl enable-linger ${status.user}`, title);
9094
}
9195

96+
/** Best-effort non-interactive lingering enablement for install scripts and CI-like flows. */
9297
export async function ensureSystemdUserLingerNonInteractive(params: {
9398
runtime: RuntimeEnv;
9499
env?: NodeJS.ProcessEnv;

src/commands/tasks-audit-system.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Combines task and task-flow audit findings for CLI output.
2+
// The combined shape lets list/json commands filter and sort both registries together.
3+
14
import type {
25
TaskFlowAuditCode,
36
TaskFlowAuditFinding,
@@ -44,6 +47,7 @@ function compareSystemAuditFindings(left: TaskSystemAuditFinding, right: TaskSys
4447
);
4548
}
4649

50+
/** Builds combined task/task-flow audit findings with optional severity/code filtering. */
4751
export function buildTaskSystemAuditFindings(params: {
4852
taskFindings: TaskAuditFinding[];
4953
flowFindings: TaskFlowAuditFinding[];
@@ -83,6 +87,7 @@ export function buildTaskSystemAuditFindings(params: {
8387
return true;
8488
})
8589
.toSorted(compareSystemAuditFindings);
90+
// Keep summary counts based on the full sorted set; filters only affect displayed findings.
8691
const sortedAllFindings = [...allFindings].toSorted(compareSystemAuditFindings);
8792
return {
8893
allFindings: sortedAllFindings,

src/commands/tasks-json.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
// JSON-only task command helpers.
2+
// These paths avoid maintenance reconciliation so short-lived JSON CLI processes stay read-only and exit cleanly.
3+
14
import type { RuntimeEnv } from "../runtime.js";
25
import { writeRuntimeJson } from "../runtime.js";
36
import { listTaskRecords } from "../tasks/runtime-internal.js";
47
import { listTaskFlowAuditFindings } from "../tasks/task-flow-registry.audit.js";
58
import { listTaskFlowRecords } from "../tasks/task-flow-runtime-internal.js";
6-
import {
7-
listTaskAuditFindings,
8-
summarizeTaskAuditFindings,
9-
} from "../tasks/task-registry.audit.js";
9+
import { listTaskAuditFindings, summarizeTaskAuditFindings } from "../tasks/task-registry.audit.js";
1010
import type { TaskRecord } from "../tasks/task-registry.types.js";
1111
import {
1212
buildTaskSystemAuditFindings,
@@ -79,6 +79,7 @@ function buildTasksAuditJsonPayload(opts: TasksAuditJsonArgs) {
7979
});
8080
const limit = typeof opts.limit === "number" && opts.limit > 0 ? opts.limit : undefined;
8181
const displayed = limit ? filteredFindings.slice(0, limit) : filteredFindings;
82+
// Preserve the legacy task-only summary while adding combined task-flow counts.
8283
const legacySummary = summarizeTaskAuditFindings(taskFindings);
8384
return {
8485
count: allFindings.length,
@@ -102,13 +103,15 @@ function buildTasksAuditJsonPayload(opts: TasksAuditJsonArgs) {
102103
};
103104
}
104105

106+
/** Writes task list JSON without triggering task maintenance. */
105107
export async function tasksListJsonCommand(
106108
opts: TasksListJsonArgs,
107109
runtime: RuntimeEnv,
108110
): Promise<void> {
109111
writeRuntimeJson(runtime, buildTasksListJsonPayload(opts));
110112
}
111113

114+
/** Writes task audit JSON with combined task/task-flow findings. */
112115
export async function tasksAuditJsonCommand(
113116
opts: TasksAuditJsonArgs,
114117
runtime: RuntimeEnv,

src/commands/tasks.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Human-facing background task commands.
2+
// Handles task listing/show/cancel/notify/audit plus registry maintenance for tasks, flows, and sessions.
3+
14
import fs from "node:fs";
25
import { timestampMsToIsoString } from "@openclaw/normalization-core/number-coercion";
36
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
@@ -129,6 +132,7 @@ function buildSessionRegistryPreserveKeys(params: {
129132
for (const key of Object.keys(params.store)) {
130133
const jobId = parseCronRunSessionJobId(key);
131134
if (!jobId) {
135+
// Non-cron session rows are outside this maintenance pass; preserve them.
132136
preserveKeys.add(key);
133137
continue;
134138
}
@@ -161,6 +165,7 @@ async function runSessionRegistryMaintenance(params: {
161165
const beforeStore = loadSessionStore(target.storePath, { skipCache: true });
162166
const beforeCount = Object.keys(beforeStore).length;
163167
if (params.apply) {
168+
// Apply mode mutates each store atomically through updateSessionStore.
164169
const applied = await updateSessionStore(
165170
target.storePath,
166171
(store) => {
@@ -191,6 +196,7 @@ async function runSessionRegistryMaintenance(params: {
191196
continue;
192197
}
193198
const previewStore = structuredClone(beforeStore);
199+
// Preview mode runs pruning against a clone so dry-run output cannot change stores.
194200
const { preserveKeys, preservedRunning } = buildSessionRegistryPreserveKeys({
195201
store: previewStore,
196202
runningCronJobIds,
@@ -350,6 +356,7 @@ function toSystemAuditFindings(params: {
350356
severityFilter?: TaskSystemAuditSeverity;
351357
codeFilter?: TaskSystemAuditCode;
352358
}) {
359+
// Human audit reconciles inspectable tasks first so stale detached runs are reflected.
353360
const taskFindings = listTaskAuditFindings({ tasks: reconcileInspectableTasks() });
354361
const flowFindings = listTaskFlowAuditFindings();
355362
return buildTaskSystemAuditFindings({
@@ -360,6 +367,7 @@ function toSystemAuditFindings(params: {
360367
});
361368
}
362369

370+
/** Lists background tasks with optional runtime/status filters. */
363371
export async function tasksListCommand(
364372
opts: { json?: boolean; runtime?: string; status?: string },
365373
runtime: RuntimeEnv,
@@ -412,6 +420,7 @@ export async function tasksListCommand(
412420
}
413421
}
414422

423+
/** Shows one task record by id or lookup token. */
415424
export async function tasksShowCommand(
416425
opts: { json?: boolean; lookup: string },
417426
runtime: RuntimeEnv,
@@ -458,6 +467,7 @@ export async function tasksShowCommand(
458467
}
459468
}
460469

470+
/** Updates a task's notification policy. */
461471
export async function tasksNotifyCommand(
462472
opts: { lookup: string; notify: TaskNotifyPolicy },
463473
runtime: RuntimeEnv,
@@ -480,6 +490,7 @@ export async function tasksNotifyCommand(
480490
runtime.log(`Updated ${updated.taskId} notify policy to ${updated.notifyPolicy}.`);
481491
}
482492

493+
/** Cancels a detached task run by lookup token. */
483494
export async function tasksCancelCommand(opts: { lookup: string }, runtime: RuntimeEnv) {
484495
const task = reconcileTaskLookupToken(opts.lookup);
485496
if (!task) {
@@ -507,6 +518,7 @@ export async function tasksCancelCommand(opts: { lookup: string }, runtime: Runt
507518
);
508519
}
509520

521+
/** Prints or serializes combined task/task-flow audit findings. */
510522
export async function tasksAuditCommand(
511523
opts: {
512524
json?: boolean;
@@ -587,6 +599,7 @@ export async function tasksAuditCommand(
587599
}
588600
}
589601

602+
/** Previews or applies task, task-flow, and backing session-registry maintenance. */
590603
export async function tasksMaintenanceCommand(
591604
opts: { json?: boolean; apply?: boolean },
592605
runtime: RuntimeEnv,

0 commit comments

Comments
 (0)