@namzu/sdk 69.3.0 → 70.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/dist/authorization/protected-paths.d.ts +24 -6
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +37 -9
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +30 -2
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +263 -0
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +30 -0
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +85 -0
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +1 -1
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/plugin/common-layout/read.js +2 -2
- package/dist/plugin/common-layout/read.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts +12 -0
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +82 -10
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/consent.d.ts +11 -0
- package/dist/plugin/hook-module/consent.d.ts.map +1 -1
- package/dist/plugin/hook-module/consent.js +31 -0
- package/dist/plugin/hook-module/consent.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +69 -23
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +1 -1
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +1 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/hook-module/scan.js +1 -1
- package/dist/plugin/hook-module/scan.js.map +1 -1
- package/dist/plugin/hook-module/worker-source.d.ts +5 -4
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
- package/dist/plugin/hook-module/worker-source.js +198 -28
- package/dist/plugin/hook-module/worker-source.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +1 -1
- package/dist/provider/side-request-reasoning.d.ts.map +1 -1
- package/dist/provider/side-request-reasoning.js +5 -1
- package/dist/provider/side-request-reasoning.js.map +1 -1
- package/dist/public-runtime.d.ts +3 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +3 -3
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +13 -2
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/failure.d.ts +12 -5
- package/dist/runtime/query/auto-review/failure.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/failure.js +42 -7
- package/dist/runtime/query/auto-review/failure.js.map +1 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +75 -10
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +21 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +57 -25
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/check-scope.d.ts +18 -0
- package/dist/runtime/query/turn/check-scope.d.ts.map +1 -0
- package/dist/runtime/query/turn/check-scope.js +90 -0
- package/dist/runtime/query/turn/check-scope.js.map +1 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +13 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +6 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -1
- package/dist/skills/inline-shell-host.js +8 -0
- package/dist/skills/inline-shell-host.js.map +1 -1
- package/dist/skills/inline-shell.d.ts +9 -1
- package/dist/skills/inline-shell.d.ts.map +1 -1
- package/dist/skills/inline-shell.js +78 -10
- package/dist/skills/inline-shell.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +2 -0
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +2 -1
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/types/permission/index.d.ts +11 -2
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +12 -2
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +7 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/package.json +1 -1
- package/src/authorization/protected-paths.ts +44 -9
- package/src/authorization/readonly-commands.ts +30 -2
- package/src/authorization/shell-lexer.ts +242 -0
- package/src/connector/web/guarded-fetch.ts +92 -0
- package/src/connector/web/index.ts +6 -1
- package/src/plugin/common-layout/read.ts +2 -2
- package/src/plugin/hook-module/capabilities.ts +94 -10
- package/src/plugin/hook-module/consent.ts +36 -0
- package/src/plugin/hook-module/host.ts +72 -21
- package/src/plugin/hook-module/index.ts +2 -0
- package/src/plugin/hook-module/scan.ts +2 -2
- package/src/plugin/hook-module/worker-source.ts +199 -28
- package/src/prompt/coding-agent-doctrine.ts +1 -1
- package/src/provider/side-request-reasoning.ts +5 -1
- package/src/public-runtime.ts +6 -0
- package/src/public-tools.ts +4 -1
- package/src/runtime/query/auto-review/classifier.ts +14 -2
- package/src/runtime/query/auto-review/failure.ts +52 -7
- package/src/runtime/query/executor.ts +74 -7
- package/src/runtime/query/review-policy.ts +72 -19
- package/src/runtime/query/turn/check-scope.ts +90 -0
- package/src/runtime/query/turn/outcome-ledger.ts +11 -0
- package/src/skills/inline-shell-host.ts +16 -0
- package/src/skills/inline-shell.ts +90 -8
- package/src/tools/builtins/job.ts +4 -1
- package/src/tools/builtins/skill.ts +2 -0
- package/src/tools/builtins/wait-for-job.ts +3 -1
- package/src/types/permission/index.ts +20 -3
- package/src/types/tool/index.ts +7 -0
|
@@ -117,6 +117,7 @@ import { seedObservationLedger } from './file-evidence-seed.js'
|
|
|
117
117
|
import { DEFAULT_TOOL_RESULT_GUARDRAILS } from './guardrail-presets.js'
|
|
118
118
|
import { declaredWriteEscalation, shellEscalations } from './path-escalation.js'
|
|
119
119
|
import type { ToolResultObservation } from './project-instructions.js'
|
|
120
|
+
import { CLASSIFY_NESTED_REFUSAL, allowedCallTooWide } from './review-policy.js'
|
|
120
121
|
import { savedPresentation } from './saved-presentation.js'
|
|
121
122
|
import { ToolCallBudget, assertMaxToolCalls } from './tool-call-budget.js'
|
|
122
123
|
import {
|
|
@@ -2375,14 +2376,34 @@ export class ToolExecutor {
|
|
|
2375
2376
|
// The mode the turn is decided under answers a nested call as it answers the same
|
|
2376
2377
|
// call made directly: the tool that made this one reads, so the policy never saw it.
|
|
2377
2378
|
// Asked only when there is a mode to answer to: with none, the call is decided as before.
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2379
|
+
// Asked again right before the call starts (below), because a hook or the person can
|
|
2380
|
+
// change the mode while the earlier steps wait.
|
|
2381
|
+
const askMode = (): string | undefined => {
|
|
2382
|
+
const mode = this.config.reviewMode?.()
|
|
2383
|
+
return mode === undefined
|
|
2381
2384
|
? undefined
|
|
2382
|
-
: nestedCallModeRefusal(
|
|
2385
|
+
: nestedCallModeRefusal(mode, {
|
|
2383
2386
|
readOnly: isTrustedReadOnly(nestedTool, preparedInput, this.toolSource(name)),
|
|
2384
2387
|
allowedByRule: gateResult?.decision === 'allow' && gateResult.matchedRule !== null,
|
|
2388
|
+
ruleTooWide:
|
|
2389
|
+
gateResult?.decision === 'allow' &&
|
|
2390
|
+
allowedCallTooWide({
|
|
2391
|
+
name,
|
|
2392
|
+
tool: nestedTool,
|
|
2393
|
+
input: preparedInput,
|
|
2394
|
+
allowRule: gateResult.matchedRule,
|
|
2395
|
+
}),
|
|
2385
2396
|
})
|
|
2397
|
+
}
|
|
2398
|
+
const modeRefusal = askMode()
|
|
2399
|
+
// A model loaded the text that made this call, and auto mode would have sent the call
|
|
2400
|
+
// to its reviewer: it is not run and not a failure. The model is asked to make the call
|
|
2401
|
+
// itself (see `ToolDispatchOptions.handOff`), where the reviewer does see it. A rule's
|
|
2402
|
+
// deny still fails the load, and so does every other mode's refusal.
|
|
2403
|
+
const handedOff =
|
|
2404
|
+
options?.handOff === true &&
|
|
2405
|
+
modeRefusal === CLASSIFY_NESTED_REFUSAL &&
|
|
2406
|
+
gateResult?.decision !== 'deny'
|
|
2386
2407
|
const runGranted =
|
|
2387
2408
|
modeRefusal === undefined &&
|
|
2388
2409
|
gateResult?.decision === 'review' &&
|
|
@@ -2394,8 +2415,20 @@ export class ToolExecutor {
|
|
|
2394
2415
|
modeRefusal !== undefined ||
|
|
2395
2416
|
(gateResult && gateResult.decision !== 'allow' && !runGranted)
|
|
2396
2417
|
) {
|
|
2418
|
+
// A hand-off still asks the caller's last word first: a guard that refuses the
|
|
2419
|
+
// command at load must not lose to the model's own call, which the classifier
|
|
2420
|
+
// decides without that guard. A refusal is the answer, and nothing is handed off.
|
|
2421
|
+
if (handedOff && options?.beforeRun) {
|
|
2422
|
+
const refusal = await options.beforeRun({ name, input: preparedInput, toolUseId: nestedId })
|
|
2423
|
+
signal.throwIfAborted()
|
|
2424
|
+
if (refusal !== undefined) {
|
|
2425
|
+
await progress.close()
|
|
2426
|
+
return { success: false, output: '', error: refusal }
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2397
2429
|
const reason =
|
|
2398
|
-
modeRefusal !== undefined
|
|
2430
|
+
modeRefusal !== undefined &&
|
|
2431
|
+
!(modeRefusal === CLASSIFY_NESTED_REFUSAL && gateResult?.decision === 'deny')
|
|
2399
2432
|
? `Blocked: ${modeRefusal}.`
|
|
2400
2433
|
: nestedEscalation
|
|
2401
2434
|
? 'Blocked: this nested call reaches a protected path, removal floor, outside-root boundary or another safety escalation. Call it directly so it can be reviewed.'
|
|
@@ -2403,7 +2436,9 @@ export class ToolExecutor {
|
|
|
2403
2436
|
? `Blocked: "${name}" requires the person's approval for every call, and an approval cannot be requested from inside another tool. Call it directly.`
|
|
2404
2437
|
: gateResult?.decision === 'deny'
|
|
2405
2438
|
? `Blocked by the authorization gate: ${gateResult.reason}`
|
|
2406
|
-
:
|
|
2439
|
+
: gateResult?.matchedRule === null
|
|
2440
|
+
? `Blocked by the authorization gate: this nested call requires an explicit allow rule because an operator review cannot be opened from inside another tool. ${gateResult.reason}`
|
|
2441
|
+
: `Blocked by the authorization gate: a rule or safety check asked for this call, an operator review cannot be opened from inside another tool, and no allow rule lifts that: call it directly so a person can review it. ${gateResult?.reason}`
|
|
2407
2442
|
const output = deniedToolOutput(name, reason)
|
|
2408
2443
|
// Same fail-closed durability rule as a direct gate denial: if the
|
|
2409
2444
|
// configured session log cannot record the refusal, do not quietly carry
|
|
@@ -2438,7 +2473,12 @@ export class ToolExecutor {
|
|
|
2438
2473
|
outputLength: output.length,
|
|
2439
2474
|
...(via ? { via } : {}),
|
|
2440
2475
|
})
|
|
2441
|
-
return {
|
|
2476
|
+
return {
|
|
2477
|
+
success: false,
|
|
2478
|
+
output: '',
|
|
2479
|
+
error: reason,
|
|
2480
|
+
...(handedOff ? { data: { handedOff: true } } : {}),
|
|
2481
|
+
}
|
|
2442
2482
|
}
|
|
2443
2483
|
|
|
2444
2484
|
// A review approved the PARENT's escalation, as the parent's input
|
|
@@ -2532,6 +2572,33 @@ export class ToolExecutor {
|
|
|
2532
2572
|
return { success: false, output: '', error: message }
|
|
2533
2573
|
}
|
|
2534
2574
|
|
|
2575
|
+
// The mode is read once more, after the hooks and the veto had their time: a switch
|
|
2576
|
+
// to a stricter one in that window must still stop this call before it starts.
|
|
2577
|
+
const lateRefusal = askMode()
|
|
2578
|
+
if (lateRefusal !== undefined) {
|
|
2579
|
+
const message = `Blocked: ${lateRefusal}.`
|
|
2580
|
+
if (this.config.recordAudit) {
|
|
2581
|
+
await this.config.recordAudit({
|
|
2582
|
+
what: { action: 'tool_call', tool: name },
|
|
2583
|
+
outcome: 'refused',
|
|
2584
|
+
reason: message,
|
|
2585
|
+
})
|
|
2586
|
+
}
|
|
2587
|
+
await progress.close()
|
|
2588
|
+
await this.emitEvent({
|
|
2589
|
+
type: 'tool_completed',
|
|
2590
|
+
turnId: this.config.turnId,
|
|
2591
|
+
toolUseId: nestedId,
|
|
2592
|
+
toolName: name,
|
|
2593
|
+
result: deniedToolOutput(name, message),
|
|
2594
|
+
isError: true,
|
|
2595
|
+
durationMs: Date.now() - startedAt,
|
|
2596
|
+
outputLength: message.length,
|
|
2597
|
+
...(via ? { via } : {}),
|
|
2598
|
+
})
|
|
2599
|
+
return { success: false, output: '', error: message }
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2535
2602
|
let result: ToolResult
|
|
2536
2603
|
try {
|
|
2537
2604
|
// Use the same deadline layer as a model-issued call. Calling the
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import { homedir } from 'node:os'
|
|
25
25
|
import { dirname, parse } from 'node:path'
|
|
26
26
|
|
|
27
|
+
import { allowRuleScope } from '../../authorization/gate.js'
|
|
27
28
|
import { unknownProgramInLine } from '../../authorization/program.js'
|
|
28
29
|
import type { ShellWord } from '../../authorization/shell-lexer.js'
|
|
29
30
|
import {
|
|
@@ -35,6 +36,7 @@ import { effectiveBashWorkingDirectory } from '../../tools/builtins/bash-cwd.js'
|
|
|
35
36
|
import { BashTool } from '../../tools/builtins/bash.js'
|
|
36
37
|
import { isTrustedReadOnly } from '../../tools/trusted-read-only.js'
|
|
37
38
|
import type { ToolManager } from '../../toolsets/manager.js'
|
|
39
|
+
import type { AuthorizationRule } from '../../types/authorization/index.js'
|
|
38
40
|
import type {
|
|
39
41
|
HITLResumeDecision,
|
|
40
42
|
LaunchedScript,
|
|
@@ -47,11 +49,13 @@ import type {
|
|
|
47
49
|
import type { ApprovalPolicy } from '../../types/hitl/policy.js'
|
|
48
50
|
import type { SessionId, TurnId } from '../../types/ids/index.js'
|
|
49
51
|
import {
|
|
52
|
+
CLASSIFY_NESTED_REFUSAL,
|
|
50
53
|
PLAN_MODE_REFUSAL,
|
|
51
54
|
PLAN_MODE_REFUSAL_WITH_PLAN_FILE,
|
|
52
55
|
STRICT_MODE_REFUSAL,
|
|
53
56
|
nestedCallModeRefusal,
|
|
54
57
|
} from '../../types/permission/index.js'
|
|
58
|
+
import type { ToolDefinition } from '../../types/tool/index.js'
|
|
55
59
|
import type { AutoReviewClassifier, AutoReviewDecision } from './auto-review/classifier.js'
|
|
56
60
|
import {
|
|
57
61
|
autoReviewBlockedFeedback,
|
|
@@ -151,6 +155,7 @@ export function isReviewMode(value: unknown): value is ReviewMode {
|
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
export {
|
|
158
|
+
CLASSIFY_NESTED_REFUSAL,
|
|
154
159
|
PLAN_MODE_REFUSAL,
|
|
155
160
|
PLAN_MODE_REFUSAL_WITH_PLAN_FILE,
|
|
156
161
|
STRICT_MODE_REFUSAL,
|
|
@@ -530,6 +535,32 @@ const CLASSIFIER_DELEGATION_TOOLS: ReadonlySet<string> = new Set([
|
|
|
530
535
|
'continue_task',
|
|
531
536
|
])
|
|
532
537
|
|
|
538
|
+
/**
|
|
539
|
+
* Whether an allow rule is one `classify` should not defer to for this call: the
|
|
540
|
+
* rule covers a whole shell tool, the line starts an interpreter or a launcher
|
|
541
|
+
* that runs whatever it is given, or the tool starts other agents. Judged on the
|
|
542
|
+
* call as well as the rule because a rule that names a program ("python") is a
|
|
543
|
+
* rule about a program that can run anything. A nested call is judged the same
|
|
544
|
+
* way, so a skill's command is held to what a direct one is.
|
|
545
|
+
*/
|
|
546
|
+
export function allowedCallTooWide(call: {
|
|
547
|
+
readonly name: string
|
|
548
|
+
readonly tool: Pick<ToolDefinition, 'commandArgument' | 'commandDialect'> | undefined
|
|
549
|
+
readonly input: unknown
|
|
550
|
+
readonly allowScope?: 'tool' | 'pattern' | undefined
|
|
551
|
+
/** The rule that allowed it, when the caller has the gate's verdict and not the scope. */
|
|
552
|
+
readonly allowRule?: AuthorizationRule | null
|
|
553
|
+
}): boolean {
|
|
554
|
+
if (CLASSIFIER_DELEGATION_TOOLS.has(call.name.toLowerCase())) return true
|
|
555
|
+
const argument = call.tool?.commandArgument
|
|
556
|
+
if (call.tool === undefined || argument === undefined) return false
|
|
557
|
+
if ((call.allowScope ?? allowRuleScope(call.allowRule ?? null)) === 'tool') return true
|
|
558
|
+
const line = (call.input as Record<string, unknown> | null)?.[argument]
|
|
559
|
+
if (typeof line !== 'string') return true
|
|
560
|
+
const reading = readShellLine(line, call.tool.commandDialect?.({ sandboxed: false }) ?? 'sh')
|
|
561
|
+
return !reading.complete || reading.invocations.some(launchesCode)
|
|
562
|
+
}
|
|
563
|
+
|
|
533
564
|
/** The shell commands `accept-edits` also approves, when every path they name is inside the roots. */
|
|
534
565
|
export const ACCEPT_EDITS_SHELL_COMMANDS: ReadonlySet<string> = new Set([
|
|
535
566
|
'mkdir',
|
|
@@ -546,7 +577,7 @@ export const ACCEPT_EDITS_SHELL_COMMANDS: ReadonlySet<string> = new Set([
|
|
|
546
577
|
* the first time in a session and nobody can be asked.
|
|
547
578
|
*/
|
|
548
579
|
export const SCREEN_CONSENT_UNATTENDED_REFUSAL =
|
|
549
|
-
"Refused: this call would send what is on the user's screen to the model provider, which a person agrees to once per session, and nobody can be asked in this session. Nothing in this batch ran. Tell the user computer use needs their consent in an interactive session."
|
|
580
|
+
"Refused: this call would send what is on the user's screen to the model provider, which a person agrees to once per session, and nobody can be asked in this session. Nothing in this batch ran. Do not try again in this run, and do not reach the screen another way. Tell the user computer use needs their consent in an interactive session, or a rule that allows this call by name."
|
|
550
581
|
|
|
551
582
|
/** What the model is told when the operator declines to share the screen. */
|
|
552
583
|
export const SCREEN_CONSENT_DECLINED_FEEDBACK =
|
|
@@ -1161,17 +1192,13 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1161
1192
|
* Judged on the call as well as the rule because a rule that names a
|
|
1162
1193
|
* program ("python") is a rule about a program that can run anything.
|
|
1163
1194
|
*/
|
|
1164
|
-
const allowRuleTooWide = (tc: ToolCallSummary): boolean =>
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
if (typeof line !== 'string') return true
|
|
1172
|
-
const reading = readShellLine(line, tool.commandDialect?.({ sandboxed: false }) ?? 'sh')
|
|
1173
|
-
return !reading.complete || reading.invocations.some(launchesCode)
|
|
1174
|
-
}
|
|
1195
|
+
const allowRuleTooWide = (tc: ToolCallSummary): boolean =>
|
|
1196
|
+
allowedCallTooWide({
|
|
1197
|
+
name: tc.name,
|
|
1198
|
+
tool: toolOf(tc.name),
|
|
1199
|
+
input: tc.input,
|
|
1200
|
+
allowScope: tc.authorization?.allowScope,
|
|
1201
|
+
})
|
|
1175
1202
|
|
|
1176
1203
|
/** Whether `classify` decides this call without the classifier: it would not be asked, or is plainly safe. */
|
|
1177
1204
|
const neverSent = async (tc: ToolCallSummary, sessionId?: string): Promise<boolean> => {
|
|
@@ -1219,12 +1246,15 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1219
1246
|
// below shows the whole batch, so its yes also answers any question
|
|
1220
1247
|
// the rest of this function would ask; nobody is asked twice.
|
|
1221
1248
|
let answered: ToolReviewAnswer | undefined
|
|
1222
|
-
const ask = async (
|
|
1249
|
+
const ask = async (
|
|
1250
|
+
screenConsent?: true,
|
|
1251
|
+
shown?: readonly ToolCallSummary[],
|
|
1252
|
+
): Promise<ToolReviewAnswer> =>
|
|
1223
1253
|
answered ??
|
|
1224
1254
|
(prompt as ToolReviewPrompt)({
|
|
1225
1255
|
sessionId: request.sessionId,
|
|
1226
1256
|
turnId: request.turnId,
|
|
1227
|
-
toolCalls: request.toolCalls,
|
|
1257
|
+
toolCalls: shown ?? request.toolCalls,
|
|
1228
1258
|
...(screenConsent ? { screenConsent } : {}),
|
|
1229
1259
|
...(request.perCall ? { perCall: true as const } : {}),
|
|
1230
1260
|
...(request.perCall && context?.signal ? { signal: context.signal } : {}),
|
|
@@ -1238,7 +1268,9 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1238
1268
|
const sessionKey = String(request.sessionId ?? '')
|
|
1239
1269
|
if (
|
|
1240
1270
|
consent &&
|
|
1241
|
-
|
|
1271
|
+
// `auto` answers for a person who is there; with nobody to ask it cannot
|
|
1272
|
+
// answer for them, so the first look is refused in every mode.
|
|
1273
|
+
(mode !== 'auto' || !prompt) &&
|
|
1242
1274
|
!consent.sessions.has(sessionKey) &&
|
|
1243
1275
|
request.toolCalls.some(
|
|
1244
1276
|
(tc) =>
|
|
@@ -1330,8 +1362,11 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1330
1362
|
if (isPermissive(mode)) {
|
|
1331
1363
|
// A person's answer on the whole batch, as a decision. An escape is
|
|
1332
1364
|
// confirmed by id only here, only for a person's yes.
|
|
1333
|
-
const askPerson = async (
|
|
1334
|
-
|
|
1365
|
+
const askPerson = async (
|
|
1366
|
+
escapes: readonly string[],
|
|
1367
|
+
shown?: readonly ToolCallSummary[],
|
|
1368
|
+
): Promise<HITLResumeDecision> => {
|
|
1369
|
+
const answer = await ask(undefined, shown)
|
|
1335
1370
|
if (answer.kind === 'reject') {
|
|
1336
1371
|
return {
|
|
1337
1372
|
action: 'reject_tools',
|
|
@@ -1351,6 +1386,24 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1351
1386
|
if (mode === 'classify' && !classified) {
|
|
1352
1387
|
const classifier = options.classifier as AutoReviewClassifier
|
|
1353
1388
|
const transcript = context?.transcript() ?? []
|
|
1389
|
+
// When the check cannot give a verdict and a person is asked, the
|
|
1390
|
+
// question is about the calls nothing else settled. A read the static
|
|
1391
|
+
// rules already allow runs without a prompt; it is not put to the
|
|
1392
|
+
// person beside the call that is, so one outage does not turn every
|
|
1393
|
+
// glob and grep of a batch into something to approve.
|
|
1394
|
+
const unsettled = async (): Promise<readonly ToolCallSummary[]> => {
|
|
1395
|
+
const kept: ToolCallSummary[] = []
|
|
1396
|
+
for (const call of request.toolCalls) {
|
|
1397
|
+
if (
|
|
1398
|
+
call.authorization?.decision === 'deny' ||
|
|
1399
|
+
isBypassImmune(call) ||
|
|
1400
|
+
!(await neverSent(call, request.sessionId))
|
|
1401
|
+
) {
|
|
1402
|
+
kept.push(call)
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
return kept
|
|
1406
|
+
}
|
|
1354
1407
|
for (const tc of live) {
|
|
1355
1408
|
// The questions a person must answer are asked of a person, never of a model.
|
|
1356
1409
|
if (isBypassImmune(tc) || (await neverSent(tc, request.sessionId))) continue
|
|
@@ -1382,7 +1435,7 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1382
1435
|
reason: 'auto mode stopped: the conversation is too long for the safety check',
|
|
1383
1436
|
}
|
|
1384
1437
|
}
|
|
1385
|
-
return askPerson(escapes)
|
|
1438
|
+
return askPerson(escapes, await unsettled())
|
|
1386
1439
|
}
|
|
1387
1440
|
transcriptTooLong = false
|
|
1388
1441
|
// A check that could not be completed says nothing about the call,
|
|
@@ -1393,7 +1446,7 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
|
|
|
1393
1446
|
if (decision.cause === 'unavailable' || decision.cause === 'unreadable') {
|
|
1394
1447
|
if (prompt) {
|
|
1395
1448
|
options.onClassifierFellBack?.({ reason: decision.reason })
|
|
1396
|
-
return askPerson(escapes)
|
|
1449
|
+
return askPerson(escapes, await unsettled())
|
|
1397
1450
|
}
|
|
1398
1451
|
}
|
|
1399
1452
|
// With nobody to ask, a check that keeps giving no verdict ends the
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a later run of a check says what an earlier failed run of it would
|
|
3
|
+
* have said, had it passed.
|
|
4
|
+
*
|
|
5
|
+
* The outcome record keys a check by its command line, so the same suite run
|
|
6
|
+
* once for a single file and later for its whole folder, or once with a
|
|
7
|
+
* reporter flag and once with an environment variable, reads as two commands
|
|
8
|
+
* and the first failure would stand for the rest of the turn beside a final
|
|
9
|
+
* state that passes. A pass of a run that includes everything the failed run
|
|
10
|
+
* ran, with nothing narrowing it, settles the failure. Anything the reading
|
|
11
|
+
* cannot place (a different program, a different option, a path outside the
|
|
12
|
+
* later run's paths, a filter the later run adds) leaves the failure standing. A
|
|
13
|
+
* run under a different program prefix (a root-level `pnpm exec biome check` against an
|
|
14
|
+
* in-package `biome check`) is not matched and also leaves it standing.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Words of a command line; a quoted run is one word. */
|
|
18
|
+
function words(line: string): string[] {
|
|
19
|
+
const out: string[] = []
|
|
20
|
+
for (const match of line.matchAll(/'[^']*'|"[^"]*"|\S+/gu)) out.push(match[0])
|
|
21
|
+
return out
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Flags that narrow what a test run runs, with a value in the next word. */
|
|
25
|
+
const FILTER_WITH_VALUE = new Set(['-t', '--testNamePattern', '-k', '--grep', '-g'])
|
|
26
|
+
|
|
27
|
+
/** A file or folder; `@scope/package` names a workspace package, not a path. */
|
|
28
|
+
const looksLikePath = (word: string): boolean =>
|
|
29
|
+
!word.startsWith('-') &&
|
|
30
|
+
!word.startsWith('@') &&
|
|
31
|
+
(word.includes('/') || /\.[cm]?[jt]sx?$/u.test(word))
|
|
32
|
+
|
|
33
|
+
interface Scope {
|
|
34
|
+
readonly program: string
|
|
35
|
+
readonly options: readonly string[]
|
|
36
|
+
readonly paths: readonly string[]
|
|
37
|
+
readonly filtered: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function scopeOf(command: string): Scope | undefined {
|
|
41
|
+
const all = words(command)
|
|
42
|
+
while (all.length > 0 && /^[A-Za-z_]\w*=/u.test(all[0] as string)) all.shift()
|
|
43
|
+
const program: string[] = []
|
|
44
|
+
const options: string[] = []
|
|
45
|
+
const paths: string[] = []
|
|
46
|
+
let filtered = false
|
|
47
|
+
let seenPath = false
|
|
48
|
+
for (let at = 0; at < all.length; at++) {
|
|
49
|
+
const word = all[at] as string
|
|
50
|
+
if (word === '--') continue
|
|
51
|
+
if (FILTER_WITH_VALUE.has(word)) {
|
|
52
|
+
filtered = true
|
|
53
|
+
at++
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
if (/^--(?:testNamePattern|grep)=/u.test(word)) {
|
|
57
|
+
filtered = true
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
if (word.startsWith('--reporter')) {
|
|
61
|
+
// `--reporter=dot` and `--reporter dot` change how the answer is drawn, not what runs.
|
|
62
|
+
if (!word.includes('=')) at++
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
if (looksLikePath(word)) {
|
|
66
|
+
seenPath = true
|
|
67
|
+
paths.push(word.replace(/\/+$/u, ''))
|
|
68
|
+
} else if (word.startsWith('-') && program.length > 0) options.push(word)
|
|
69
|
+
else if (!seenPath) program.push(word)
|
|
70
|
+
else return undefined
|
|
71
|
+
}
|
|
72
|
+
if (program.length === 0) return undefined
|
|
73
|
+
return { program: program.join(' '), options: options.sort(), paths, filtered }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** True when a passing `later` run covers everything a failed `earlier` run ran. */
|
|
77
|
+
export function laterRunCovers(later: string, earlier: string): boolean {
|
|
78
|
+
const after = scopeOf(later)
|
|
79
|
+
const before = scopeOf(earlier)
|
|
80
|
+
if (after === undefined || before === undefined) return false
|
|
81
|
+
if (after.filtered || after.program !== before.program) return false
|
|
82
|
+
if (before.options.some((option) => !after.options.includes(option))) return false
|
|
83
|
+
// A run with no path names the whole of what its program checks, so it covers any
|
|
84
|
+
// earlier run of that program; an earlier path-less run is covered only by another.
|
|
85
|
+
if (after.paths.length === 0) return true
|
|
86
|
+
if (before.paths.length === 0) return false
|
|
87
|
+
return before.paths.every((path) =>
|
|
88
|
+
after.paths.some((held) => path === held || path.startsWith(`${held}/`)),
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type TurnOutcomeVerdict,
|
|
27
27
|
} from '../../../types/session/outcome.js'
|
|
28
28
|
import type { ToolFacts } from '../../../types/tool/index.js'
|
|
29
|
+
import { laterRunCovers } from './check-scope.js'
|
|
29
30
|
import { WRITING_TOOLS, isVerificationCommand } from './completion-audit.js'
|
|
30
31
|
|
|
31
32
|
/** A finished tool call as the ledger sees it. */
|
|
@@ -611,6 +612,13 @@ export class OutcomeLedger {
|
|
|
611
612
|
// Latest run of each distinct command, ordered by when it last ran.
|
|
612
613
|
this.checks.delete(key)
|
|
613
614
|
this.checks.set(key, state)
|
|
615
|
+
// A pass of a run that includes what an earlier failed run ran settles that
|
|
616
|
+
// failure: the line must not name it beside a final state that passes.
|
|
617
|
+
if (state.result === 'passed') {
|
|
618
|
+
for (const [held, check] of this.checks) {
|
|
619
|
+
if (check.result === 'failed' && laterRunCovers(key, held)) this.checks.delete(held)
|
|
620
|
+
}
|
|
621
|
+
}
|
|
614
622
|
if (this.checks.size > MAX_REMEMBERED_CHECKS) {
|
|
615
623
|
// A failing check is never the one forgotten.
|
|
616
624
|
for (const [candidate, held] of this.checks) {
|
|
@@ -639,6 +647,9 @@ export class OutcomeLedger {
|
|
|
639
647
|
if (facts.background === true || facts.continued === true || facts.timedOut === true) {
|
|
640
648
|
return { result: 'unsettled', ...withCode }
|
|
641
649
|
}
|
|
650
|
+
// Stopped by a signal (a job the operator or the model killed): it was cut
|
|
651
|
+
// short, not found wanting, so it neither passes nor fails.
|
|
652
|
+
if (facts.signal !== undefined && exitCode === undefined) return { result: 'unsettled' }
|
|
642
653
|
if (exitCode === undefined) {
|
|
643
654
|
return { result: call.isError === true ? 'failed' : 'unsettled' }
|
|
644
655
|
}
|
|
@@ -213,6 +213,12 @@ export interface ToolSkillShellHostOptions {
|
|
|
213
213
|
readonly context: ToolContext
|
|
214
214
|
readonly allow?: ToolDispatchOptions['allow']
|
|
215
215
|
readonly toolName?: string
|
|
216
|
+
/**
|
|
217
|
+
* The text is going to a model that can run a command in its own call. A command
|
|
218
|
+
* the turn's auto mode would send to its reviewer then comes back as a hand-off
|
|
219
|
+
* and the load goes on, where otherwise it fails.
|
|
220
|
+
*/
|
|
221
|
+
readonly handOff?: boolean
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
/**
|
|
@@ -240,6 +246,7 @@ export function createToolSkillShellHost(options: ToolSkillShellHostOptions): In
|
|
|
240
246
|
{ command },
|
|
241
247
|
{
|
|
242
248
|
...(options.allow ? { allow: options.allow } : {}),
|
|
249
|
+
...(options.handOff ? { handOff: true } : {}),
|
|
243
250
|
beforeRun: async () => {
|
|
244
251
|
const verdict = await beforeRun()
|
|
245
252
|
if (verdict.kind === 'run') return undefined
|
|
@@ -255,11 +262,20 @@ export function createToolSkillShellHost(options: ToolSkillShellHostOptions): In
|
|
|
255
262
|
throw error
|
|
256
263
|
}
|
|
257
264
|
if (hook !== undefined) return { kind: 'hook', verdict: hook }
|
|
265
|
+
if (!result.success && handedOff(result)) return { kind: 'handoff' }
|
|
258
266
|
return outcomeOf(result)
|
|
259
267
|
},
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
270
|
|
|
271
|
+
function handedOff(result: { readonly data?: unknown }): boolean {
|
|
272
|
+
return (
|
|
273
|
+
result.data !== null &&
|
|
274
|
+
typeof result.data === 'object' &&
|
|
275
|
+
(result.data as Record<string, unknown>).handedOff === true
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
263
279
|
/** A shell tool result as the host's outcome of one command. */
|
|
264
280
|
export function outcomeOf(result: {
|
|
265
281
|
readonly success: boolean
|
|
@@ -242,7 +242,7 @@ type ShellContext = 'none' | 'single' | 'double' | 'unsafe'
|
|
|
242
242
|
/**
|
|
243
243
|
* How the shell reads the position at the end of `prefix`, the text of one
|
|
244
244
|
* command up to a value: outside any quote, inside single or double quotes, or
|
|
245
|
-
* somewhere a value cannot be made safe (a comment, a dangling backslash
|
|
245
|
+
* somewhere a value cannot be made safe (a comment, a dangling backslash or a bare `$`, a here-document, a `${...}`, an
|
|
246
246
|
* arithmetic or backtick expansion, an ANSI-C string that is not closed).
|
|
247
247
|
*
|
|
248
248
|
* A `$( ... )` starts a fresh reading of its own, so a value inside one is
|
|
@@ -309,7 +309,9 @@ function shellContextAt(prefix: string): ShellContext {
|
|
|
309
309
|
i = end
|
|
310
310
|
wordStart = false
|
|
311
311
|
continue
|
|
312
|
-
}
|
|
312
|
+
} // A `$` right before the value would join its first character: `$` and a
|
|
313
|
+
// quote read as an ANSI-C string, `$` and `(` or a name as an expansion.
|
|
314
|
+
if (i === prefix.length - 1) return 'unsafe'
|
|
313
315
|
}
|
|
314
316
|
if (c === '`') {
|
|
315
317
|
const end = skipTo(i + 1, '`')
|
|
@@ -442,7 +444,7 @@ function quoteForCommand(value: string, prefix: string, dialect: ShellDialect):
|
|
|
442
444
|
if (context === 'unsafe' || value.includes('`')) {
|
|
443
445
|
throw new InlineShellError(
|
|
444
446
|
context === 'unsafe'
|
|
445
|
-
? 'A value given to this skill or command would land inside a here-document
|
|
447
|
+
? 'A value given to this skill or command would land inside a here-document, a ${...} or arithmetic expansion, or right after a bare $ of a shell command, where it cannot be quoted, so it was not loaded.'
|
|
446
448
|
: 'A value given to this skill or command contains a backtick, which cannot be put inside a shell command, so it was not loaded.',
|
|
447
449
|
'injection',
|
|
448
450
|
)
|
|
@@ -470,7 +472,7 @@ interface Occurrence {
|
|
|
470
472
|
* reads it as data ({@link quoteForCommand}), by where it sits: a person's
|
|
471
473
|
* `-n 5` stays two arguments, and `x; touch f #` stays words of an argument
|
|
472
474
|
* list. Throws {@link InlineShellError} when a value cannot be made safe, or the
|
|
473
|
-
* substituted text
|
|
475
|
+
* substituted text does not hold exactly the template's commands, in order.
|
|
474
476
|
*/
|
|
475
477
|
export function substituteEscaped(
|
|
476
478
|
template: string,
|
|
@@ -514,6 +516,8 @@ export function substituteEscaped(
|
|
|
514
516
|
return marker.kind === 'inline' ? marker.start + 2 : neutral.indexOf('\n', marker.start) + 1
|
|
515
517
|
}
|
|
516
518
|
let out = ''
|
|
519
|
+
// Where each value landed: its place in the neutral text (one character wide) and in the output.
|
|
520
|
+
const landed: Array<{ at: number; outAt: number; length: number }> = []
|
|
517
521
|
for (const piece of pieces) {
|
|
518
522
|
if (typeof piece === 'string') {
|
|
519
523
|
out += piece
|
|
@@ -521,7 +525,7 @@ export function substituteEscaped(
|
|
|
521
525
|
}
|
|
522
526
|
const value = values[piece.token] as string
|
|
523
527
|
const from = commandAt(piece.at)
|
|
524
|
-
|
|
528
|
+
const put =
|
|
525
529
|
from === undefined
|
|
526
530
|
? escapeBetween(value, piece.before, piece.after)
|
|
527
531
|
: quoteForCommand(
|
|
@@ -529,8 +533,26 @@ export function substituteEscaped(
|
|
|
529
533
|
neutral.slice(from, piece.at),
|
|
530
534
|
options.dialect ?? hostCommandShell().dialect,
|
|
531
535
|
)
|
|
536
|
+
landed.push({ at: piece.at, outAt: out.length, length: put.length })
|
|
537
|
+
out += put
|
|
538
|
+
}
|
|
539
|
+
// A neutral offset (a marker's edge) in the output text.
|
|
540
|
+
const inOutput = (at: number): number => {
|
|
541
|
+
let shift = 0
|
|
542
|
+
for (const place of landed) {
|
|
543
|
+
if (place.at >= at) break
|
|
544
|
+
shift += place.length - 1
|
|
545
|
+
}
|
|
546
|
+
return at + shift
|
|
532
547
|
}
|
|
533
|
-
|
|
548
|
+
// The commands the author wrote, values quoted in, are what must be there: the same
|
|
549
|
+
// ones, in the same order. A count would let a value that masks one command and
|
|
550
|
+
// creates another through.
|
|
551
|
+
const expected = markers.map(
|
|
552
|
+
(m) => `${m.kind}\u0000${out.slice(inOutput(m.start), inOutput(m.end))}`,
|
|
553
|
+
)
|
|
554
|
+
const found = findInlineShell(out).map((m) => `${m.kind}\u0000${m.raw}`)
|
|
555
|
+
if (expected.length !== found.length || expected.some((raw, index) => raw !== found[index])) {
|
|
534
556
|
throw new InlineShellError(
|
|
535
557
|
'A value given to this skill or command contains text that would start a shell command, so it was not loaded.',
|
|
536
558
|
'injection',
|
|
@@ -571,6 +593,12 @@ export type InlineShellHookVerdict =
|
|
|
571
593
|
export type InlineShellOutcome =
|
|
572
594
|
/** The permission rules said no, or would have asked a person who is not there. */
|
|
573
595
|
| { readonly kind: 'denied'; readonly reason: string }
|
|
596
|
+
/**
|
|
597
|
+
* Not run here: the session's auto-mode reviewer judges only the commands the model
|
|
598
|
+
* runs itself, so the text asks the model to run this one in its own `bash` call and
|
|
599
|
+
* the load goes on. Only a host with a model to hand it to answers this.
|
|
600
|
+
*/
|
|
601
|
+
| { readonly kind: 'handoff' }
|
|
574
602
|
/** The hook, which runs after permission and before the shell, refused or stopped. */
|
|
575
603
|
| { readonly kind: 'hook'; readonly verdict: Exclude<InlineShellHookVerdict, { kind: 'run' }> }
|
|
576
604
|
| {
|
|
@@ -672,7 +700,10 @@ export async function expandInlineShell(
|
|
|
672
700
|
}
|
|
673
701
|
}
|
|
674
702
|
|
|
675
|
-
|
|
703
|
+
// A string is the text for that spot; a number is the place of a hand-off, whose note
|
|
704
|
+
// is final once the count is known. Never a marker inside the text, which could collide.
|
|
705
|
+
const replacements: (string | number)[] = []
|
|
706
|
+
const handedOff: string[] = []
|
|
676
707
|
let total = 0
|
|
677
708
|
for (const marker of markers) {
|
|
678
709
|
options.signal?.throwIfAborted()
|
|
@@ -688,6 +719,11 @@ export async function expandInlineShell(
|
|
|
688
719
|
'permission',
|
|
689
720
|
)
|
|
690
721
|
}
|
|
722
|
+
if (outcome.kind === 'handoff') {
|
|
723
|
+
handedOff.push(marker.command)
|
|
724
|
+
replacements.push(handedOff.length - 1)
|
|
725
|
+
continue
|
|
726
|
+
}
|
|
691
727
|
if (outcome.kind === 'hook') {
|
|
692
728
|
const verdict = outcome.verdict
|
|
693
729
|
if (verdict.kind === 'stop') {
|
|
@@ -731,7 +767,53 @@ export async function expandInlineShell(
|
|
|
731
767
|
replacements.push(shaped)
|
|
732
768
|
}
|
|
733
769
|
let n = 0
|
|
734
|
-
|
|
770
|
+
if (handedOff.length === 0) {
|
|
771
|
+
return replaceMarkers(source, markers, () => replacements[n++] as string)
|
|
772
|
+
}
|
|
773
|
+
const { header, spot } = handOffNotes(handedOff)
|
|
774
|
+
const body = replaceMarkers(source, markers, () => {
|
|
775
|
+
const r = replacements[n++] as string | number
|
|
776
|
+
return typeof r === 'number' ? spot(r) : r
|
|
777
|
+
})
|
|
778
|
+
return header === '' ? body : `${header}\n\n${body}`
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** A command as it is written in a hand-off note: in backticks, or fenced when it holds a backtick or a newline. */
|
|
782
|
+
function fenced(command: string): string {
|
|
783
|
+
const longest = Math.max(0, ...(command.match(/`+/g) ?? []).map((run) => run.length))
|
|
784
|
+
const fence = '`'.repeat(Math.max(3, longest + 1))
|
|
785
|
+
return `${fence}\n${command}\n${fence}`
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* The hand-off notes for the commands a model is asked to run itself. One command: its
|
|
790
|
+
* note stands where the command was. Several: a short numbered list goes first (the
|
|
791
|
+
* header), and each spot names its number.
|
|
792
|
+
*/
|
|
793
|
+
function handOffNotes(commands: readonly string[]): {
|
|
794
|
+
header: string
|
|
795
|
+
spot: (index: number) => string
|
|
796
|
+
} {
|
|
797
|
+
const plain = (command: string) => !/[`\n]/.test(command)
|
|
798
|
+
if (commands.length === 1) {
|
|
799
|
+
const command = commands[0] as string
|
|
800
|
+
const lead = '[run this first, exactly as written, with the bash tool and use its output:'
|
|
801
|
+
const note = plain(command) ? `${lead} \`${command}\`]` : `${lead}]\n${fenced(command)}`
|
|
802
|
+
return { header: '', spot: () => note }
|
|
803
|
+
}
|
|
804
|
+
const head = `[Run these ${commands.length} commands first, exactly as written, with the bash tool, and use their output where each is named below. Run them one per call.]`
|
|
805
|
+
const list = commands.map((command, i) =>
|
|
806
|
+
plain(command) ? `${i + 1}. \`${command}\`` : `${i + 1}.\n${fenced(command)}`,
|
|
807
|
+
)
|
|
808
|
+
return {
|
|
809
|
+
header: [head, ...list].join('\n'),
|
|
810
|
+
spot: (i) => {
|
|
811
|
+
const command = commands[i] as string
|
|
812
|
+
return plain(command)
|
|
813
|
+
? `[output of command ${i + 1}, \`${command}\`]`
|
|
814
|
+
: `[output of command ${i + 1}]`
|
|
815
|
+
},
|
|
816
|
+
}
|
|
735
817
|
}
|
|
736
818
|
|
|
737
819
|
function replaceMarkers(
|
|
@@ -63,7 +63,10 @@ export const JobTool = defineTool({
|
|
|
63
63
|
const label =
|
|
64
64
|
input.action === 'list'
|
|
65
65
|
? 'List background jobs'
|
|
66
|
-
:
|
|
66
|
+
: // No id in the row: it is the model's handle on the job, not something the person reads.
|
|
67
|
+
input.action === 'kill'
|
|
68
|
+
? 'Stop background job'
|
|
69
|
+
: 'Read background output'
|
|
67
70
|
return { kind: 'generic', presentation: 'activity', label }
|
|
68
71
|
},
|
|
69
72
|
|