Skip to content

Commit c7a8114

Browse files
committed
docs: document bash process helpers
1 parent ef17cec commit c7a8114

6 files changed

Lines changed: 25 additions & 0 deletions

src/agents/bash-process-references.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { listRunningSessions } from "./bash-process-registry.js";
22
import { deriveSessionName } from "./bash-tools.shared.js";
33

4+
// Builds compact references for currently running background process sessions.
5+
// These references are surfaced to agents so they can reconnect to prior work.
46
const DEFAULT_ACTIVE_PROCESS_LIMIT = 8;
57
const MAX_COMMAND_LABEL_CHARS = 140;
68

@@ -27,6 +29,7 @@ function truncate(value: string, maxChars: number): string {
2729
return `${value.slice(0, Math.max(0, maxChars - 3))}...`;
2830
}
2931

32+
/** List active background process sessions for one scope key, newest first. */
3033
export function listActiveProcessSessionReferences(params: {
3134
scopeKey?: string;
3235
now?: number;

src/agents/bash-tools.exec-approval-followup-state.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
77
import type { ExecElevatedDefaults } from "./bash-tools.exec-types.js";
88

9+
// Short-lived in-memory handoff state for exec approval follow-up turns. The
10+
// handoff carries elevated defaults across the approval response without
11+
// persisting operator approval state longer than the TTL.
912
const EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX = "exec-approval-followup:";
1013
const EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_NONCE_MARKER = ":nonce:";
1114
const EXEC_APPROVAL_FOLLOWUP_RUNTIME_HANDOFF_TTL_MS = 5 * 60 * 1000;
@@ -66,6 +69,7 @@ function pruneExpiredExecApprovalFollowupRuntimeHandoffs(nowMs: number): void {
6669
}
6770
}
6871

72+
/** Build the idempotency key used for an exec approval follow-up. */
6973
export function buildExecApprovalFollowupIdempotencyKey(params: {
7074
approvalId: string;
7175
nonce?: string;
@@ -75,6 +79,7 @@ export function buildExecApprovalFollowupIdempotencyKey(params: {
7579
return nonce ? `${base}${EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_NONCE_MARKER}${nonce}` : base;
7680
}
7781

82+
/** Parse the approval id embedded in a follow-up idempotency key. */
7883
export function parseExecApprovalFollowupApprovalId(idempotencyKey: string): string | undefined {
7984
const normalized = normalizeOptionalString(idempotencyKey);
8085
if (!normalized?.startsWith(EXEC_APPROVAL_FOLLOWUP_IDEMPOTENCY_PREFIX)) {
@@ -85,6 +90,7 @@ export function parseExecApprovalFollowupApprovalId(idempotencyKey: string): str
8590
return normalizeOptionalString(nonceMarker >= 0 ? body.slice(0, nonceMarker) : body);
8691
}
8792

93+
/** Register a short-lived exec approval handoff for the next follow-up turn. */
8894
export function registerExecApprovalFollowupRuntimeHandoff(params: {
8995
approvalId: string;
9096
sessionKey: string;
@@ -121,6 +127,7 @@ export function registerExecApprovalFollowupRuntimeHandoff(params: {
121127
return { handoffId, idempotencyKey };
122128
}
123129

130+
/** Consume a matching handoff once, validating approval/session/idempotency data. */
124131
export function consumeExecApprovalFollowupRuntimeHandoff(params: {
125132
handoffId?: string;
126133
approvalId?: string;
@@ -150,12 +157,15 @@ export function consumeExecApprovalFollowupRuntimeHandoff(params: {
150157
entry.idempotencyKey !== idempotencyKey ||
151158
entry.sessionKey !== sessionKey
152159
) {
160+
// Handoffs are single-session capabilities; mismatched follow-up metadata
161+
// must not consume or expose the stored elevated defaults.
153162
return undefined;
154163
}
155164
execApprovalFollowupRuntimeHandoffs.delete(handoffId);
156165
return cloneExecApprovalFollowupRuntimeHandoff(entry);
157166
}
158167

168+
/** Clear exec approval follow-up handoffs between tests. */
159169
export function resetExecApprovalFollowupRuntimeHandoffsForTests(): void {
160170
execApprovalFollowupRuntimeHandoffs.clear();
161171
}

src/agents/bash-tools.exec-approval-request.runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { explainShellCommand, formatCommandSpans } from "../infra/command-explainer/index.js";
22
import type { ExecApprovalCommandSpan } from "../infra/exec-approvals.js";
33

4+
// Runtime wrapper for shell command highlighting in exec approval requests.
5+
/** Resolve command spans used to highlight exec approval prompts. */
46
export async function resolveExecApprovalCommandSpans(
57
command: string,
68
): Promise<ExecApprovalCommandSpan[] | undefined> {

src/agents/bash-tools.exec-host-node.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { ExecAsk, ExecSecurity } from "../infra/exec-approvals.js";
22
import type { ExecAutoReviewer } from "../infra/exec-auto-review.js";
33
import type { ExecElevatedDefaults } from "./bash-tools.exec-types.js";
44

5+
// Full parameter bundle for Node-hosted exec command execution. Keeping this
6+
// type centralized prevents the host/runtime boundary from drifting.
57
export type ExecuteNodeHostCommandParams = {
68
command: string;
79
workdir: string | undefined;

src/agents/bash-tools.exec-output.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const EXEC_NO_OUTPUT_PLACEHOLDER = "(no output)";
22

3+
// Rendering helpers for exec output/status updates.
4+
/** Render command output with a stable placeholder for empty output. */
35
export function renderExecOutputText(value: string | undefined): string {
46
return value || EXEC_NO_OUTPUT_PLACEHOLDER;
57
}
68

9+
/** Render the text shown in exec progress updates, including warnings first. */
710
export function renderExecUpdateText(params: { tailText?: string; warnings: string[] }): string {
811
const warningText = params.warnings.length ? `${params.warnings.join("\n")}\n\n` : "";
912
return warningText + renderExecOutputText(params.tailText);

src/agents/bash-tools.process-send-keys.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { deriveSessionName } from "./bash-tools.shared.js";
33
import { encodeKeySequence, hasCursorModeSensitiveKeys } from "./pty-keys.js";
44
import type { AgentToolResult } from "./runtime/index.js";
55

6+
// Process send-keys support for background PTY sessions. It encodes symbolic,
7+
// hex, and literal input before writing to a live session stdin.
68
export type WritableStdin = {
79
write: (data: string, cb?: (err?: Error | null) => void) => void;
810
end: () => void;
@@ -36,6 +38,7 @@ async function writeToStdin(stdin: WritableStdin, data: string) {
3638
});
3739
}
3840

41+
/** Encode and write requested key data into a running process session. */
3942
export async function handleProcessSendKeys(params: {
4043
sessionId: string;
4144
session: ProcessSession;
@@ -50,6 +53,8 @@ export async function handleProcessSendKeys(params: {
5053
literal: params.literal,
5154
};
5255
if (params.session.cursorKeyMode === "unknown" && hasCursorModeSensitiveKeys(request)) {
56+
// Arrow/keypad encodings depend on cursor key mode. Wait for startup output
57+
// to identify the mode before sending potentially wrong bytes.
5358
return failText(
5459
`Session ${params.sessionId} cursor key mode is not known yet. Poll or log until startup output appears, then retry send-keys.`,
5560
);

0 commit comments

Comments
 (0)