@zergai/ztc 0.26.6-dev.202611240947 → 0.27.0-beta.1
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/README.md +629 -167
- package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +6 -1
- package/dist/agent/agent.d.ts +21 -15
- package/dist/agent/agent.js +389 -163
- package/dist/agent/backends/codex_app_server.d.ts +7 -1
- package/dist/agent/backends/codex_app_server.js +11 -1
- package/dist/agent/backends/gemini.js +22 -8
- package/dist/agent/commands/batch.js +8 -0
- package/dist/agent/commands/config.js +10 -0
- package/dist/agent/commands/environment.js +5 -5
- package/dist/agent/commands/goal.d.ts +1 -0
- package/dist/agent/commands/goal.js +2 -1
- package/dist/agent/commands/index.js +2 -1
- package/dist/agent/commands/manifest.js +4 -0
- package/dist/agent/commands/optimize.js +5 -2
- package/dist/agent/commands/pane_cli.d.ts +29 -0
- package/dist/agent/commands/pane_cli.js +303 -0
- package/dist/agent/commands/settings.js +13 -3
- package/dist/agent/commands/shannon.js +8 -0
- package/dist/agent/commands/update.js +15 -3
- package/dist/agent/commands/zerg.js +31 -1
- package/dist/agent/commands/ztc_pane.js +3 -1
- package/dist/agent/factory.d.ts +4 -0
- package/dist/agent/factory.js +11 -1
- package/dist/agent/loop_policy.d.ts +42 -5
- package/dist/agent/loop_policy.js +206 -3
- package/dist/agent/runtime/command_jobs.d.ts +5 -0
- package/dist/agent/runtime/command_jobs.js +241 -31
- package/dist/agent/runtime/command_wait.d.ts +2 -0
- package/dist/agent/runtime/command_wait.js +1 -0
- package/dist/agent/runtime/done_report.d.ts +18 -0
- package/dist/agent/runtime/done_report.js +130 -0
- package/dist/agent/runtime/execution_context.js +4 -1
- package/dist/agent/runtime/failure_cause.d.ts +2 -0
- package/dist/agent/runtime/failure_cause.js +35 -0
- package/dist/agent/runtime/policy.d.ts +14 -2
- package/dist/agent/runtime/policy.js +104 -12
- package/dist/agent/runtime/quiet_job.d.ts +18 -0
- package/dist/agent/runtime/quiet_job.js +48 -0
- package/dist/agent/runtime/recovery.d.ts +1 -5
- package/dist/agent/runtime/recovery.js +2 -44
- package/dist/agent/runtime/tool_runtime.d.ts +1 -0
- package/dist/agent/runtime/tool_runtime.js +2 -0
- package/dist/agent/subagent.js +6 -1
- package/dist/agent/tools/deferred.js +1 -0
- package/dist/agent/tools/index.d.ts +2 -0
- package/dist/agent/tools/index.js +1 -0
- package/dist/agent/tools/outcome.d.ts +15 -0
- package/dist/agent/tools/outcome.js +107 -0
- package/dist/agent/tools/pane.d.ts +2 -1
- package/dist/agent/tools/pane.js +21 -3
- package/dist/agent/tools/registry.js +2 -0
- package/dist/agent/tools/shell.d.ts +1 -0
- package/dist/agent/tools/shell.js +128 -17
- package/dist/agent/tools/sim_domain_tools.js +4 -2
- package/dist/agent/tools/supervision.js +4 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/command_context.js +5 -9
- package/dist/app/conversation_compaction.d.ts +4 -2
- package/dist/app/conversation_compaction.js +16 -5
- package/dist/app/headless_shell_mode.d.ts +14 -0
- package/dist/app/headless_shell_mode.js +7 -0
- package/dist/app/hosted_resident.d.ts +356 -0
- package/dist/app/hosted_resident.js +677 -0
- package/dist/app/restart.js +11 -2
- package/dist/app/session_manager.d.ts +5 -0
- package/dist/app/session_manager.js +21 -6
- package/dist/app/session_messages.js +6 -6
- package/dist/app/workspace_layout_controller.js +7 -0
- package/dist/batch/worktree.d.ts +10 -0
- package/dist/batch/worktree.js +15 -0
- package/dist/bench/registry.js +4 -2
- package/dist/cli_args.js +1 -1
- package/dist/cli_main.js +80 -10
- package/dist/cli_ratatui.d.ts +75 -0
- package/dist/cli_ratatui.js +485 -84
- package/dist/components/InputArea.js +4 -4
- package/dist/config/execution.d.ts +10 -0
- package/dist/config/execution.js +10 -0
- package/dist/config/hosted_runtime.d.ts +4 -1
- package/dist/config/hosted_runtime.js +4 -1
- package/dist/config/permission_pin.d.ts +34 -2
- package/dist/config/permission_pin.js +52 -2
- package/dist/config/person_command_policy.d.ts +38 -0
- package/dist/config/person_command_policy.js +11 -0
- package/dist/config/profiles.d.ts +21 -0
- package/dist/config/profiles.js +56 -2
- package/dist/config/types.d.ts +4 -1
- package/dist/config.js +34 -19
- package/dist/desktop/daily/codex_exec_adapter.js +7 -2
- package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
- package/dist/desktop/daily/desktop_wiring.js +11 -3
- package/dist/desktop/daily/recipes.js +20 -4
- package/dist/desktop/health.d.ts +24 -0
- package/dist/desktop/health.js +151 -0
- package/dist/desktop/native_dialogs.d.ts +37 -0
- package/dist/desktop/native_dialogs.js +105 -0
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +28 -0
- package/dist/embedded/registry.js +4 -2
- package/dist/emulation/tool_adapters.js +9 -4
- package/dist/emulation/ztc_addendum.js +3 -0
- package/dist/headless.d.ts +11 -4
- package/dist/headless.js +99 -34
- package/dist/headless_approval.d.ts +6 -0
- package/dist/headless_cli.js +1 -1
- package/dist/hooks/runner.js +7 -6
- package/dist/library.d.ts +4 -0
- package/dist/library.js +3 -0
- package/dist/mcp/client.js +3 -3
- package/dist/modes/registry.js +13 -4
- package/dist/onboarding/setup_environment.js +13 -1
- package/dist/optimize/adapters/kernelbench.js +88 -10
- package/dist/optimize/adapters/types.d.ts +5 -0
- package/dist/optimize/executor.js +21 -0
- package/dist/panes/cli_install.d.ts +54 -0
- package/dist/panes/cli_install.js +157 -0
- package/dist/panes/model_catalog.js +3 -0
- package/dist/panes/new_pane_choices.d.ts +6 -2
- package/dist/panes/new_pane_choices.js +24 -12
- package/dist/panes/pane_cli_launch.d.ts +50 -0
- package/dist/panes/pane_cli_launch.js +124 -0
- package/dist/panes/pane_clis.d.ts +171 -0
- package/dist/panes/pane_clis.js +325 -0
- package/dist/panes/person_only_panes.d.ts +45 -0
- package/dist/panes/person_only_panes.js +117 -0
- package/dist/plugin/simulation_living.js +0 -2
- package/dist/plugin/simulation_living_engine.d.ts +1 -0
- package/dist/plugin/simulation_living_engine.js +1 -0
- package/dist/plugin/simulation_living_labels.d.ts +3 -0
- package/dist/plugin/simulation_living_labels.js +2 -0
- package/dist/router_auth.js +12 -1
- package/dist/session.js +26 -1
- package/dist/simulation/art/gemini_image.js +11 -5
- package/dist/simulation/domains/loader.js +25 -3
- package/dist/simulation/living/cold.d.ts +23 -0
- package/dist/simulation/living/cold.js +41 -0
- package/dist/simulation/living/context.d.ts +591 -1283
- package/dist/simulation/living/context.js +378 -244
- package/dist/simulation/living/contradictions.d.ts +14 -0
- package/dist/simulation/living/contradictions.js +282 -0
- package/dist/simulation/living/core/ids.d.ts +53 -0
- package/dist/simulation/living/core/ids.js +39 -0
- package/dist/simulation/living/core/kind.d.ts +20 -0
- package/dist/simulation/living/core/kind.js +15 -0
- package/dist/simulation/living/core/laws.d.ts +179 -0
- package/dist/simulation/living/core/laws.js +184 -0
- package/dist/simulation/living/core/ops.d.ts +257 -0
- package/dist/simulation/living/core/ops.js +34 -0
- package/dist/simulation/living/definer.d.ts +17 -1
- package/dist/simulation/living/definer.js +130 -51
- package/dist/simulation/living/definition.d.ts +174 -65
- package/dist/simulation/living/definition.js +287 -180
- package/dist/simulation/living/director.d.ts +80 -0
- package/dist/simulation/living/director.js +363 -0
- package/dist/simulation/living/frame.d.ts +108 -21
- package/dist/simulation/living/frame.js +111 -66
- package/dist/simulation/living/identifiers.d.ts +0 -1
- package/dist/simulation/living/identifiers.js +0 -3
- package/dist/simulation/living/index.d.ts +18 -9
- package/dist/simulation/living/index.js +18 -9
- package/dist/simulation/living/inference.d.ts +92 -50
- package/dist/simulation/living/inference.js +319 -175
- package/dist/simulation/living/knowledge.d.ts +28 -0
- package/dist/simulation/living/knowledge.js +73 -0
- package/dist/simulation/living/library.json +1177 -0
- package/dist/simulation/living/mechanics.d.ts +31 -34
- package/dist/simulation/living/mechanics.js +222 -138
- package/dist/simulation/living/model-input.d.ts +6 -3
- package/dist/simulation/living/model-input.js +18 -26
- package/dist/simulation/living/open-world.d.ts +74 -94
- package/dist/simulation/living/open-world.js +151 -30
- package/dist/simulation/living/phrases.d.ts +3 -0
- package/dist/simulation/living/phrases.js +37 -0
- package/dist/simulation/living/phrases.json +560 -0
- package/dist/simulation/living/projection.d.ts +316 -2
- package/dist/simulation/living/projection.js +50 -2
- package/dist/simulation/living/prompts/example-spec.json +11 -0
- package/dist/simulation/living/prompts/role-text.json +14 -0
- package/dist/simulation/living/prompts.d.ts +5 -0
- package/dist/simulation/living/prompts.js +275 -0
- package/dist/simulation/living/recall.d.ts +2 -2
- package/dist/simulation/living/reduce.d.ts +51 -14
- package/dist/simulation/living/reduce.js +941 -579
- package/dist/simulation/living/replay.d.ts +5 -4
- package/dist/simulation/living/replay.js +10 -9
- package/dist/simulation/living/runtime.d.ts +135 -25
- package/dist/simulation/living/runtime.js +1641 -583
- package/dist/simulation/living/scale.d.ts +96 -0
- package/dist/simulation/living/scale.js +124 -0
- package/dist/simulation/living/script.d.ts +5 -0
- package/dist/simulation/living/script.js +115 -0
- package/dist/simulation/living/shared-kinds.d.ts +4 -11
- package/dist/simulation/living/shared-kinds.js +11 -81
- package/dist/simulation/living/space.d.ts +14 -0
- package/dist/simulation/living/space.js +132 -0
- package/dist/simulation/living/state.d.ts +100 -0
- package/dist/simulation/living/state.js +393 -0
- package/dist/simulation/living/types.d.ts +829 -512
- package/dist/simulation/living/types.js +162 -187
- package/dist/simulation/living/world-rules.d.ts +100 -0
- package/dist/simulation/living/world-rules.js +267 -0
- package/dist/simulation/plugins/loader.js +11 -0
- package/dist/skills/loader.js +4 -0
- package/dist/tools.d.ts +1 -0
- package/dist/tools.js +1 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
- package/dist/ui/ratatui/headless_pane_manager.js +13 -9
- package/dist/ui/ratatui/pane_relay.js +29 -0
- package/dist/ui/ratatui/pane_type.d.ts +10 -0
- package/dist/ui/ratatui/pane_type.js +11 -0
- package/dist/ui/ratatui/process.d.ts +30 -0
- package/dist/ui/ratatui/process.js +133 -19
- package/dist/ui/ratatui/protocol.d.ts +124 -2
- package/dist/ui/ratatui/protocol.js +35 -0
- package/dist/ui/ratatui/relay_policy.js +3 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
- package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
- package/dist/ui/terminal_image.d.ts +12 -0
- package/dist/ui/terminal_image.js +21 -1
- package/dist/utils/codex_project_trust.d.ts +19 -0
- package/dist/utils/codex_project_trust.js +37 -0
- package/dist/utils/compaction.js +103 -20
- package/dist/utils/git_program_files.d.ts +19 -12
- package/dist/utils/git_program_files.js +411 -83
- package/dist/utils/host_shell.d.ts +10 -1
- package/dist/utils/host_shell.js +14 -1
- package/dist/utils/mid_turn_compaction.d.ts +2 -0
- package/dist/utils/mid_turn_compaction.js +2 -0
- package/dist/utils/models.js +6 -1
- package/dist/utils/sandbox.d.ts +109 -8
- package/dist/utils/sandbox.js +981 -187
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.js +10 -4
- package/dist/utils/subprocess_env.d.ts +47 -11
- package/dist/utils/subprocess_env.js +107 -15
- package/dist/utils/system_ps.d.ts +8 -0
- package/dist/utils/system_ps.js +39 -7
- package/dist/utils/unattended_compaction.d.ts +9 -0
- package/dist/utils/unattended_compaction.js +13 -0
- package/dist/utils/ztc_own_state.d.ts +8 -5
- package/dist/utils/ztc_own_state.js +17 -11
- package/dist/web/mirror_client.js +1 -0
- package/dist/web/mirror_stream.d.ts +50 -6
- package/dist/web/mirror_stream.js +160 -15
- package/dist/workflows/registry.js +3 -1
- package/dist/workspace/controller.js +12 -0
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +14 -1
- package/dist/workspace_session_context.js +2 -1
- package/dist/zlm-embed.mjs +3823 -1970
- package/node_modules/@zerg/model-contracts/README.md +16 -4
- package/node_modules/@zerg/model-contracts/index.js +6 -1
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -24
- package/packages/model-contracts/README.md +16 -4
- package/packages/model-contracts/index.js +6 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID, createHash } from 'node:crypto';
|
|
2
|
-
import { appendFileSync, closeSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, rmSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { appendFileSync, closeSync, constants, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, rmSync, rmdirSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { pipelineWarning, runShellCommand } from '../../utils/shell.js';
|
|
@@ -9,7 +9,17 @@ import { writeFileAtomicSync } from '../../utils/atomic_write.js';
|
|
|
9
9
|
const MAX_LOG_BYTES = 16 * 1024 * 1024;
|
|
10
10
|
const MAX_RETAINED_JOBS = 64;
|
|
11
11
|
const RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
12
|
+
const HEARTBEAT_MS = 5_000;
|
|
12
13
|
const sessions = new Map();
|
|
14
|
+
/** The ids of the jobs this process started or took over. A session's other jobs are those of an earlier or another ZTC. */
|
|
15
|
+
const started = new Set();
|
|
16
|
+
/**
|
|
17
|
+
* Whether JOB is one this process started or took over: what it stops as a run or an interrupted turn ends, and whose
|
|
18
|
+
* state it announces. Another ZTC on the session sees to its own.
|
|
19
|
+
*/
|
|
20
|
+
export function startedHere(job) {
|
|
21
|
+
return started.has(job.job_id);
|
|
22
|
+
}
|
|
13
23
|
const listeners = new Map();
|
|
14
24
|
export function subscribeCommandJobs(sessionId, listener) {
|
|
15
25
|
let subscriptions = listeners.get(sessionId);
|
|
@@ -52,6 +62,9 @@ function pruneCommandLogs() {
|
|
|
52
62
|
if (receipt.status === 'running') {
|
|
53
63
|
if ([...sessions.values()].some(registry => registry.get(id)?.receipt.status === 'running'))
|
|
54
64
|
continue;
|
|
65
|
+
// Its owner may be a process that can't be seen from here: another container's, on the same state folder.
|
|
66
|
+
if (heartbeatFresh(join(path, file.name)))
|
|
67
|
+
continue;
|
|
55
68
|
if (Number.isSafeInteger(receipt.owner_pid) && receipt.owner_pid > 0) {
|
|
56
69
|
try {
|
|
57
70
|
process.kill(receipt.owner_pid, 0);
|
|
@@ -116,25 +129,81 @@ function directory(sessionId) {
|
|
|
116
129
|
function save(sessionId, receipt) {
|
|
117
130
|
writeFileAtomicSync(join(directory(sessionId), `${receipt.job_id}.json`), JSON.stringify(receipt), { mode: 0o600 });
|
|
118
131
|
}
|
|
132
|
+
function stopRequestPath(sessionId, jobId) {
|
|
133
|
+
return join(directory(sessionId), `${jobId}.stop`);
|
|
134
|
+
}
|
|
135
|
+
function liveJob(sessionId, jobId) {
|
|
136
|
+
return sessions.get(sessionId)?.get(jobId);
|
|
137
|
+
}
|
|
138
|
+
/** While the job runs, keeps its receipt's heartbeat fresh and acts on a stop another process requests. */
|
|
139
|
+
function watchStopRequests(sessionId, job) {
|
|
140
|
+
const path = stopRequestPath(sessionId, job.receipt.job_id);
|
|
141
|
+
let beat = Date.now();
|
|
142
|
+
const timer = setInterval(() => {
|
|
143
|
+
if (job.receipt.status !== 'running')
|
|
144
|
+
return;
|
|
145
|
+
if (Date.now() - beat >= HEARTBEAT_MS) {
|
|
146
|
+
beat = Date.now();
|
|
147
|
+
const file = join(directory(sessionId), `${job.receipt.job_id}.json`);
|
|
148
|
+
// Another process marks the job interrupted when the beats stall past the bound; the owner, still
|
|
149
|
+
// running it, saves its receipt again.
|
|
150
|
+
let onDisk;
|
|
151
|
+
try {
|
|
152
|
+
onDisk = JSON.parse(readFileSync(file, 'utf8')).status;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
onDisk = undefined;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
if (onDisk === 'running')
|
|
159
|
+
utimesSync(file, new Date(beat), new Date(beat));
|
|
160
|
+
else
|
|
161
|
+
save(sessionId, job.receipt);
|
|
162
|
+
}
|
|
163
|
+
catch { /* the next beat retries */ }
|
|
164
|
+
}
|
|
165
|
+
if (!existsSync(path))
|
|
166
|
+
return;
|
|
167
|
+
// A request that can't be cleared away (a folder of its name, a folder turned read-only) is one all the same.
|
|
168
|
+
try {
|
|
169
|
+
rmSync(path, { force: true });
|
|
170
|
+
}
|
|
171
|
+
catch { /* the job ends, and with it this watch */ }
|
|
172
|
+
job.controller.abort();
|
|
173
|
+
}, 250);
|
|
174
|
+
timer.unref();
|
|
175
|
+
return timer;
|
|
176
|
+
}
|
|
177
|
+
async function waitForPersistedJob(sessionId, jobId, waitMs, signal) {
|
|
178
|
+
const deadline = Date.now() + waitMs;
|
|
179
|
+
while (Date.now() < deadline) {
|
|
180
|
+
if (signal?.aborted)
|
|
181
|
+
throw new Error(`Command read cancelled; inspect job ${jobId} before retrying. The job may still be running.`);
|
|
182
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(250, Math.max(1, deadline - Date.now()))));
|
|
183
|
+
try {
|
|
184
|
+
if (resolveJob(sessionId, jobId).receipt.status !== 'running')
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
119
192
|
function resolveJob(sessionId, jobId) {
|
|
120
193
|
if (!/^[0-9a-f-]{36}$/.test(jobId))
|
|
121
194
|
throw new Error('Command job not found in this session');
|
|
122
195
|
const live = sessions.get(sessionId)?.get(jobId);
|
|
123
196
|
if (live)
|
|
124
197
|
return live;
|
|
125
|
-
let receipt;
|
|
126
|
-
|
|
127
|
-
receipt = JSON.parse(readFileSync(join(directory(sessionId), `${jobId}.json`), 'utf8'));
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
198
|
+
let receipt = savedReceipt(sessionId, jobId);
|
|
199
|
+
if (!receipt)
|
|
130
200
|
throw new Error('Command job not found in this session');
|
|
131
|
-
}
|
|
132
201
|
const policy = parseCommandExecutionPolicy(receipt.execution_policy);
|
|
133
202
|
if (policy && policy.started_at === receipt.started_at)
|
|
134
203
|
receipt.execution_policy = policy;
|
|
135
204
|
else
|
|
136
205
|
delete receipt.execution_policy;
|
|
137
|
-
if (receipt.status === 'running') {
|
|
206
|
+
if (receipt.status === 'running' && !owningProcessAlive(sessionId, receipt)) {
|
|
138
207
|
receipt = { ...receipt, status: 'interrupted', error: 'Owning ZTC process ended; inspect output before retrying.',
|
|
139
208
|
...(receipt.verification?.process_outcome === 'running' ? { verification: { ...receipt.verification,
|
|
140
209
|
process_outcome: 'interrupted', source_binding: 'unknown' } } : {}) };
|
|
@@ -148,8 +217,126 @@ function resolveJob(sessionId, jobId) {
|
|
|
148
217
|
canInspectVerificationSource: () => false };
|
|
149
218
|
}
|
|
150
219
|
export function listCommandJobs(sessionId) {
|
|
151
|
-
const
|
|
152
|
-
|
|
220
|
+
const live = [...(sessions.get(sessionId)?.values() ?? [])].map(job => job.receipt);
|
|
221
|
+
const known = new Set(live.map(receipt => receipt.job_id));
|
|
222
|
+
const running = [];
|
|
223
|
+
const terminal = [];
|
|
224
|
+
for (const receipt of live)
|
|
225
|
+
(receipt.status === 'running' ? running : terminal).push(receipt);
|
|
226
|
+
for (const persisted of persistedReceipts(sessionId)) {
|
|
227
|
+
if (known.has(persisted.job_id))
|
|
228
|
+
continue;
|
|
229
|
+
if (persisted.status !== 'running') {
|
|
230
|
+
terminal.push(persisted);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (owningProcessAlive(sessionId, persisted)) {
|
|
234
|
+
running.push(persisted);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const interrupted = { ...persisted, status: 'interrupted', error: 'Owning ZTC process ended; inspect output before retrying.',
|
|
238
|
+
...(persisted.verification?.process_outcome === 'running' ? { verification: { ...persisted.verification,
|
|
239
|
+
process_outcome: 'interrupted', source_binding: 'unknown' } } : {}) };
|
|
240
|
+
delete interrupted.ended_at;
|
|
241
|
+
delete interrupted.observed_at;
|
|
242
|
+
delete interrupted.elapsed_ms;
|
|
243
|
+
try {
|
|
244
|
+
save(sessionId, interrupted);
|
|
245
|
+
}
|
|
246
|
+
catch { /* a listing still reports what it observed */ }
|
|
247
|
+
terminal.push(interrupted);
|
|
248
|
+
}
|
|
249
|
+
terminal.sort((left, right) => (Date.parse(left.ended_at ?? left.started_at) || 0)
|
|
250
|
+
- (Date.parse(right.ended_at ?? right.started_at) || 0));
|
|
251
|
+
return [...running.map(observeReceipt), ...terminal.slice(-28).map(observeReceipt)];
|
|
252
|
+
}
|
|
253
|
+
/** A reused PID or an unreaped owner still answers a signal check, so ownership also needs a fresh heartbeat. */
|
|
254
|
+
function owningProcessAlive(sessionId, receipt) {
|
|
255
|
+
const pid = receipt.owner_pid;
|
|
256
|
+
if (pid === undefined || !Number.isSafeInteger(pid) || pid <= 0 || pid === process.pid)
|
|
257
|
+
return false;
|
|
258
|
+
try {
|
|
259
|
+
process.kill(pid, 0);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return heartbeatFresh(join(directory(sessionId), `${receipt.job_id}.json`));
|
|
265
|
+
}
|
|
266
|
+
/** Whether the ZTC running the job of the receipt at PATH wrote or touched it within the last beats. */
|
|
267
|
+
function heartbeatFresh(path) {
|
|
268
|
+
try {
|
|
269
|
+
return Date.now() - statSync(path).mtimeMs < 3 * HEARTBEAT_MS;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const STATUSES = new Set(['running', 'completed', 'failed', 'cancelled', 'timed_out', 'interrupted']);
|
|
276
|
+
/** Whether VALUE, what a receipt file of JOB_ID's name holds, is that job's receipt, so that nothing that reads one fails on it. */
|
|
277
|
+
function isReceipt(value, jobId) {
|
|
278
|
+
if (typeof value !== 'object' || value === null)
|
|
279
|
+
return false;
|
|
280
|
+
const receipt = value;
|
|
281
|
+
const optional = (field, type) => field === undefined || (field !== null && typeof field === type);
|
|
282
|
+
return receipt.job_id === jobId && STATUSES.has(receipt.status)
|
|
283
|
+
&& [receipt.command, receipt.cwd, receipt.started_at].every(field => typeof field === 'string')
|
|
284
|
+
&& [receipt.ended_at, receipt.warning, receipt.followed_file, receipt.error].every(field => optional(field, 'string'))
|
|
285
|
+
&& [receipt.exit_code, receipt.owner_pid, receipt.dropped_bytes].every(field => optional(field, 'number'))
|
|
286
|
+
&& [receipt.pipeline_exit_codes, receipt.earlier_pipeline_exit_codes].every(field => field === undefined || Array.isArray(field))
|
|
287
|
+
&& [receipt.checked, receipt.verification, receipt.verification_current, receipt.execution_policy].every(field => optional(field, 'object'))
|
|
288
|
+
&& optional(receipt.output_truncated, 'boolean');
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* A file of the registry's folder, opened for reading: the one of that name itself, never one a link there names, and a
|
|
292
|
+
* regular file, so nothing waits on a pipe.
|
|
293
|
+
*/
|
|
294
|
+
function openOwnFile(path) {
|
|
295
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
296
|
+
if (fstatSync(fd).isFile())
|
|
297
|
+
return fd;
|
|
298
|
+
closeSync(fd);
|
|
299
|
+
throw new Error('Not a regular file');
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* The receipt on disk of one of the session's jobs, if what is there is one: another process may be replacing it, and
|
|
303
|
+
* what is no receipt of that job is no job. Its log is the one of its own name beside it, whatever path the receipt
|
|
304
|
+
* names: ZTC reads that file, and names it, as its own (as pruneCommandLogs removes it).
|
|
305
|
+
*/
|
|
306
|
+
function savedReceipt(sessionId, jobId) {
|
|
307
|
+
let value;
|
|
308
|
+
try {
|
|
309
|
+
const fd = openOwnFile(join(directory(sessionId), `${jobId}.json`));
|
|
310
|
+
try {
|
|
311
|
+
value = JSON.parse(readFileSync(fd, 'utf8'));
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
closeSync(fd);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
return isReceipt(value, jobId) ? { ...value, log_path: join(directory(sessionId), `${jobId}.log`) } : undefined;
|
|
321
|
+
}
|
|
322
|
+
function persistedReceipts(sessionId) {
|
|
323
|
+
const path = directory(sessionId);
|
|
324
|
+
let files;
|
|
325
|
+
try {
|
|
326
|
+
files = readdirSync(path);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
const receipts = [];
|
|
332
|
+
for (const file of files) {
|
|
333
|
+
if (!/^[0-9a-f-]{36}\.json$/.test(file))
|
|
334
|
+
continue;
|
|
335
|
+
const receipt = savedReceipt(sessionId, file.slice(0, -5));
|
|
336
|
+
if (receipt)
|
|
337
|
+
receipts.push(receipt);
|
|
338
|
+
}
|
|
339
|
+
return receipts;
|
|
153
340
|
}
|
|
154
341
|
function observeReceipt(receipt) {
|
|
155
342
|
const result = structuredClone(receipt);
|
|
@@ -194,6 +381,8 @@ function createJob(options) {
|
|
|
194
381
|
} };
|
|
195
382
|
save(sessionId, job.receipt);
|
|
196
383
|
registry.set(jobId, job);
|
|
384
|
+
started.add(jobId);
|
|
385
|
+
job.stopWatch = watchStopRequests(sessionId, job);
|
|
197
386
|
publish(sessionId);
|
|
198
387
|
return job;
|
|
199
388
|
}
|
|
@@ -261,6 +450,8 @@ function settleJob(sessionId, job, running, cleanup, onSettled) {
|
|
|
261
450
|
const terminal = [...registry.entries()].filter(([, entry]) => entry.receipt.status !== 'running');
|
|
262
451
|
for (const [id] of terminal.slice(0, Math.max(0, terminal.length - 64)))
|
|
263
452
|
registry.delete(id);
|
|
453
|
+
if (job.stopWatch)
|
|
454
|
+
clearInterval(job.stopWatch);
|
|
264
455
|
notifyActivity(job);
|
|
265
456
|
publish(sessionId);
|
|
266
457
|
try {
|
|
@@ -315,27 +506,33 @@ export async function readCommandJob(sessionId, jobId, cursor = 0, waitMs = 0, s
|
|
|
315
506
|
throw new Error('cursor must be a non-negative byte offset');
|
|
316
507
|
if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 60000)
|
|
317
508
|
throw new Error('wait_ms must be an integer between 0 and 60000');
|
|
318
|
-
|
|
509
|
+
let job = resolveJob(sessionId, jobId);
|
|
319
510
|
if (canInspectSource)
|
|
320
511
|
job.canInspectVerificationSource = canInspectSource;
|
|
321
512
|
const cancelled = () => new Error(`Command read cancelled; inspect job ${jobId} before retrying. The job may still be running.`);
|
|
322
513
|
if (signal?.aborted)
|
|
323
514
|
throw cancelled();
|
|
324
515
|
if (job.receipt.status === 'running' && waitMs > 0) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
await Promise.race([job.done, new Promise((resolve, reject) => {
|
|
329
|
-
timer = setTimeout(resolve, waitMs);
|
|
330
|
-
onAbort = () => reject(cancelled());
|
|
331
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
332
|
-
})]);
|
|
516
|
+
if (liveJob(sessionId, jobId) === undefined) {
|
|
517
|
+
await waitForPersistedJob(sessionId, jobId, waitMs, signal);
|
|
518
|
+
job = resolveJob(sessionId, jobId);
|
|
333
519
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
520
|
+
else {
|
|
521
|
+
let timer;
|
|
522
|
+
let onAbort;
|
|
523
|
+
try {
|
|
524
|
+
await Promise.race([job.done, new Promise((resolve, reject) => {
|
|
525
|
+
timer = setTimeout(resolve, waitMs);
|
|
526
|
+
onAbort = () => reject(cancelled());
|
|
527
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
528
|
+
})]);
|
|
529
|
+
}
|
|
530
|
+
finally {
|
|
531
|
+
if (timer)
|
|
532
|
+
clearTimeout(timer);
|
|
533
|
+
if (onAbort)
|
|
534
|
+
signal?.removeEventListener('abort', onAbort);
|
|
535
|
+
}
|
|
339
536
|
}
|
|
340
537
|
}
|
|
341
538
|
const result = await refreshReadVerification(job, readOutput(job, cursor), canInspectSource);
|
|
@@ -351,13 +548,15 @@ async function refreshReadVerification(job, result, canInspectSource) {
|
|
|
351
548
|
return { ...result, verification_current: current };
|
|
352
549
|
}
|
|
353
550
|
function readOutput(job, cursor) {
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const buffer = Buffer.alloc(Math.min(16384, size - cursor));
|
|
358
|
-
const fd = openSync(job.receipt.log_path, 'r');
|
|
551
|
+
const fd = openOwnFile(job.receipt.log_path);
|
|
552
|
+
let size;
|
|
553
|
+
let buffer;
|
|
359
554
|
let count;
|
|
360
555
|
try {
|
|
556
|
+
size = fstatSync(fd).size;
|
|
557
|
+
if (cursor > size)
|
|
558
|
+
throw new Error('cursor is beyond the command output');
|
|
559
|
+
buffer = Buffer.alloc(Math.min(16384, size - cursor));
|
|
361
560
|
count = readSync(fd, buffer, 0, buffer.length, cursor);
|
|
362
561
|
}
|
|
363
562
|
finally {
|
|
@@ -438,9 +637,20 @@ export async function waitForCommandProgress(sessionId, jobId, options) {
|
|
|
438
637
|
return { reason: progress.reason, result: observeReceipt(result) };
|
|
439
638
|
}
|
|
440
639
|
export async function stopCommandJob(sessionId, jobId, canInspectSource) {
|
|
441
|
-
|
|
640
|
+
let job = resolveJob(sessionId, jobId);
|
|
442
641
|
if (canInspectSource)
|
|
443
642
|
job.canInspectVerificationSource = canInspectSource;
|
|
643
|
+
if (job.receipt.status === 'running' && liveJob(sessionId, jobId) === undefined) {
|
|
644
|
+
const request = stopRequestPath(sessionId, jobId);
|
|
645
|
+
writeFileAtomicSync(request, new Date().toISOString(), { mode: 0o600 });
|
|
646
|
+
try {
|
|
647
|
+
await waitForPersistedJob(sessionId, jobId, 5000);
|
|
648
|
+
}
|
|
649
|
+
finally {
|
|
650
|
+
rmSync(request, { force: true });
|
|
651
|
+
}
|
|
652
|
+
job = resolveJob(sessionId, jobId);
|
|
653
|
+
}
|
|
444
654
|
if (job.receipt.status === 'running') {
|
|
445
655
|
job.controller.abort();
|
|
446
656
|
await job.done;
|
|
@@ -463,5 +673,5 @@ export async function shutdownCommandJobs(sessionId) {
|
|
|
463
673
|
await Promise.all(pending);
|
|
464
674
|
}
|
|
465
675
|
export async function interruptCommandJobs(sessionId) {
|
|
466
|
-
await Promise.all(listCommandJobs(sessionId).filter(job => job.status === 'running').map(job => stopCommandJob(sessionId, job.job_id)));
|
|
676
|
+
await Promise.all(listCommandJobs(sessionId).filter(job => job.status === 'running' && startedHere(job)).map(job => stopCommandJob(sessionId, job.job_id)));
|
|
467
677
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AgentEvent, Message } from '../../types.js';
|
|
2
2
|
import { type ManagedCommandObservation } from './command_jobs.js';
|
|
3
|
+
/** note: what the host says of a job it waited on (a quiet one: quiet_job.ts). */
|
|
3
4
|
export type ManagedCommandWaitObservation = ManagedCommandObservation & {
|
|
4
5
|
toolCallId: string;
|
|
5
6
|
readCursor?: number;
|
|
7
|
+
note?: string;
|
|
6
8
|
};
|
|
7
9
|
export interface ManagedCommandWaitOptions {
|
|
8
10
|
signal?: AbortSignal;
|
|
@@ -99,6 +99,7 @@ export function formatManagedCommandObservations(observations) {
|
|
|
99
99
|
...(item.result.error === undefined ? {} : { error: item.result.error }),
|
|
100
100
|
...(item.result.output_truncated === undefined ? {} : { output_truncated: item.result.output_truncated }),
|
|
101
101
|
...(item.result.dropped_bytes === undefined ? {} : { dropped_bytes: item.result.dropped_bytes }),
|
|
102
|
+
...(item.note === undefined ? {} : { note: item.note }),
|
|
102
103
|
}));
|
|
103
104
|
const serialize = () => prefix + JSON.stringify(rows);
|
|
104
105
|
const full = serialize();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** A task's Done-when section, and whether a done report says one of its items was not met, in the task's own words. */
|
|
2
|
+
/** The items of a task's Done-when section, inline (`Done when: a; b.`) or a list. Empty without one. */
|
|
3
|
+
export declare function doneWhenItems(task: string): string[];
|
|
4
|
+
/**
|
|
5
|
+
* The Done-when items a report says were not met, each with the statement that says so: one with a word of not-done
|
|
6
|
+
* that shares the item's own words. An item that is itself a "not" ("no test fails") is left alone: meeting it reads
|
|
7
|
+
* the same. So is an item of one word ("the PR is merged", a table cell, a list's label): any aside that uses the word
|
|
8
|
+
* ("I did not merge main back") would read as about it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function unmetDoneItems(items: readonly string[], report: string): Array<{
|
|
11
|
+
item: string;
|
|
12
|
+
line: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** The first of unmetDoneItems. */
|
|
15
|
+
export declare function unmetDoneItem(items: readonly string[], report: string): {
|
|
16
|
+
item: string;
|
|
17
|
+
line: string;
|
|
18
|
+
} | undefined;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** A task's Done-when section, and whether a done report says one of its items was not met, in the task's own words. */
|
|
2
|
+
/**
|
|
3
|
+
* `Done when:` with its items after it or below it, `**Done when:**`, `## Acceptance criteria`, or the words alone on
|
|
4
|
+
* their line. A sentence that starts with them ("Definition of done is in the ticket") is not a heading.
|
|
5
|
+
*/
|
|
6
|
+
const DONE_HEADING = /^\s*(?:#{1,6}\s*)?[*_]{0,2}(?:done[\s-]+when|definition\s+of\s+done|acceptance\s+criteria|completion\s+criteria)[*_]{0,2}\s*(?:[:–—-][*_]{0,2}\s*(.*)|$)/i;
|
|
7
|
+
const NEXT_HEADING = /^\s*(?:#{1,6}\s+\S|[*_]{0,2}[A-Z][A-Za-z][A-Za-z /_-]{1,32}:)/;
|
|
8
|
+
const BULLET = /^\s*(?:[-*•]|\d+[.)])\s+/;
|
|
9
|
+
const FENCE = /^\s*(?:```|~~~)/;
|
|
10
|
+
const CHECKBOX_MARK = /^\[[ xX]\]\s+/;
|
|
11
|
+
// Every pattern that splits or trims starts only where a run of its characters starts: a run of spaces, `!` or `.`
|
|
12
|
+
// was tried from each of its characters, and 100,000 of them in a report took seconds.
|
|
13
|
+
const ITEM_SPLIT = /(?<!\s)\s*;\s*|(?<!\s)\s+\|\s+/u;
|
|
14
|
+
const ITEM_TAIL = /(?<![.;:,])[.;:,]+$/u;
|
|
15
|
+
// `go test ./...` ends no sentence.
|
|
16
|
+
const STATEMENT_SPLIT = /\r?\n|(?<![;!?])[;!?]+\s|(?<!\/\.\.)\.\s+|,\s+(?:but|although|though|however|while)\s+|(?<!\s)\s+(?:but|although|though|however)\s+/u;
|
|
17
|
+
const UNMET = '(?:unverified|unchecked|pending|skipped|missing|fail|failed|failing|fails|blocked|outstanding|unmet|unfinished|incomplete)';
|
|
18
|
+
const NEGATIVE = new RegExp(`(?:^|[^A-Za-z])(?:not|no|never|none|without|${UNMET})\\b|n['’]t\\b`, 'i');
|
|
19
|
+
/** An item that is itself a "not" in other words ("nothing is left running"): meeting it reads the same. */
|
|
20
|
+
const NEGATED_ITEM = /\b(?:nothing|nobody|neither|nor|zero)\b/i;
|
|
21
|
+
/** Words of not-done that say the opposite: "0 failed", "no regressions", "Not verified: none", "fixed the missing flag". */
|
|
22
|
+
const SETTLED = '(?:fail(?:ed|ing|s|ures?)?|errors?|regress(?:ed|ions?)|issues?|problems?|warnings?|conflicts?|skipped|pending|blocked|blockers?|missing|outstanding|unmet|unfinished|incomplete|left|remaining|broken)';
|
|
23
|
+
const REASSURING = [
|
|
24
|
+
new RegExp(`\\b(?:0|zero|no|none|nothing|without(?: any)?)(?: (?:of|is|are|was|were|has|have|new|known|open|other|more|remaining|tests?|items?|checks?)){0,3} ${SETTLED}\\b`, 'gi'),
|
|
25
|
+
// "Failed: 0", "Not verified: none", and node:test's "# fail 0".
|
|
26
|
+
/\b(?:not (?:verified|checked|run|done|met|covered)|fail|failed|failures|errors|skipped|pending|missing|blocked|outstanding|unmet|unverified|remaining)\s*(?:[:=]\s*(?:0|none|nothing|n\/a)|0)\b/gi,
|
|
27
|
+
/\b(?:no longer|not (?:needed|required|applicable|necessary)|\d+ (?:tests? )?skipped)\b/gi,
|
|
28
|
+
new RegExp(`\\b(?:previously|formerly|earlier|initially|originally)[ -]${SETTLED}\\b`, 'gi'),
|
|
29
|
+
new RegExp(`\\b(?:fix(?:ed|es)?|resolved|restored|repaired|unblocked)(?: the| a| every| all)? ${SETTLED}\\b`, 'gi'),
|
|
30
|
+
new RegExp(`\\bthe ${SETTLED}(?= [a-z ]{1,60}\\b(?:now|passes|pass|works)\\b)`, 'gi'),
|
|
31
|
+
// `go test` prints it for a package with no tests.
|
|
32
|
+
/\[no test files\]/gi,
|
|
33
|
+
];
|
|
34
|
+
/** A report's own scope ("Limits: …", "Out of scope: …") restates the task's limits; it says nothing of an item. */
|
|
35
|
+
const SCOPE_LINE = /^\W*(?:limits?|constraints?|out of scope|per the limits)\b/i;
|
|
36
|
+
/** An unticked box in a report's checklist is an item not done. */
|
|
37
|
+
const UNTICKED = /^\s*(?:[-*]\s+)?\[ \]/;
|
|
38
|
+
const STOPWORDS = new Set([
|
|
39
|
+
'the', 'and', 'with', 'that', 'this', 'from', 'into', 'each', 'have', 'has', 'had', 'for', 'are', 'was', 'were',
|
|
40
|
+
'will', 'must', 'should', 'shall', 'every', 'any', 'all', 'its', 'their', 'they', 'them', 'when', 'then', 'than',
|
|
41
|
+
'also', 'only', 'just', 'such', 'same', 'which', 'what', 'where', 'while', 'after', 'before', 'under', 'over', 'not',
|
|
42
|
+
]);
|
|
43
|
+
/** A text's words, stemmed so "passes", "passed" and "pass" are one. */
|
|
44
|
+
function terms(text) {
|
|
45
|
+
return text.toLowerCase().split(/[^a-z0-9]+/u)
|
|
46
|
+
.filter(word => word.length >= 3 && !STOPWORDS.has(word))
|
|
47
|
+
.map(word => word.length > 4 ? word.replace(/(?:ing|ed|es|(?<!s)s|e)$/u, '') : word.replace(/(?<!s)s$/u, ''));
|
|
48
|
+
}
|
|
49
|
+
/** The items of a task's Done-when section, inline (`Done when: a; b.`) or a list. Empty without one. */
|
|
50
|
+
export function doneWhenItems(task) {
|
|
51
|
+
const lines = task.split(/\r?\n/u);
|
|
52
|
+
let heading = -1;
|
|
53
|
+
let inline = '';
|
|
54
|
+
let fenced = false;
|
|
55
|
+
for (let index = 0; index < lines.length; index++) {
|
|
56
|
+
const line = lines[index] ?? '';
|
|
57
|
+
// A section shown in a code block is an example, not the task's own.
|
|
58
|
+
if (FENCE.test(line)) {
|
|
59
|
+
fenced = !fenced;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const match = fenced ? null : DONE_HEADING.exec(line);
|
|
63
|
+
if (match) {
|
|
64
|
+
heading = index;
|
|
65
|
+
inline = (match[1] ?? '').trim();
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (heading < 0)
|
|
70
|
+
return [];
|
|
71
|
+
const collected = inline ? [inline] : [];
|
|
72
|
+
for (let index = heading + 1; index < lines.length; index++) {
|
|
73
|
+
const line = lines[index] ?? '';
|
|
74
|
+
if (FENCE.test(line) || (inline && !BULLET.test(line)))
|
|
75
|
+
break;
|
|
76
|
+
if (line.trim() === '') {
|
|
77
|
+
const next = lines[index + 1] ?? '';
|
|
78
|
+
if (next.trim() !== '' && (NEXT_HEADING.test(next) || !BULLET.test(next)))
|
|
79
|
+
break;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!inline && NEXT_HEADING.test(line))
|
|
83
|
+
break;
|
|
84
|
+
collected.push(line.trim());
|
|
85
|
+
}
|
|
86
|
+
const items = [];
|
|
87
|
+
for (const row of collected) {
|
|
88
|
+
for (const part of row.replace(BULLET, '').replace(CHECKBOX_MARK, '').split(ITEM_SPLIT)) {
|
|
89
|
+
const item = part.replace(ITEM_TAIL, '').trim();
|
|
90
|
+
if (item.length > 2)
|
|
91
|
+
items.push(item);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return items;
|
|
95
|
+
}
|
|
96
|
+
/** A report's statements: a "0 failed" about the tests says nothing of the changelog in the next one. */
|
|
97
|
+
function statements(report) {
|
|
98
|
+
return report.split(STATEMENT_SPLIT).map(line => line.trim()).filter(line => line.length > 0);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The Done-when items a report says were not met, each with the statement that says so: one with a word of not-done
|
|
102
|
+
* that shares the item's own words. An item that is itself a "not" ("no test fails") is left alone: meeting it reads
|
|
103
|
+
* the same. So is an item of one word ("the PR is merged", a table cell, a list's label): any aside that uses the word
|
|
104
|
+
* ("I did not merge main back") would read as about it.
|
|
105
|
+
*/
|
|
106
|
+
export function unmetDoneItems(items, report) {
|
|
107
|
+
const unmet = statements(report)
|
|
108
|
+
.filter(line => !SCOPE_LINE.test(line)
|
|
109
|
+
&& (UNTICKED.test(line) || NEGATIVE.test(REASSURING.reduce((text, phrase) => text.replace(phrase, ' '), line))))
|
|
110
|
+
.map(line => ({ line, terms: new Set(terms(line)) }));
|
|
111
|
+
if (unmet.length === 0)
|
|
112
|
+
return [];
|
|
113
|
+
const found = [];
|
|
114
|
+
for (const item of items) {
|
|
115
|
+
if (NEGATIVE.test(item) || NEGATED_ITEM.test(item))
|
|
116
|
+
continue;
|
|
117
|
+
const itemTerms = [...new Set(terms(item))];
|
|
118
|
+
if (itemTerms.length < 2)
|
|
119
|
+
continue;
|
|
120
|
+
const needed = Math.min(3, Math.max(2, Math.ceil(itemTerms.length * 0.4)));
|
|
121
|
+
const said = unmet.find(statement => itemTerms.filter(term => statement.terms.has(term)).length >= needed);
|
|
122
|
+
if (said !== undefined)
|
|
123
|
+
found.push({ item, line: said.line });
|
|
124
|
+
}
|
|
125
|
+
return found;
|
|
126
|
+
}
|
|
127
|
+
/** The first of unmetDoneItems. */
|
|
128
|
+
export function unmetDoneItem(items, report) {
|
|
129
|
+
return unmetDoneItems(items, report)[0];
|
|
130
|
+
}
|
|
@@ -4,6 +4,8 @@ import { parseCommandExecutionObservation, parseCommandExecutionPolicy } from '.
|
|
|
4
4
|
import { describePermissionPolicy } from '../../config/permissions.js';
|
|
5
5
|
import { dockerTarget } from '../../utils/docker_target.js';
|
|
6
6
|
export const DELETION_EVIDENCE_GUIDANCE = 'Deletion or reclaimed-space claims require a successful result for the exact operation and target, followed by target-state verification. A dry run, acknowledgement or unresolved result proves no deletion. Report removed logical bytes separately from measured quota/free-space change; identify its source and interval, and state unknown when attribution is unavailable.';
|
|
7
|
+
/** TEXT, or its start with an ellipsis where the facts cut it: a person may be shown them (/status --verbose), and a read-only observer is withheld what may start a credential at the mark. */
|
|
8
|
+
const shortened = (text, limit) => text.length <= limit ? text : `${text.slice(0, limit - 1)}…`;
|
|
7
9
|
/** Keep recent stage outcomes readable without expanding the prompt with every retained job. */
|
|
8
10
|
function managedCommandSummary(jobs) {
|
|
9
11
|
if (!jobs.length)
|
|
@@ -17,7 +19,8 @@ function managedCommandSummary(jobs) {
|
|
|
17
19
|
const parsedPolicy = parseCommandExecutionPolicy(job.execution_policy);
|
|
18
20
|
const executionPolicy = parsedPolicy?.started_at === job.started_at ? parsedPolicy : { mode: 'unknown' };
|
|
19
21
|
const observation = parseCommandExecutionObservation({ observed_at: job.observed_at, elapsed_ms: job.elapsed_ms }, job.started_at);
|
|
20
|
-
const row = JSON.stringify({ job_id: job.job_id.slice(0, 256), status: job.status,
|
|
22
|
+
const row = JSON.stringify({ job_id: job.job_id.slice(0, 256), status: job.status, command: shortened(job.command, 240),
|
|
23
|
+
cwd: shortened(job.cwd, 512),
|
|
21
24
|
exit_code: job.exit_code,
|
|
22
25
|
execution_policy: executionPolicy, observed_at: observation?.observed_at ?? null, elapsed_ms: observation?.elapsed_ms ?? null,
|
|
23
26
|
...(checked === undefined ? {} : { checked: checked ?? { status: 'incomplete', verification: 'unknown', reason: 'Checked outcome unavailable' } }) });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { failureWithoutExecutionSuffix } from './command_execution_policy.js';
|
|
2
|
+
function squash(line) {
|
|
3
|
+
return line.replace(/['"`][^'"`]*['"`]/g, '<value>').replace(/\d+/g, '#').trim().slice(0, 240);
|
|
4
|
+
}
|
|
5
|
+
export function errorLine(output) {
|
|
6
|
+
const lines = output.split('\n').map(line => line.trim()).filter(Boolean);
|
|
7
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
8
|
+
const line = lines[index];
|
|
9
|
+
if (/^(?:pipe stages exited|hint:|command failed \(exit)/.test(line))
|
|
10
|
+
continue;
|
|
11
|
+
if (/^(?:[\w.]+\.)?\w*(?:error|exception)\b\s*:/i.test(line) || /^(?:error|fatal)\b[:\s]/i.test(line) || /\berror(?:\[\w+\])?:/i.test(line))
|
|
12
|
+
return line;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
export function normalizeFailure(content) {
|
|
17
|
+
const text = failureWithoutExecutionSuffix(content).toLowerCase();
|
|
18
|
+
if (/not_executed/.test(text))
|
|
19
|
+
return '';
|
|
20
|
+
for (const [pattern, cause] of [
|
|
21
|
+
[/heredoc|unexpected end of file|unterminated/, 'unfinished shell input'],
|
|
22
|
+
[/permission denied|eacces/, 'permission denied'],
|
|
23
|
+
[/not found|enoent|unknown tool|unavailable/, 'capability or file unavailable'],
|
|
24
|
+
[/timeout|timed out/, 'timeout'],
|
|
25
|
+
[/syntaxerror|syntax error|invalid.*syntax/, 'syntax error'],
|
|
26
|
+
])
|
|
27
|
+
if (pattern.test(text))
|
|
28
|
+
return cause;
|
|
29
|
+
const exit = text.match(/command failed \(exit (\d+)\)/);
|
|
30
|
+
if (exit) {
|
|
31
|
+
const line = errorLine(text);
|
|
32
|
+
return `command exit ${exit[1]}${line ? `: ${squash(line)}` : ''}`;
|
|
33
|
+
}
|
|
34
|
+
return squash(text.split('\n')[0]);
|
|
35
|
+
}
|
|
@@ -77,13 +77,25 @@ export declare class CapabilityPolicy implements Policy {
|
|
|
77
77
|
});
|
|
78
78
|
evaluateTool(request: ToolPolicyRequest): ToolPolicyDecision;
|
|
79
79
|
private evaluatePathPolicy;
|
|
80
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* The roots the profile allows and denies, canonical, a relative one this policy's folder's. Those it allows by one look
|
|
82
|
+
* at each (utils/sandbox.ts's profileRootLooks), each by the real path that look found, which no check after it resolves
|
|
83
|
+
* again: the policy canonicalized each root again after the look, so a command left running in the background that
|
|
84
|
+
* swapped a root, or a folder above it, between a folder and a link to a folder outside every root had read_file and
|
|
85
|
+
* write_file act there (the review of fix/r9-release-blockers' repair, R9C-ESCAPE-1). A root it names that is, or is
|
|
86
|
+
* named through, a link a command could have made (LINKED) allows nothing: canonicalized through the link on every call,
|
|
87
|
+
* it let write_file write HOME/.bashrc once a command had made a root not made yet (`./build`) a link there (the review
|
|
88
|
+
* of fix/r9-release-blockers, RV8-LINK). Nor does one ZTC couldn't look at (UNREADABLE: below a folder it can't look
|
|
89
|
+
* into), which threw on every call, whatever the call (R9C-TRUTH-5). A denial ZTC can't look up (a folder above it it
|
|
90
|
+
* can't look into) refuses every call, saying which folder and why (LOOKUP): it threw too (RV6-PATH).
|
|
91
|
+
*/
|
|
81
92
|
private profileRoots;
|
|
82
93
|
/**
|
|
83
94
|
* Why PATH is refused under this profile, SUBJECT naming what it is (a path a call names, a command's working
|
|
84
95
|
* directory), or null: it is in ZTC's own state (OWN_STATE_HOLDING says where; null checks none) under a profile that
|
|
85
96
|
* limits the agent, in a root the profile denies, or outside the roots it allows (ROOTS, profileRoots) and the folders
|
|
86
|
-
* ALSO_READ gives (canonical), which a command may read as its roots
|
|
97
|
+
* ALSO_READ gives (canonical), which a command may read as its roots; one in a root it names that is a link a command
|
|
98
|
+
* could have made (ROOTS.linked), as named or where the link leads, is refused naming the link.
|
|
87
99
|
*/
|
|
88
100
|
private refusePath;
|
|
89
101
|
/**
|