@luminascale/shepherd 0.0.0-stage → 0.6.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/.agents/agents/README.md +12 -0
- package/.agents/agents/planner.md +38 -0
- package/.agents/agents/reviewer.md +38 -0
- package/.agents/agents/scout.md +43 -0
- package/.agents/agents/worker.md +33 -0
- package/.agents/skills/smoke-test/SKILL.md +155 -0
- package/.agents/skills/smoke-test/references/forensics.md +46 -0
- package/.agents/skills/smoke-test/scripts/live-smoke-poll.mjs +130 -0
- package/.github/workflows/publish.yml +77 -0
- package/.pi/prompts/release.md +21 -0
- package/.prettierrc +10 -0
- package/AGENTS.md +88 -0
- package/CONTRIBUTING.md +177 -0
- package/LICENSE +201 -0
- package/README.md +397 -2
- package/docs/README.md +26 -0
- package/docs/guides/agent-definitions.md +42 -0
- package/docs/guides/diagnostics.md +199 -0
- package/docs/guides/installation.md +61 -0
- package/docs/guides/tool-reference.md +55 -0
- package/docs/manual-tests/ping-pong-peer-messaging.md +147 -0
- package/docs/plans/agent-labels.md +257 -0
- package/docs/plans/architecture.md +110 -0
- package/docs/plans/settings-scope.md +163 -0
- package/docs/plans/tool-surface-split.md +278 -0
- package/docs/reference/dictionary +26 -0
- package/docs/releasing.md +47 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/baseline.md +115 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/handoff.md +564 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase10-notes.md +109 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase6-notes.md +69 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase7-notes.md +100 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase8-notes.md +127 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase9-notes.md +104 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/plan.md +1093 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/spec.md +583 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/tasks.md +838 -0
- package/docs/specs/006-shepherd-tool-rendering/plan.md +175 -0
- package/docs/specs/006-shepherd-tool-rendering/spec.md +469 -0
- package/index.ts +602 -0
- package/package.json +112 -4
- package/scripts/capture-system-prompt.mjs +45 -0
- package/scripts/extract-pi-system-prompt.mjs +277 -0
- package/scripts/host-impact.mjs +74 -0
- package/scripts/resolve-agent.mjs +43 -0
- package/scripts/show-shepherd-orchestrator.mjs +58 -0
- package/scripts/show-shepherd-prompt.mjs +96 -0
- package/scripts/verify-suites.mjs +67 -0
- package/specs/001-artifacts/spec.md +436 -0
- package/specs/002-simplify-agent-orchestration/plan.md +287 -0
- package/specs/002-simplify-agent-orchestration/spec.md +323 -0
- package/specs/002-simplify-agent-orchestration/tasks.md +212 -0
- package/specs/003-orchestrator-session-artifacts/plan.md +396 -0
- package/specs/003-orchestrator-session-artifacts/spec.md +453 -0
- package/specs/003-orchestrator-session-artifacts/tasks.md +141 -0
- package/specs/004-asynchronous-prompt-watchers/plan.md +139 -0
- package/specs/004-asynchronous-prompt-watchers/spec.md +202 -0
- package/specs/004-asynchronous-prompt-watchers/tasks.md +126 -0
- package/specs/005-per-workspace-settings/plan.md +230 -0
- package/specs/005-per-workspace-settings/spec.md +368 -0
- package/specs/005-per-workspace-settings/tasks.md +178 -0
- package/specs/006-dual-runtime-herdr-durable/intent.md +86 -0
- package/specs/006-dual-runtime-herdr-durable/journal.md +80 -0
- package/specs/006-dual-runtime-herdr-durable/plan.md +242 -0
- package/specs/006-dual-runtime-herdr-durable/spec.md +389 -0
- package/specs/006-dual-runtime-herdr-durable/tasks.md +199 -0
- package/specs/007-unwatched-completion-notice/journal.md +145 -0
- package/specs/007-unwatched-completion-notice/plan.md +186 -0
- package/specs/007-unwatched-completion-notice/spec.md +284 -0
- package/specs/007-unwatched-completion-notice/tasks.md +147 -0
- package/specs/008-remote-machine-sheep/intent.md +174 -0
- package/specs/008-remote-machine-sheep/journal.md +57 -0
- package/specs/008-remote-machine-sheep/prerequisites.md +219 -0
- package/specs/009-hc-runtime/intent.md +44 -0
- package/specs/009-hc-runtime/plan.md +49 -0
- package/specs/009-hc-runtime/spec.md +118 -0
- package/specs/009-hc-runtime/tasks.md +62 -0
- package/specs/010-unseen-watch-parity/intent.md +57 -0
- package/specs/010-unseen-watch-parity/journal.md +172 -0
- package/specs/010-unseen-watch-parity/plan.md +74 -0
- package/specs/010-unseen-watch-parity/spec.md +191 -0
- package/specs/010-unseen-watch-parity/tasks.md +119 -0
- package/specs/011-hc-background-poll/intent.md +57 -0
- package/specs/011-hc-background-poll/journal.md +95 -0
- package/specs/011-hc-background-poll/plan.md +87 -0
- package/specs/011-hc-background-poll/spec.md +141 -0
- package/specs/011-hc-background-poll/tasks.md +83 -0
- package/specs/012-steer-default/intent.md +12 -0
- package/specs/012-steer-default/journal.md +40 -0
- package/specs/012-steer-default/plan.md +7 -0
- package/specs/012-steer-default/spec.md +42 -0
- package/specs/012-steer-default/tasks.md +6 -0
- package/specs/013-opencode-shepherd/handoff-t011.md +94 -0
- package/specs/013-opencode-shepherd/intent.md +59 -0
- package/specs/013-opencode-shepherd/plan.md +204 -0
- package/specs/013-opencode-shepherd/spec.md +258 -0
- package/specs/013-opencode-shepherd/tasks.md +263 -0
- package/src/core/artifact-sessions.ts +835 -0
- package/src/core/config.ts +329 -0
- package/src/core/discovery.ts +342 -0
- package/src/core/herdr.ts +1 -0
- package/src/core/host.ts +77 -0
- package/src/core/ids.ts +78 -0
- package/src/core/lifecycle.ts +1 -0
- package/src/core/messaging.ts +1 -0
- package/src/core/migration.ts +55 -0
- package/src/core/orchestration.ts +1 -0
- package/src/core/types.ts +143 -0
- package/src/core/unseen-completions.ts +114 -0
- package/src/extension/cli.ts +417 -0
- package/src/extension/config.ts +1 -0
- package/src/extension/settings-ui.ts +296 -0
- package/src/extension/shepherd-done.ts +768 -0
- package/src/extension/shepherd.ts +2548 -0
- package/src/extension/system-prompt.ts +38 -0
- package/src/extension/unseen-completions.ts +237 -0
- package/src/opencode/actions.ts +794 -0
- package/src/opencode/bridge.ts +777 -0
- package/src/opencode/display.ts +36 -0
- package/src/opencode/fieldnotes.ts +60 -0
- package/src/opencode/host.ts +62 -0
- package/src/opencode/orphans.ts +162 -0
- package/src/opencode/server.ts +458 -0
- package/src/runtimes/backend.ts +119 -0
- package/src/runtimes/detect.ts +102 -0
- package/src/runtimes/hc/hc.ts +527 -0
- package/src/runtimes/hc/runtime.ts +1898 -0
- package/src/runtimes/herdr/herdr.ts +912 -0
- package/src/runtimes/herdr/lifecycle.ts +1712 -0
- package/src/runtimes/herdr/messaging.ts +703 -0
- package/src/runtimes/herdr/orchestration.ts +1583 -0
- package/src/runtimes/herdr/runtime.ts +224 -0
- package/src/runtimes/runtime.ts +133 -0
- package/src/runtimes/settle-observations.ts +114 -0
- package/test/fixtures/context-project/AGENTS.md +2 -0
- package/test/fixtures/home/.agents/agents/same.md +6 -0
- package/test/fixtures/home/.agents/agents/shared-only.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/invalid-thinking.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/model-empty.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/model-explicit.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-absent.md +5 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-false.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-invalid.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-true.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-false.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-invalid.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-pi-docs.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/omit-true.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/only-user.md +9 -0
- package/test/fixtures/home/.pi/agent/agents/same.md +6 -0
- package/test/fixtures/proj/.agents/agents/proj-shared.md +6 -0
- package/test/fixtures/proj/.pi/agents/project-pi.md +6 -0
- package/test/fixtures/proj/.pi/agents/same.md +6 -0
- package/test/helpers/fake-clock.mjs +39 -0
- package/test/helpers/feature-contracts.mjs +44 -0
- package/test/helpers/test-utils.mjs +44 -0
- package/test/verify-artifact-sessions.mjs +258 -0
- package/test/verify-backend.mjs +297 -0
- package/test/verify-child-mislabel.mjs +135 -0
- package/test/verify-child-surface.mjs +321 -0
- package/test/verify-cli.mjs +197 -0
- package/test/verify-command-ux.mjs +100 -0
- package/test/verify-compat.mjs +32 -0
- package/test/verify-cross-host-notes.mjs +128 -0
- package/test/verify-delegate.mjs +161 -0
- package/test/verify-detect.mjs +151 -0
- package/test/verify-discovery.mjs +239 -0
- package/test/verify-done-nudge.mjs +238 -0
- package/test/verify-effective-prompt.mjs +98 -0
- package/test/verify-hc-matrix.mjs +246 -0
- package/test/verify-hc-poll.mjs +260 -0
- package/test/verify-host-docs.mjs +66 -0
- package/test/verify-host-impact.mjs +49 -0
- package/test/verify-ids.mjs +141 -0
- package/test/verify-launch.mjs +183 -0
- package/test/verify-message-routing.mjs +560 -0
- package/test/verify-messaging.mjs +303 -0
- package/test/verify-migration-notice.mjs +74 -0
- package/test/verify-multi-wait.mjs +42 -0
- package/test/verify-opencode-display.mjs +47 -0
- package/test/verify-opencode-fieldnotes.mjs +121 -0
- package/test/verify-opencode-notice.mjs +77 -0
- package/test/verify-opencode-nudge.mjs +116 -0
- package/test/verify-opencode-orphans.mjs +160 -0
- package/test/verify-opencode-surface.mjs +107 -0
- package/test/verify-packaging.mjs +82 -0
- package/test/verify-parent-surface.mjs +118 -0
- package/test/verify-phase0.mjs +95 -0
- package/test/verify-registry.mjs +124 -0
- package/test/verify-rename-migration.mjs +111 -0
- package/test/verify-rendering.mjs +379 -0
- package/test/verify-session-boundary.mjs +146 -0
- package/test/verify-settings.mjs +260 -0
- package/test/verify-stale-wait.mjs +339 -0
- package/test/verify-status-widget.mjs +377 -0
- package/test/verify-status.mjs +172 -0
- package/test/verify-task-completion.mjs +156 -0
- package/test/verify-task-failures.mjs +201 -0
- package/test/verify-task-mislabel.mjs +143 -0
- package/test/verify-task-registry.mjs +194 -0
- package/test/verify-task-watchers.mjs +217 -0
- package/test/verify-tool-schemas.mjs +120 -0
- package/test/verify-unseen-completions.mjs +1211 -0
- package/test/verify-watchers.mjs +181 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Phase 5 verification for explicit task completion handling. */
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import {
|
|
5
|
+
createChildBroker,
|
|
6
|
+
createEnvelope,
|
|
7
|
+
publishFromChild,
|
|
8
|
+
registerChild,
|
|
9
|
+
} from '../src/core/messaging.ts';
|
|
10
|
+
import {
|
|
11
|
+
currentParentBroker,
|
|
12
|
+
ensureParentBroker,
|
|
13
|
+
processParentBrokerMessages,
|
|
14
|
+
shutdownParentBroker,
|
|
15
|
+
} from '../src/core/lifecycle.ts';
|
|
16
|
+
import { LifecycleRegistry, lifecycleRegistry } from '../src/core/orchestration.ts';
|
|
17
|
+
|
|
18
|
+
// Use the exported process-global registry because the lifecycle broker
|
|
19
|
+
// monitor consumes the same registry as the parent extension.
|
|
20
|
+
const broker = ensureParentBroker('completion-test-session');
|
|
21
|
+
const scout = lifecycleRegistry.registerAgent({
|
|
22
|
+
agent: 'scout',
|
|
23
|
+
label: 'completion',
|
|
24
|
+
paneId: undefined,
|
|
25
|
+
});
|
|
26
|
+
const planner = lifecycleRegistry.registerAgent({
|
|
27
|
+
agent: 'planner',
|
|
28
|
+
label: 'completion',
|
|
29
|
+
paneId: undefined,
|
|
30
|
+
});
|
|
31
|
+
const foreign = lifecycleRegistry.registerAgent({
|
|
32
|
+
agent: 'worker',
|
|
33
|
+
label: 'completion',
|
|
34
|
+
paneId: undefined,
|
|
35
|
+
});
|
|
36
|
+
const scoutCap = registerChild(broker, scout.id);
|
|
37
|
+
const plannerCap = registerChild(broker, planner.id);
|
|
38
|
+
const foreignCap = registerChild(broker, foreign.id);
|
|
39
|
+
const scoutChild = createChildBroker({ rootDir: broker.rootDir, ...scoutCap });
|
|
40
|
+
const plannerChild = createChildBroker({ rootDir: broker.rootDir, ...plannerCap });
|
|
41
|
+
const foreignChild = createChildBroker({ rootDir: broker.rootDir, ...foreignCap });
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const task = lifecycleRegistry.createTask(scout, 'Complete the explicit completion test.');
|
|
45
|
+
lifecycleRegistry.setTaskRunning(task.id);
|
|
46
|
+
lifecycleRegistry.setAgentState(scout, 'idle');
|
|
47
|
+
assert.equal(lifecycleRegistry.getTask(task.id).state, 'running');
|
|
48
|
+
const completion = createEnvelope(
|
|
49
|
+
{
|
|
50
|
+
sessionId: scoutChild.sessionId,
|
|
51
|
+
brokerId: scoutChild.brokerId,
|
|
52
|
+
senderId: scoutChild.agentId,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
kind: 'task_done',
|
|
56
|
+
targetId: 'shepherd',
|
|
57
|
+
taskId: task.id,
|
|
58
|
+
status: 'completed',
|
|
59
|
+
summary: 'The explicit task is complete.',
|
|
60
|
+
delivery: 'followUp',
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
publishFromChild(scoutChild, completion);
|
|
64
|
+
const results = await processParentBrokerMessages();
|
|
65
|
+
assert.equal(results.length, 1);
|
|
66
|
+
assert.equal(results[0].status, 'completed');
|
|
67
|
+
assert.equal(results[0].text, 'The explicit task is complete.');
|
|
68
|
+
assert.equal(lifecycleRegistry.getTask(task.id).state, 'completed');
|
|
69
|
+
console.log('PASS explicit task-done envelope settles a task even after an idle child turn');
|
|
70
|
+
|
|
71
|
+
const duplicateResults = await processParentBrokerMessages();
|
|
72
|
+
assert.deepEqual(duplicateResults, []);
|
|
73
|
+
console.log('PASS consumed task-done envelopes do not produce duplicate settlement');
|
|
74
|
+
|
|
75
|
+
const waitingTask = lifecycleRegistry.createTask(planner, 'Wait for a required reply.');
|
|
76
|
+
lifecycleRegistry.setTaskRunning(waitingTask.id);
|
|
77
|
+
lifecycleRegistry.addPendingRequest(waitingTask.id, 'request-required');
|
|
78
|
+
lifecycleRegistry.setTaskWaiting(waitingTask.id);
|
|
79
|
+
const premature = createEnvelope(
|
|
80
|
+
{
|
|
81
|
+
sessionId: plannerChild.sessionId,
|
|
82
|
+
brokerId: plannerChild.brokerId,
|
|
83
|
+
senderId: plannerChild.agentId,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
kind: 'task_done',
|
|
87
|
+
targetId: 'shepherd',
|
|
88
|
+
taskId: waitingTask.id,
|
|
89
|
+
status: 'completed',
|
|
90
|
+
summary: 'This is premature.',
|
|
91
|
+
delivery: 'followUp',
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
publishFromChild(plannerChild, premature);
|
|
95
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
96
|
+
assert.equal(lifecycleRegistry.getTask(waitingTask.id).state, 'waiting');
|
|
97
|
+
console.log('PASS successful completion is rejected while required requests remain pending');
|
|
98
|
+
|
|
99
|
+
const blocked = createEnvelope(
|
|
100
|
+
{
|
|
101
|
+
sessionId: plannerChild.sessionId,
|
|
102
|
+
brokerId: plannerChild.brokerId,
|
|
103
|
+
senderId: plannerChild.agentId,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
kind: 'task_done',
|
|
107
|
+
targetId: 'shepherd',
|
|
108
|
+
taskId: waitingTask.id,
|
|
109
|
+
status: 'blocked',
|
|
110
|
+
summary: 'The required reply never arrived.',
|
|
111
|
+
delivery: 'followUp',
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
publishFromChild(plannerChild, blocked);
|
|
115
|
+
const blockedResult = await processParentBrokerMessages();
|
|
116
|
+
assert.equal(blockedResult[0].status, 'blocked');
|
|
117
|
+
assert.equal(lifecycleRegistry.getTask(waitingTask.id).state, 'blocked');
|
|
118
|
+
console.log('PASS blocked completion explicitly settles a waiting task');
|
|
119
|
+
|
|
120
|
+
const foreignTask = lifecycleRegistry.createTask(scout, 'Reject foreign completion.');
|
|
121
|
+
lifecycleRegistry.setTaskRunning(foreignTask.id);
|
|
122
|
+
const foreignCompletion = createEnvelope(
|
|
123
|
+
{
|
|
124
|
+
sessionId: foreignChild.sessionId,
|
|
125
|
+
brokerId: foreignChild.brokerId,
|
|
126
|
+
senderId: foreignChild.agentId,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
kind: 'task_done',
|
|
130
|
+
targetId: 'shepherd',
|
|
131
|
+
taskId: foreignTask.id,
|
|
132
|
+
status: 'completed',
|
|
133
|
+
summary: 'Wrong owner.',
|
|
134
|
+
delivery: 'followUp',
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
publishFromChild(foreignChild, foreignCompletion);
|
|
138
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
139
|
+
assert.equal(lifecycleRegistry.getTask(foreignTask.id).state, 'running');
|
|
140
|
+
console.log('PASS foreign child completion is rejected without settling the task');
|
|
141
|
+
|
|
142
|
+
lifecycleRegistry.settleTask(foreignTask.id, { status: 'cancelled', error: 'test cleanup' });
|
|
143
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
144
|
+
} finally {
|
|
145
|
+
for (const agent of [scout, planner, foreign]) {
|
|
146
|
+
const active = lifecycleRegistry.activeTaskForAgent(agent);
|
|
147
|
+
if (active)
|
|
148
|
+
lifecycleRegistry.settleTask(active.taskId, { status: 'cancelled', error: 'test cleanup' });
|
|
149
|
+
}
|
|
150
|
+
shutdownParentBroker(() => true);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Keep the import above as a deliberate guard against accidentally replacing
|
|
154
|
+
// the process-global lifecycle registry with an unrelated local registry.
|
|
155
|
+
assert.ok(new LifecycleRegistry());
|
|
156
|
+
console.log('All task completion assertions passed.');
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Phase 5 failure-path verification: provider errors, unexpected pane exit,
|
|
4
|
+
* close-to-cancellation, and deadline timeout.
|
|
5
|
+
*
|
|
6
|
+
* The parent runtime monitor (processParentBrokerMessages) observes external
|
|
7
|
+
* terminal failures through the Herdr CLI: `pane list` for pane survival and
|
|
8
|
+
* `agent read` for provider-error text. A fake `herdr` executable on PATH
|
|
9
|
+
* (a small Node script backed by a JSON state file) keeps those observations
|
|
10
|
+
* deterministic.
|
|
11
|
+
*/
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import {
|
|
16
|
+
closeAgent,
|
|
17
|
+
ensureParentBroker,
|
|
18
|
+
processParentBrokerMessages,
|
|
19
|
+
shutdownParentBroker,
|
|
20
|
+
} from '../src/core/lifecycle.ts';
|
|
21
|
+
import { recordCreatedPane } from '../src/core/herdr.ts';
|
|
22
|
+
import { lifecycleRegistry } from '../src/core/orchestration.ts';
|
|
23
|
+
import { withTempDirectory } from './helpers/test-utils.mjs';
|
|
24
|
+
|
|
25
|
+
function writeState(stateFile, { panes, errorPanes = [] }) {
|
|
26
|
+
fs.writeFileSync(stateFile, JSON.stringify({ panes, errorPanes }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await withTempDirectory('pi-shepherd-task-failures-', async root => {
|
|
30
|
+
const bin = path.join(root, 'bin');
|
|
31
|
+
const agentDir = path.join(root, 'agent-dir');
|
|
32
|
+
const stateFile = path.join(root, 'herdr-state.json');
|
|
33
|
+
fs.mkdirSync(bin);
|
|
34
|
+
const fakePath = path.join(bin, 'herdr');
|
|
35
|
+
// Inline the state file path into the generated script.
|
|
36
|
+
const stateBody = [
|
|
37
|
+
'#!/usr/bin/env node',
|
|
38
|
+
'const fs = require("node:fs");',
|
|
39
|
+
`const state = JSON.parse(fs.readFileSync('${stateFile}', "utf8"));`,
|
|
40
|
+
'const [cmd, sub, target] = process.argv.slice(2);',
|
|
41
|
+
'if (cmd === "pane" && sub === "list") {',
|
|
42
|
+
' process.stdout.write(JSON.stringify({ result: { panes: (state.panes ?? []).map(id => ({ pane_id: id })) } }));',
|
|
43
|
+
'} else if (cmd === "pane" && sub === "close") {',
|
|
44
|
+
' state.panes = (state.panes ?? []).filter(id => id !== target);',
|
|
45
|
+
` fs.writeFileSync(${JSON.stringify(stateFile)}, JSON.stringify(state));`,
|
|
46
|
+
'} else if (cmd === "agent" && sub === "read") {',
|
|
47
|
+
' if ((state.errorPanes ?? []).includes(target)) {',
|
|
48
|
+
' process.stdout.write("Error: provider authentication failed\\n");',
|
|
49
|
+
' }',
|
|
50
|
+
'}',
|
|
51
|
+
'process.exit(0);',
|
|
52
|
+
'',
|
|
53
|
+
].join('\n');
|
|
54
|
+
fs.writeFileSync(fakePath, stateBody);
|
|
55
|
+
fs.chmodSync(fakePath, 0o755);
|
|
56
|
+
writeState(stateFile, {
|
|
57
|
+
panes: ['pane-provider', 'pane-exited', 'pane-healthy'],
|
|
58
|
+
errorPanes: [],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const oldPath = process.env.PATH;
|
|
62
|
+
const oldAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
63
|
+
process.env.PATH = `${bin}${path.delimiter}${oldPath ?? ''}`;
|
|
64
|
+
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const broker = ensureParentBroker('task-failure-test-session');
|
|
68
|
+
assert.ok(broker);
|
|
69
|
+
|
|
70
|
+
// ── Provider failure + unexpected pane exit ────────────────────────────
|
|
71
|
+
const providerAgent = lifecycleRegistry.registerAgent({
|
|
72
|
+
agent: 'worker',
|
|
73
|
+
label: 'provider failure',
|
|
74
|
+
paneId: 'pane-provider',
|
|
75
|
+
});
|
|
76
|
+
const exitedAgent = lifecycleRegistry.registerAgent({
|
|
77
|
+
agent: 'scout',
|
|
78
|
+
label: 'exited pane',
|
|
79
|
+
paneId: 'pane-exited',
|
|
80
|
+
});
|
|
81
|
+
const healthyAgent = lifecycleRegistry.registerAgent({
|
|
82
|
+
agent: 'planner',
|
|
83
|
+
label: 'healthy pane',
|
|
84
|
+
paneId: 'pane-healthy',
|
|
85
|
+
});
|
|
86
|
+
const providerTask = lifecycleRegistry.createTask(
|
|
87
|
+
providerAgent,
|
|
88
|
+
'Task that meets a provider error.'
|
|
89
|
+
);
|
|
90
|
+
const exitedTask = lifecycleRegistry.createTask(exitedAgent, 'Task whose pane exits.');
|
|
91
|
+
const healthyTask = lifecycleRegistry.createTask(healthyAgent, 'Task on a healthy pane.');
|
|
92
|
+
for (const id of [providerTask.id, exitedTask.id, healthyTask.id]) {
|
|
93
|
+
lifecycleRegistry.setTaskRunning(id);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
97
|
+
assert.equal(lifecycleRegistry.getTask(providerTask.id).state, 'running');
|
|
98
|
+
assert.equal(lifecycleRegistry.getTask(exitedTask.id).state, 'running');
|
|
99
|
+
assert.equal(lifecycleRegistry.getTask(healthyTask.id).state, 'running');
|
|
100
|
+
console.log('PASS live panes with clean output do not fail tracked tasks');
|
|
101
|
+
|
|
102
|
+
// Simulate the provider dying and a second pane exiting mid-task.
|
|
103
|
+
// The 250ms monitor (or the explicit drain below, whichever wins)
|
|
104
|
+
// performs the runtime observation; task registry state is the
|
|
105
|
+
// authoritative assertion either way.
|
|
106
|
+
writeState(stateFile, {
|
|
107
|
+
panes: ['pane-provider', 'pane-healthy'],
|
|
108
|
+
errorPanes: ['pane-provider'],
|
|
109
|
+
});
|
|
110
|
+
let sawFailure = false;
|
|
111
|
+
for (let i = 0; i < 8 && !sawFailure; i++) {
|
|
112
|
+
await processParentBrokerMessages();
|
|
113
|
+
sawFailure = [
|
|
114
|
+
lifecycleRegistry.taskResult(providerTask.id),
|
|
115
|
+
lifecycleRegistry.taskResult(exitedTask.id),
|
|
116
|
+
].every(r => r?.status === 'failed');
|
|
117
|
+
if (!sawFailure) await new Promise(resolve => setTimeout(resolve, 250));
|
|
118
|
+
}
|
|
119
|
+
assert.ok(sawFailure, 'provider failure and pane exit settled both tasks');
|
|
120
|
+
|
|
121
|
+
const providerResult = lifecycleRegistry.taskResult(providerTask.id);
|
|
122
|
+
assert.equal(providerResult?.status, 'failed');
|
|
123
|
+
assert.equal(providerResult?.returnCode, 1);
|
|
124
|
+
assert.match(providerResult?.error ?? '', /provider authentication failed/);
|
|
125
|
+
console.log('PASS provider error in pane output settles the task as failed');
|
|
126
|
+
|
|
127
|
+
const exitedResult = lifecycleRegistry.taskResult(exitedTask.id);
|
|
128
|
+
assert.equal(exitedResult?.status, 'failed');
|
|
129
|
+
assert.match(exitedResult?.error ?? '', /pane disappeared/);
|
|
130
|
+
console.log('PASS unexpected agent pane exit settles the task as failed');
|
|
131
|
+
|
|
132
|
+
assert.equal(lifecycleRegistry.getTask(healthyTask.id).state, 'running');
|
|
133
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
134
|
+
console.log('PASS a healthy pane task stays running and failure observation stays idempotent');
|
|
135
|
+
lifecycleRegistry.settleTask(healthyTask.id, { status: 'cancelled', error: 'test cleanup' });
|
|
136
|
+
|
|
137
|
+
// ── Close maps to task cancellation ────────────────────────────────────
|
|
138
|
+
writeState(stateFile, {
|
|
139
|
+
panes: ['pane-provider', 'pane-healthy', 'pane-closed'],
|
|
140
|
+
errorPanes: [],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const closedAgent = lifecycleRegistry.registerAgent({
|
|
144
|
+
agent: 'planner',
|
|
145
|
+
label: 'close target',
|
|
146
|
+
paneId: 'pane-closed',
|
|
147
|
+
});
|
|
148
|
+
recordCreatedPane({
|
|
149
|
+
paneId: 'pane-closed',
|
|
150
|
+
tabId: 'tab-closed',
|
|
151
|
+
name: 'close-target',
|
|
152
|
+
cwd: root,
|
|
153
|
+
createdAt: Date.now(),
|
|
154
|
+
ownerSession: 'task-failure-test-session',
|
|
155
|
+
});
|
|
156
|
+
const closedTask = lifecycleRegistry.createTask(
|
|
157
|
+
closedAgent,
|
|
158
|
+
'Task that gets closed mid-flight.'
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
closeAgent(closedAgent);
|
|
162
|
+
|
|
163
|
+
const cancelledResult = lifecycleRegistry.taskResult(closedTask.id);
|
|
164
|
+
assert.equal(cancelledResult?.status, 'cancelled');
|
|
165
|
+
assert.equal(cancelledResult?.returnCode, 130);
|
|
166
|
+
assert.match(cancelledResult?.error ?? '', /closed/i);
|
|
167
|
+
assert.equal(lifecycleRegistry.getAgent(closedAgent).state, 'closed');
|
|
168
|
+
assert.equal(lifecycleRegistry.activeTaskForAgent(closedAgent), undefined);
|
|
169
|
+
console.log('PASS closing an agent cancels its active tracked task');
|
|
170
|
+
|
|
171
|
+
// ── Deadline expiry maps to task timeout ───────────────────────────────
|
|
172
|
+
const timeoutAgent = lifecycleRegistry.registerAgent({
|
|
173
|
+
agent: 'worker',
|
|
174
|
+
label: 'deadline target',
|
|
175
|
+
paneId: 'pane-healthy',
|
|
176
|
+
});
|
|
177
|
+
const deadlineTask = lifecycleRegistry.createTask(timeoutAgent, 'Task that must time out.', {
|
|
178
|
+
timeoutMs: 300,
|
|
179
|
+
});
|
|
180
|
+
assert.equal(lifecycleRegistry.getTask(deadlineTask.id).state, 'created');
|
|
181
|
+
assert.ok(lifecycleRegistry.getTask(deadlineTask.id).deadlineAt !== undefined);
|
|
182
|
+
|
|
183
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
184
|
+
const timedOutResult = lifecycleRegistry.taskResult(deadlineTask.id);
|
|
185
|
+
assert.equal(timedOutResult?.status, 'timed_out');
|
|
186
|
+
assert.equal(timedOutResult?.returnCode, 124);
|
|
187
|
+
assert.match(timedOutResult?.error ?? '', /deadline/i);
|
|
188
|
+
console.log('PASS deadline expiry settles the task as timed_out through the real timer');
|
|
189
|
+
|
|
190
|
+
assert.strictEqual(
|
|
191
|
+
shutdownParentBroker(() => true),
|
|
192
|
+
true
|
|
193
|
+
);
|
|
194
|
+
} finally {
|
|
195
|
+
process.env.PATH = oldPath;
|
|
196
|
+
if (oldAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
197
|
+
else process.env.PI_CODING_AGENT_DIR = oldAgentDir;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
console.log('All task failure assertions passed.');
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Phase 6 verification for the task-mislabel fix (issue #13): the child LLM
|
|
4
|
+
* can echo a fabricated or foreign task id in shepherd_done. The parent must
|
|
5
|
+
* correlate the completion on the authenticated sender's active task, keep a
|
|
6
|
+
* diagnostic for unresolvable completions, and never silently ack one.
|
|
7
|
+
*/
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {
|
|
12
|
+
createChildBroker,
|
|
13
|
+
createEnvelope,
|
|
14
|
+
publishFromChild,
|
|
15
|
+
registerChild,
|
|
16
|
+
} from '../src/core/messaging.ts';
|
|
17
|
+
import {
|
|
18
|
+
configureParentMessageNotifications,
|
|
19
|
+
ensureParentBroker,
|
|
20
|
+
processParentBrokerMessages,
|
|
21
|
+
shutdownParentBroker,
|
|
22
|
+
} from '../src/core/lifecycle.ts';
|
|
23
|
+
import { lifecycleRegistry } from '../src/core/orchestration.ts';
|
|
24
|
+
|
|
25
|
+
const broker = ensureParentBroker('mislabel-test-session');
|
|
26
|
+
const worker = lifecycleRegistry.registerAgent({
|
|
27
|
+
agent: 'worker',
|
|
28
|
+
label: 'mislabel',
|
|
29
|
+
paneId: undefined,
|
|
30
|
+
});
|
|
31
|
+
const planner = lifecycleRegistry.registerAgent({
|
|
32
|
+
agent: 'planner',
|
|
33
|
+
label: 'mislabel',
|
|
34
|
+
paneId: undefined,
|
|
35
|
+
});
|
|
36
|
+
const workerCap = registerChild(broker, worker.id);
|
|
37
|
+
const plannerCap = registerChild(broker, planner.id);
|
|
38
|
+
const workerChild = createChildBroker({ rootDir: broker.rootDir, ...workerCap });
|
|
39
|
+
const plannerChild = createChildBroker({ rootDir: broker.rootDir, ...plannerCap });
|
|
40
|
+
|
|
41
|
+
const dropped = [];
|
|
42
|
+
configureParentMessageNotifications(notification => {
|
|
43
|
+
if (notification.kind === 'task_done_dropped') {
|
|
44
|
+
dropped.push({ envelope: notification.envelope, reason: notification.reason });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const taskDone = (child, taskId, status, summary) =>
|
|
49
|
+
createEnvelope(
|
|
50
|
+
{ sessionId: child.sessionId, brokerId: child.brokerId, senderId: child.agentId },
|
|
51
|
+
{
|
|
52
|
+
kind: 'task_done',
|
|
53
|
+
targetId: 'shepherd',
|
|
54
|
+
taskId,
|
|
55
|
+
status,
|
|
56
|
+
summary,
|
|
57
|
+
delivery: 'followUp',
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const rejectedFiles = (prefix) =>
|
|
62
|
+
fs.readdirSync(path.join(broker.rootDir, 'rejected')).filter(name => name.startsWith(prefix));
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// 1. A sender with an active task publishes a completion whose id is
|
|
66
|
+
// fabricated: the completion settles the sender's own task and the
|
|
67
|
+
// watcher is woken, with a diagnostic recording the mismatch.
|
|
68
|
+
const task = lifecycleRegistry.createTask(worker, 'Implement the engine wiring.');
|
|
69
|
+
lifecycleRegistry.setTaskRunning(task.id);
|
|
70
|
+
const watch = lifecycleRegistry.waitForTasks(task.id);
|
|
71
|
+
publishFromChild(workerChild, taskDone(workerChild, 'T2854-9715', 'completed', 'M2 engine wiring complete.'));
|
|
72
|
+
const results = await processParentBrokerMessages();
|
|
73
|
+
assert.equal(results.length, 1);
|
|
74
|
+
assert.equal(results[0].taskId, task.id);
|
|
75
|
+
assert.equal(results[0].status, 'completed');
|
|
76
|
+
assert.equal(results[0].text, 'M2 engine wiring complete.');
|
|
77
|
+
assert.equal(lifecycleRegistry.getTask(task.id).state, 'completed');
|
|
78
|
+
const [settled] = await watch;
|
|
79
|
+
assert.equal(settled.status, 'completed');
|
|
80
|
+
const mismatches = rejectedFiles('task-done-mismatch-');
|
|
81
|
+
assert.equal(mismatches.length, 1);
|
|
82
|
+
const mismatch = JSON.parse(
|
|
83
|
+
fs.readFileSync(path.join(broker.rootDir, 'rejected', mismatches[0]), 'utf8')
|
|
84
|
+
);
|
|
85
|
+
assert.match(mismatch.reason, /T2854-9715/);
|
|
86
|
+
console.log(
|
|
87
|
+
'PASS a completion with a fabricated task id settles the sender active task and wakes its watcher'
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// 2. A sender without an active task publishes an unknown id: nothing
|
|
91
|
+
// settles, the drop is surfaced to the parent, and a diagnostic remains.
|
|
92
|
+
const otherTask = lifecycleRegistry.createTask(planner, 'Unrelated running work.');
|
|
93
|
+
lifecycleRegistry.setTaskRunning(otherTask.id);
|
|
94
|
+
publishFromChild(workerChild, taskDone(workerChild, 'T9999-4242', 'failed', 'No such task.'));
|
|
95
|
+
assert.deepEqual(await processParentBrokerMessages(), []);
|
|
96
|
+
assert.equal(lifecycleRegistry.getTask(otherTask.id).state, 'running');
|
|
97
|
+
assert.equal(dropped.length, 1);
|
|
98
|
+
assert.equal(dropped[0].envelope.taskId, 'T9999-4242');
|
|
99
|
+
assert.match(dropped[0].reason ?? '', /no active task/);
|
|
100
|
+
const droppedFiles = rejectedFiles('task-done-dropped-');
|
|
101
|
+
assert.equal(droppedFiles.length, 1);
|
|
102
|
+
const droppedRecord = JSON.parse(
|
|
103
|
+
fs.readFileSync(path.join(broker.rootDir, 'rejected', droppedFiles[0]), 'utf8')
|
|
104
|
+
);
|
|
105
|
+
assert.match(droppedRecord.reason, /no active task/);
|
|
106
|
+
console.log(
|
|
107
|
+
'PASS a completion with no matching task is dropped observably without settling anything'
|
|
108
|
+
);
|
|
109
|
+
lifecycleRegistry.settleTask(otherTask.id, { status: 'cancelled', error: 'scenario cleanup' });
|
|
110
|
+
|
|
111
|
+
// 3. A sender with its own active task echoes a known task id owned by
|
|
112
|
+
// another agent: the foreign task is left untouched and the sender's
|
|
113
|
+
// own task settles.
|
|
114
|
+
const own = lifecycleRegistry.createTask(worker, 'Own work to finish.');
|
|
115
|
+
lifecycleRegistry.setTaskRunning(own.id);
|
|
116
|
+
const foreign = lifecycleRegistry.createTask(planner, 'Foreign task to ignore.');
|
|
117
|
+
lifecycleRegistry.setTaskRunning(foreign.id);
|
|
118
|
+
publishFromChild(workerChild, taskDone(workerChild, foreign.id, 'completed', 'Done with the other one.'));
|
|
119
|
+
const foreignResults = await processParentBrokerMessages();
|
|
120
|
+
assert.equal(foreignResults.length, 1);
|
|
121
|
+
assert.equal(foreignResults[0].taskId, own.id);
|
|
122
|
+
assert.equal(lifecycleRegistry.getTask(own.id).state, 'completed');
|
|
123
|
+
assert.equal(lifecycleRegistry.getTask(foreign.id).state, 'running');
|
|
124
|
+
console.log('PASS a completion mislabeled with a foreign task id settles the sender own task');
|
|
125
|
+
|
|
126
|
+
// 4. A duplicate completion of an already-settled task stays idempotent.
|
|
127
|
+
publishFromChild(workerChild, taskDone(workerChild, own.id, 'completed', 'Again.'));
|
|
128
|
+
const duplicate = await processParentBrokerMessages();
|
|
129
|
+
assert.equal(duplicate.length, 1);
|
|
130
|
+
assert.equal(duplicate[0].taskId, own.id);
|
|
131
|
+
assert.equal(duplicate[0].status, 'completed');
|
|
132
|
+
console.log('PASS a duplicate completion of a settled task returns the stored result');
|
|
133
|
+
} finally {
|
|
134
|
+
for (const agent of [worker, planner]) {
|
|
135
|
+
const active = lifecycleRegistry.activeTaskForAgent(agent);
|
|
136
|
+
if (active) {
|
|
137
|
+
lifecycleRegistry.settleTask(active.taskId, { status: 'cancelled', error: 'test cleanup' });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
shutdownParentBroker(() => true);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log('All task mislabel assertions passed.');
|