@crouton-kit/crouter 0.3.16 → 0.3.18
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/dist/builtin-personas/design/{base.md → PERSONA.md} +4 -0
- package/dist/builtin-personas/developer/{base.md → PERSONA.md} +4 -0
- package/dist/builtin-personas/explore/{base.md → PERSONA.md} +4 -0
- package/dist/builtin-personas/general/{base.md → PERSONA.md} +4 -0
- package/dist/builtin-personas/orchestration-kernel.md +6 -6
- package/dist/builtin-personas/plan/{base.md → PERSONA.md} +5 -1
- package/dist/builtin-personas/plan/reviewers/architecture-fit/{base.md → PERSONA.md} +1 -1
- package/dist/builtin-personas/plan/reviewers/code-smells/{base.md → PERSONA.md} +1 -1
- package/dist/builtin-personas/plan/reviewers/pattern-consistency/{base.md → PERSONA.md} +1 -1
- package/dist/builtin-personas/plan/reviewers/requirements-coverage/{base.md → PERSONA.md} +1 -1
- package/dist/builtin-personas/plan/reviewers/security/{base.md → PERSONA.md} +1 -1
- package/dist/builtin-personas/review/{base.md → PERSONA.md} +4 -0
- package/dist/builtin-personas/spec/{base.md → PERSONA.md} +5 -1
- package/dist/builtin-skills/skills/crouter-development/personas/SKILL.md +24 -14
- package/dist/builtin-skills/skills/crouter-development/personas/base-prompt/SKILL.md +4 -4
- package/dist/commands/canvas-browse.d.ts +2 -0
- package/dist/commands/canvas-browse.js +45 -0
- package/dist/commands/canvas-prune.js +11 -2
- package/dist/commands/canvas.js +3 -2
- package/dist/commands/daemon.js +1 -1
- package/dist/commands/human/prompts.js +3 -9
- package/dist/commands/human/shared.d.ts +26 -1
- package/dist/commands/human/shared.js +48 -10
- package/dist/commands/node.js +66 -4
- package/dist/commands/skill/author.js +2 -2
- package/dist/core/__tests__/cascade-close.test.js +199 -0
- package/dist/core/__tests__/daemon-boot.test.js +7 -0
- package/dist/core/__tests__/daemon-liveness.test.js +59 -4
- package/dist/core/__tests__/dead-pane-regression.test.js +151 -0
- package/dist/core/__tests__/fixtures/fake-pi-host.d.ts +2 -0
- package/dist/core/__tests__/fixtures/fake-pi-host.js +301 -0
- package/dist/core/__tests__/flagship-lifecycle.test.js +273 -0
- package/dist/core/__tests__/grace-clock.test.d.ts +1 -0
- package/dist/core/__tests__/grace-clock.test.js +115 -0
- package/dist/core/__tests__/helpers/harness.d.ts +78 -0
- package/dist/core/__tests__/helpers/harness.js +406 -0
- package/dist/core/__tests__/human-surface-target.test.d.ts +1 -0
- package/dist/core/__tests__/human-surface-target.test.js +98 -0
- package/dist/core/__tests__/lifecycle.test.js +6 -13
- package/dist/core/__tests__/live-mutation.test.d.ts +1 -0
- package/dist/core/__tests__/live-mutation.test.js +341 -0
- package/dist/core/__tests__/persona-subkind.test.js +18 -15
- package/dist/core/__tests__/placement-focus.test.js +53 -15
- package/dist/core/__tests__/relaunch.test.js +12 -12
- package/dist/core/__tests__/reset.test.js +11 -6
- package/dist/core/__tests__/spike-harness.test.d.ts +1 -0
- package/dist/core/__tests__/spike-harness.test.js +241 -0
- package/dist/core/__tests__/subscription-delivery.test.d.ts +1 -0
- package/dist/core/__tests__/subscription-delivery.test.js +233 -0
- package/dist/core/canvas/browse/__tests__/model.test.d.ts +1 -0
- package/dist/core/canvas/browse/__tests__/model.test.js +142 -0
- package/dist/core/canvas/browse/__tests__/render.test.d.ts +1 -0
- package/dist/core/canvas/browse/__tests__/render.test.js +102 -0
- package/dist/core/canvas/browse/app.d.ts +4 -0
- package/dist/core/canvas/browse/app.js +349 -0
- package/dist/core/canvas/browse/model.d.ts +97 -0
- package/dist/core/canvas/browse/model.js +258 -0
- package/dist/core/canvas/browse/render.d.ts +41 -0
- package/dist/core/canvas/browse/render.js +387 -0
- package/dist/core/canvas/browse/terminal.d.ts +23 -0
- package/dist/core/canvas/browse/terminal.js +100 -0
- package/dist/core/canvas/canvas.d.ts +9 -2
- package/dist/core/canvas/canvas.js +41 -3
- package/dist/core/canvas/paths.d.ts +4 -1
- package/dist/core/canvas/paths.js +10 -4
- package/dist/core/canvas/render.d.ts +10 -0
- package/dist/core/canvas/render.js +25 -1
- package/dist/core/canvas/types.js +2 -2
- package/dist/core/feed/inbox.d.ts +0 -3
- package/dist/core/feed/inbox.js +1 -5
- package/dist/core/help.d.ts +6 -0
- package/dist/core/help.js +7 -0
- package/dist/core/personas/index.d.ts +4 -3
- package/dist/core/personas/index.js +3 -2
- package/dist/core/personas/loader.d.ts +34 -16
- package/dist/core/personas/loader.js +102 -29
- package/dist/core/personas/resolve.d.ts +4 -4
- package/dist/core/personas/resolve.js +16 -14
- package/dist/core/runtime/busy.d.ts +8 -0
- package/dist/core/runtime/busy.js +46 -0
- package/dist/core/runtime/lifecycle.d.ts +1 -1
- package/dist/core/runtime/lifecycle.js +12 -4
- package/dist/core/runtime/naming.d.ts +3 -3
- package/dist/core/runtime/naming.js +6 -6
- package/dist/core/runtime/placement.d.ts +32 -5
- package/dist/core/runtime/placement.js +81 -14
- package/dist/core/runtime/reset.d.ts +11 -8
- package/dist/core/runtime/reset.js +23 -18
- package/dist/core/spawn.d.ts +20 -1
- package/dist/core/spawn.js +52 -5
- package/dist/daemon/crtrd.js +43 -21
- package/dist/pi-extensions/canvas-nav.js +106 -55
- package/dist/pi-extensions/canvas-resume.d.ts +0 -1
- package/dist/pi-extensions/canvas-resume.js +35 -126
- package/dist/pi-extensions/canvas-stophook.d.ts +1 -1
- package/dist/pi-extensions/canvas-stophook.js +16 -0
- package/dist/prompts/skill.js +6 -1
- package/package.json +1 -1
- package/dist/commands/__tests__/skill.test.js +0 -290
- package/dist/core/__tests__/pkg.test.js +0 -218
- package/dist/core/__tests__/sys.test.js +0 -208
- /package/dist/{commands/__tests__/skill.test.d.ts → core/__tests__/cascade-close.test.d.ts} +0 -0
- /package/dist/core/__tests__/{pkg.test.d.ts → dead-pane-regression.test.d.ts} +0 -0
- /package/dist/core/__tests__/{sys.test.d.ts → flagship-lifecycle.test.d.ts} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Run with: node --import tsx/esm --test src/core/__tests__/human-surface-target.test.ts
|
|
2
|
+
//
|
|
3
|
+
// BUG REGRESSION: `crtr human ask|approve|review|notify` surfaced its humanloop
|
|
4
|
+
// TUI in the backstage `crtr` session (the asking node's own pane) — a session
|
|
5
|
+
// the user never watches — because spawnAndDetach was called with no `-t`
|
|
6
|
+
// target. The fix routes the TUI to the HIGHEST FOCUSED node of the asking
|
|
7
|
+
// node's graph (the viewport the user is actually watching the work in).
|
|
8
|
+
//
|
|
9
|
+
// This locks in the PURE selection (`graphSurfaceTarget`, db-only, no tmux):
|
|
10
|
+
// walk the asking node's spine to its root, enumerate the tree root-first, and
|
|
11
|
+
// return the focus row of the node closest to the root that occupies a viewport.
|
|
12
|
+
import { test, before, after, beforeEach } from 'node:test';
|
|
13
|
+
import assert from 'node:assert/strict';
|
|
14
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { createNode, subscribe } from '../canvas/canvas.js';
|
|
18
|
+
import { openFocusRow, closeFocusRow, getFocusByNode } from '../canvas/focuses.js';
|
|
19
|
+
import { closeDb } from '../canvas/db.js';
|
|
20
|
+
import { graphSurfaceTarget } from '../runtime/placement.js';
|
|
21
|
+
let home;
|
|
22
|
+
let savedTmux;
|
|
23
|
+
function node(id, parent) {
|
|
24
|
+
return {
|
|
25
|
+
node_id: id,
|
|
26
|
+
name: id,
|
|
27
|
+
created: new Date().toISOString(),
|
|
28
|
+
cwd: '/tmp/work',
|
|
29
|
+
kind: 'developer',
|
|
30
|
+
mode: 'base',
|
|
31
|
+
lifecycle: 'terminal',
|
|
32
|
+
status: 'active',
|
|
33
|
+
parent,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
before(() => {
|
|
37
|
+
home = mkdtempSync(join(tmpdir(), 'crtr-human-surface-'));
|
|
38
|
+
process.env['CRTR_HOME'] = home;
|
|
39
|
+
savedTmux = process.env['TMUX'];
|
|
40
|
+
delete process.env['TMUX']; // PURE: graphSurfaceTarget never touches tmux
|
|
41
|
+
});
|
|
42
|
+
after(() => {
|
|
43
|
+
closeDb();
|
|
44
|
+
if (savedTmux !== undefined)
|
|
45
|
+
process.env['TMUX'] = savedTmux;
|
|
46
|
+
rmSync(home, { recursive: true, force: true });
|
|
47
|
+
});
|
|
48
|
+
// Graph R → M → W (parent edges + the auto-subscribe spine the runtime builds:
|
|
49
|
+
// a parent subscribes_to its child, so view(R) walks down to M then W).
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
closeDb();
|
|
52
|
+
rmSync(home, { recursive: true, force: true });
|
|
53
|
+
home = mkdtempSync(join(tmpdir(), 'crtr-human-surface-'));
|
|
54
|
+
process.env['CRTR_HOME'] = home;
|
|
55
|
+
createNode(node('R', null));
|
|
56
|
+
createNode(node('M', 'R'));
|
|
57
|
+
createNode(node('W', 'M'));
|
|
58
|
+
subscribe('R', 'M');
|
|
59
|
+
subscribe('M', 'W');
|
|
60
|
+
});
|
|
61
|
+
test('highest focused = the root when only the root is on screen', () => {
|
|
62
|
+
openFocusRow('f-r', '%10', 'work', 'R');
|
|
63
|
+
const t = graphSurfaceTarget('W');
|
|
64
|
+
assert.equal(t?.node_id, 'R');
|
|
65
|
+
assert.equal(t?.pane, '%10');
|
|
66
|
+
});
|
|
67
|
+
test('falls to the focused mid-orchestrator when the root is NOT on screen', () => {
|
|
68
|
+
openFocusRow('f-m', '%20', 'work', 'M');
|
|
69
|
+
assert.equal(graphSurfaceTarget('W')?.node_id, 'M');
|
|
70
|
+
});
|
|
71
|
+
test('picks the SHALLOWEST focused node when several are on screen', () => {
|
|
72
|
+
openFocusRow('f-m', '%20', 'work', 'M');
|
|
73
|
+
openFocusRow('f-w', '%30', 'work', 'W');
|
|
74
|
+
// M is closer to the root than W → M wins.
|
|
75
|
+
assert.equal(graphSurfaceTarget('W')?.node_id, 'M');
|
|
76
|
+
openFocusRow('f-r', '%10', 'work', 'R');
|
|
77
|
+
// Root trumps everything.
|
|
78
|
+
assert.equal(graphSurfaceTarget('W')?.node_id, 'R');
|
|
79
|
+
});
|
|
80
|
+
test('null when nothing in the graph is on screen (caller falls back)', () => {
|
|
81
|
+
assert.equal(graphSurfaceTarget('W'), null);
|
|
82
|
+
});
|
|
83
|
+
test('a focus row with no pane is skipped, not selected', () => {
|
|
84
|
+
openFocusRow('f-r', null, null, 'R'); // focus exists but not yet placed on a pane
|
|
85
|
+
openFocusRow('f-m', '%20', 'work', 'M');
|
|
86
|
+
assert.equal(graphSurfaceTarget('W')?.node_id, 'M');
|
|
87
|
+
});
|
|
88
|
+
test('the asking node itself, when it is the focused root, is returned', () => {
|
|
89
|
+
openFocusRow('f-r', '%10', 'work', 'R');
|
|
90
|
+
assert.equal(graphSurfaceTarget('R')?.node_id, 'R');
|
|
91
|
+
});
|
|
92
|
+
test('sanity: a closed focus drops out of the selection', () => {
|
|
93
|
+
openFocusRow('f-m', '%20', 'work', 'M');
|
|
94
|
+
assert.equal(graphSurfaceTarget('W')?.node_id, 'M');
|
|
95
|
+
closeFocusRow('f-m');
|
|
96
|
+
assert.equal(getFocusByNode('M'), null);
|
|
97
|
+
assert.equal(graphSurfaceTarget('W'), null);
|
|
98
|
+
});
|
|
@@ -67,18 +67,11 @@ test('finalize: illegal from done|dead|canceled → throws, status untouched', (
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
// ---------------------------------------------------------------------------
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const m = transition(`n_${from}`, 'reap');
|
|
76
|
-
assert.equal(m.status, 'done', `reap from ${from}`);
|
|
77
|
-
assert.equal(m.intent, null, `reap from ${from} clears intent`);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
// cancel → canceled + intent cleared, legal from ANY status
|
|
70
|
+
// cancel → canceled + intent cleared, legal from ANY status (forced teardown).
|
|
71
|
+
// A5 (human-confirmed 2026-06-06): the `reap` event was COLLAPSED into `cancel`
|
|
72
|
+
// — they were identical (status differed only; both intent=null, from=ANY, no
|
|
73
|
+
// side effects in transition()). Every external reap (close cascade AND
|
|
74
|
+
// reset/relaunch) now routes through `cancel`; `done` is reserved for finalize.
|
|
82
75
|
// ---------------------------------------------------------------------------
|
|
83
76
|
test('cancel: any status → canceled + intent cleared', () => {
|
|
84
77
|
for (const from of ALL) {
|
|
@@ -172,7 +165,7 @@ test('boot: illegal from done|dead|canceled → throws', () => {
|
|
|
172
165
|
// unknown node → throws for every event
|
|
173
166
|
// ---------------------------------------------------------------------------
|
|
174
167
|
test('transition on an unknown node throws', () => {
|
|
175
|
-
for (const ev of ['finalize', '
|
|
168
|
+
for (const ev of ['finalize', 'cancel', 'crash', 'yield', 'release', 'revive', 'boot']) {
|
|
176
169
|
assert.throws(() => transition('ghost', ev), /unknown node/);
|
|
177
170
|
}
|
|
178
171
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// Run with: node --import tsx/esm --test src/core/__tests__/live-mutation.test.ts
|
|
2
|
+
//
|
|
3
|
+
// AXIS: LIVE MUTATION of the 2×2 state vector (mode {base,orchestrator} ×
|
|
4
|
+
// lifecycle {terminal,resident}) while a node is ACTIVE/LIVE — driven through
|
|
5
|
+
// the REAL `crtr node lifecycle` / `node promote` / `node demote` CLI verbs
|
|
6
|
+
// against a live fake-pi, with the REAL stophook / kickoff / daemon hooks doing
|
|
7
|
+
// the work. Every assertion reads the canvas data layer and is checked against
|
|
8
|
+
// the state-model ORACLE (mq1su40t .../state-model.md).
|
|
9
|
+
//
|
|
10
|
+
// This file is ADDITIVE and uses ONLY the public Harness API + a couple of pure
|
|
11
|
+
// test-local helpers (noted below). It does not edit harness.ts / fake-pi-host.ts
|
|
12
|
+
// or any production file.
|
|
13
|
+
//
|
|
14
|
+
// Coverage rationale (grep of src/core/__tests__/ before writing):
|
|
15
|
+
// • persona.test.ts — UNIT-level personaDrift/transitionGuidance (pure
|
|
16
|
+
// functions; no live pi, no turn_end firing).
|
|
17
|
+
// • stop-guard.test.ts — UNIT-level evaluateStop (no live flip via CLI).
|
|
18
|
+
// • daemon-liveness.test.ts — superviseTick over BORN-terminal idle-release
|
|
19
|
+
// rows (never a live lifecycle FLIP).
|
|
20
|
+
// • flagship-lifecycle — B born terminal idle-releases; A born resident
|
|
21
|
+
// stays live; promote+turn fires the steer ONCE.
|
|
22
|
+
// GENUINELY MISSING (this file): the LIVE FLIP itself — flipping a running
|
|
23
|
+
// node's lifecycle/mode through the real verb and proving the runtime behavior
|
|
24
|
+
// (idle-release vs dormant; persona-ack recompose; the A4 boundary) changes
|
|
25
|
+
// accordingly. None of the above drives `crtr node lifecycle` on a live node,
|
|
26
|
+
// nor asserts persona_ack mutation across a live promote, nor the A4 loss site.
|
|
27
|
+
import { test } from 'node:test';
|
|
28
|
+
import assert from 'node:assert/strict';
|
|
29
|
+
import { spawnSync } from 'node:child_process';
|
|
30
|
+
import { createHarness, hasTmux } from './helpers/harness.js';
|
|
31
|
+
const SKIP = !hasTmux() ? 'tmux unavailable' : false;
|
|
32
|
+
function sessionExists(session) {
|
|
33
|
+
return spawnSync('tmux', ['has-session', '-t', session], { stdio: 'ignore' }).status === 0;
|
|
34
|
+
}
|
|
35
|
+
// --- pure test-local helpers (candidates to fold into harness.ts later) -----
|
|
36
|
+
/** The injected entries delivered as a turn-boundary `steer`. */
|
|
37
|
+
function steers(inj) {
|
|
38
|
+
return inj.filter((e) => e.deliverAs === 'steer');
|
|
39
|
+
}
|
|
40
|
+
/** A steer carrying the base→orchestrator orchestration guidance. */
|
|
41
|
+
function orchestrationSteers(inj) {
|
|
42
|
+
return steers(inj).filter((e) => /ORCHESTRATOR/i.test(e.content));
|
|
43
|
+
}
|
|
44
|
+
/** Normalize the two persona axes off a NodeMeta for deepEqual. */
|
|
45
|
+
function persona(m) {
|
|
46
|
+
return { mode: m.mode, lifecycle: m.lifecycle };
|
|
47
|
+
}
|
|
48
|
+
/** The first %pane_id of a tmux window. The spawn path records window+session
|
|
49
|
+
* but NOT pane (spawn.ts: pane is null until a reconcile/focus), so a node's
|
|
50
|
+
* live pane must be resolved from its window here. */
|
|
51
|
+
function firstPaneOf(window) {
|
|
52
|
+
const r = spawnSync('tmux', ['list-panes', '-t', window, '-F', '#{pane_id}'], { encoding: 'utf8' });
|
|
53
|
+
if (r.status !== 0)
|
|
54
|
+
return null;
|
|
55
|
+
return r.stdout.split('\n').map((s) => s.trim()).filter(Boolean)[0] ?? null;
|
|
56
|
+
}
|
|
57
|
+
// ===========================================================================
|
|
58
|
+
// (a) LIFECYCLE FLIP — `crtr node lifecycle` on a LIVE node, both directions,
|
|
59
|
+
// observing the idle-release behavior change. A round-trip on ONE live
|
|
60
|
+
// node (terminal→resident→terminal) proves both directions faithfully:
|
|
61
|
+
// a flipped-resident node no longer idle-releases (stays live, daemon does
|
|
62
|
+
// NOT release it); flipped-terminal it idle-releases again on pi-death.
|
|
63
|
+
// ===========================================================================
|
|
64
|
+
test('live lifecycle flip: terminal→resident suppresses idle-release; resident→terminal restores it', { skip: SKIP, timeout: 120_000 }, async () => {
|
|
65
|
+
const h = await createHarness({ sessionPrefix: 'crtr-live-life' });
|
|
66
|
+
try {
|
|
67
|
+
// A (resident root, data-layer) ─ B (base/terminal, live) ─ C (base/terminal, live).
|
|
68
|
+
// B holds an ACTIVE live subscription to C → a TERMINAL B that stops is
|
|
69
|
+
// legitimately 'awaiting' (stop-guard) and would idle-release. That live
|
|
70
|
+
// sub is the precondition that makes the resident-vs-terminal flip the
|
|
71
|
+
// ONLY variable.
|
|
72
|
+
const A = h.spawnRoot('resident root');
|
|
73
|
+
const B = await h.spawnChild(A, 'do the work', { kind: 'developer' });
|
|
74
|
+
const C = await h.spawnChild(B, 'a subtask');
|
|
75
|
+
{
|
|
76
|
+
const b = h.node(B);
|
|
77
|
+
assert.deepEqual(persona(b), { mode: 'base', lifecycle: 'terminal' }, 'B born base×terminal');
|
|
78
|
+
assert.equal(b.status, 'active', 'B active');
|
|
79
|
+
assert.equal(b.intent ?? null, null, 'B no intent');
|
|
80
|
+
assert.equal(h.status(C), 'active', 'C active — B holds a live sub to it');
|
|
81
|
+
assert.ok(h.subscriptions(B).some((s) => s.node_id === C && s.active), 'B subscribes_to C (active) — the awaiting precondition');
|
|
82
|
+
}
|
|
83
|
+
// --- FLIP 1: terminal → RESIDENT (live). Oracle §4: sets lifecycle + the
|
|
84
|
+
// launch spec, status/intent UNTOUCHED. ---
|
|
85
|
+
{
|
|
86
|
+
const res = h.cli(B, ['node', 'lifecycle', 'resident', '--node', B]);
|
|
87
|
+
assert.equal(res.code, 0, `lifecycle resident exit 0\n${res.stderr}`);
|
|
88
|
+
const b = h.node(B);
|
|
89
|
+
assert.equal(b.lifecycle, 'resident', 'B → resident');
|
|
90
|
+
assert.equal(b.mode, 'base', 'mode UNCHANGED by a lifecycle flip (orthogonal axis)');
|
|
91
|
+
assert.equal(b.status, 'active', 'status UNTOUCHED by node lifecycle (oracle §4)');
|
|
92
|
+
assert.equal(b.intent ?? null, null, 'intent UNTOUCHED by node lifecycle (oracle §4)');
|
|
93
|
+
}
|
|
94
|
+
// B stops AS RESIDENT: agent_end runs the stop-guard, which keys on
|
|
95
|
+
// lifecycle==='resident' → 'dormant' → the handler does NOT shut pi down
|
|
96
|
+
// (oracle §3a). So B stays active, pi alive, pane held — it does NOT
|
|
97
|
+
// idle-release despite holding the same live sub that would release a
|
|
98
|
+
// terminal node.
|
|
99
|
+
await h.stop(B);
|
|
100
|
+
// MINOR-2: asserting a NON-event (B must NOT idle-release) cannot be a single
|
|
101
|
+
// immediate read — h.stop() resolves once agent_end is RECORDED, BEFORE the
|
|
102
|
+
// handler completes, so a regression where the resident 'dormant' branch
|
|
103
|
+
// wrongly ran transition('release') + ctx.shutdown() asynchronously would
|
|
104
|
+
// still observe the pre-release state and false-pass. Instead POLL-STABLE:
|
|
105
|
+
// sample repeatedly across a real settle (a daemon tick partway, so the
|
|
106
|
+
// handler + a full superviseTick have both run) and assert the invariant
|
|
107
|
+
// holds on EVERY sample. A regression that idle-releases within the window
|
|
108
|
+
// is caught the moment it flips.
|
|
109
|
+
{
|
|
110
|
+
const deadline = Date.now() + 2_000;
|
|
111
|
+
let ticked = false;
|
|
112
|
+
for (;;) {
|
|
113
|
+
const b = h.node(B);
|
|
114
|
+
assert.equal(b.status, 'active', 'resident B stays ACTIVE on stop (dormant, not released)');
|
|
115
|
+
assert.equal(b.intent ?? null, null, 'resident B has NO idle-release intent');
|
|
116
|
+
assert.equal(h.paneAlive(B), true, 'resident B keeps its live pi/pane (no shutdown)');
|
|
117
|
+
assert.equal(h.status(C), 'active', 'C untouched while B is dormant-resident');
|
|
118
|
+
// Drive a real daemon decision pass midway: a superviseTick sees B
|
|
119
|
+
// active + pane-alive + pid-alive → handleLiveWindow 'leave'. If the
|
|
120
|
+
// daemon wrongly released a resident node, the next sample catches it.
|
|
121
|
+
if (!ticked) {
|
|
122
|
+
await h.tick();
|
|
123
|
+
ticked = true;
|
|
124
|
+
}
|
|
125
|
+
if (Date.now() >= deadline)
|
|
126
|
+
break;
|
|
127
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// --- FLIP 2: resident → TERMINAL (live), on the now-resident live node. ---
|
|
131
|
+
{
|
|
132
|
+
const res = h.cli(B, ['node', 'lifecycle', 'terminal', '--node', B]);
|
|
133
|
+
assert.equal(res.code, 0, `lifecycle terminal exit 0\n${res.stderr}`);
|
|
134
|
+
const b = h.node(B);
|
|
135
|
+
assert.equal(b.lifecycle, 'terminal', 'B → terminal');
|
|
136
|
+
assert.equal(b.status, 'active', 'status still UNTOUCHED by the flip');
|
|
137
|
+
assert.equal(b.intent ?? null, null, 'intent still UNTOUCHED by the flip');
|
|
138
|
+
}
|
|
139
|
+
// B stops AS TERMINAL now: stop-guard sees terminal + an active live sub to
|
|
140
|
+
// C → 'awaiting' → transition('release') + ctx.shutdown(). idle/idle-release;
|
|
141
|
+
// pi dies; UNFOCUSED backstage pane closes (oracle §3b). The exact behavior
|
|
142
|
+
// the resident flip had suppressed.
|
|
143
|
+
await h.stop(B);
|
|
144
|
+
await h.waitForStatus(B, 'idle');
|
|
145
|
+
{
|
|
146
|
+
const b = h.node(B);
|
|
147
|
+
assert.equal(b.status, 'idle', 'terminal B idle-releases on stop');
|
|
148
|
+
assert.equal(b.intent, 'idle-release', 'intent=idle-release (transition release)');
|
|
149
|
+
}
|
|
150
|
+
await h.waitForPaneGone(B);
|
|
151
|
+
assert.equal(h.paneAlive(B), false, 'unfocused terminal B → pane closed on idle-release');
|
|
152
|
+
assert.equal(h.status(C), 'active', 'C still active while B sleeps');
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
const session = h.session;
|
|
156
|
+
await h.dispose();
|
|
157
|
+
assert.equal(sessionExists(session), false, 'isolated session killed — no stray');
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
// ===========================================================================
|
|
161
|
+
// (b) MODE FLIP — promote: base → orchestrator on a LIVE node. The flip itself
|
|
162
|
+
// does NOT commit the persona ack; the turn_end injector recomposes (commits
|
|
163
|
+
// the ack + delivers the steer) on the next turn, and a second turn is a
|
|
164
|
+
// no-op (drift cleared). Flagship asserts the steer fires once; the NEW
|
|
165
|
+
// assertions here are the persona_ack MUTATION across the live flip and the
|
|
166
|
+
// idempotence — neither is covered elsewhere.
|
|
167
|
+
// ===========================================================================
|
|
168
|
+
test('live mode flip: promote base→orchestrator recomposes persona_ack at turn_end (and is idempotent)', { skip: SKIP, timeout: 120_000 }, async () => {
|
|
169
|
+
const h = await createHarness({ sessionPrefix: 'crtr-live-mode' });
|
|
170
|
+
try {
|
|
171
|
+
const A = h.spawnRoot('resident root');
|
|
172
|
+
const B = await h.spawnChild(A, 'do the work', { kind: 'developer' });
|
|
173
|
+
{
|
|
174
|
+
const b = h.node(B);
|
|
175
|
+
assert.deepEqual(persona(b), { mode: 'base', lifecycle: 'terminal' }, 'B born base×terminal');
|
|
176
|
+
// Invariant 11: born acked to its own persona → no spurious drift turn 1.
|
|
177
|
+
assert.deepEqual(b.persona_ack, { mode: 'base', lifecycle: 'terminal' }, 'persona_ack born equal to the initial persona (invariant 11)');
|
|
178
|
+
}
|
|
179
|
+
// PROMOTE (live): mode→orchestrator, lifecycle UNCHANGED, status/intent
|
|
180
|
+
// untouched (no transition). Crucially promote does NOT commit the ack —
|
|
181
|
+
// the drift is left PENDING for the injector.
|
|
182
|
+
{
|
|
183
|
+
const res = h.cli(B, ['node', 'promote', '--kind', 'developer']);
|
|
184
|
+
assert.equal(res.code, 0, `promote exit 0\n${res.stderr}`);
|
|
185
|
+
const b = h.node(B);
|
|
186
|
+
assert.equal(b.mode, 'orchestrator', 'B → orchestrator');
|
|
187
|
+
assert.equal(b.lifecycle, 'terminal', 'lifecycle UNCHANGED (promote is mode-only)');
|
|
188
|
+
assert.equal(b.status, 'active', 'status untouched by promote');
|
|
189
|
+
assert.equal(b.intent ?? null, null, 'intent untouched by promote');
|
|
190
|
+
assert.deepEqual(b.persona_ack, { mode: 'base', lifecycle: 'terminal' }, 'promote does NOT commit the ack — drift left PENDING for the injector');
|
|
191
|
+
}
|
|
192
|
+
// A TURN fires turn_end: personaDrift base→orchestrator → inject the
|
|
193
|
+
// orchestration guidance as a STEER, then commitPersonaAck. agent_end then
|
|
194
|
+
// stalls (orchestrator, no live sub, no final) → reprompt → B stays alive.
|
|
195
|
+
const injBefore = h.injected(B).length;
|
|
196
|
+
await h.turn(B, 'orchestrating');
|
|
197
|
+
const fresh = await h.waitFor(() => {
|
|
198
|
+
const slice = h.injected(B).slice(injBefore);
|
|
199
|
+
return orchestrationSteers(slice).length > 0 ? slice : null;
|
|
200
|
+
}, { timeoutMs: 15_000, label: 'base→orchestrator steer at turn_end' });
|
|
201
|
+
assert.ok(orchestrationSteers(fresh).length >= 1, 'turn_end delivered the orchestration guidance as a steer');
|
|
202
|
+
{
|
|
203
|
+
const b = h.node(B);
|
|
204
|
+
assert.deepEqual(b.persona_ack, { mode: 'orchestrator', lifecycle: 'terminal' }, 'persona RECOMPOSE committed: persona_ack advanced to the new persona at turn_end');
|
|
205
|
+
assert.equal(b.status, 'active', 'B not stranded — reprompt keeps it alive');
|
|
206
|
+
}
|
|
207
|
+
// IDEMPOTENCE: a SECOND turn finds no drift (ack already committed) → NO
|
|
208
|
+
// new persona steer is injected.
|
|
209
|
+
const injBeforeSecond = h.injected(B).length;
|
|
210
|
+
await h.turn(B, 'orchestrating again');
|
|
211
|
+
const afterSecond = h.injected(B).slice(injBeforeSecond);
|
|
212
|
+
assert.equal(orchestrationSteers(afterSecond).length, 0, 'no fresh orchestration steer on the second turn — drift cleared (idempotent recompose)');
|
|
213
|
+
assert.equal(h.node(B).mode, 'orchestrator', 'B still orchestrator');
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
const session = h.session;
|
|
217
|
+
await h.dispose();
|
|
218
|
+
assert.equal(sessionExists(session), false, 'isolated session killed — no stray');
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
// ===========================================================================
|
|
222
|
+
// (b) MODE FLIP — demote. ⚑ FLAG vs the task framing ("demote orchestrator back
|
|
223
|
+
// to base; assert the mode field changes"): the `node demote` verb does NOT
|
|
224
|
+
// flip the SAME live node's mode orchestrator→base. Per ORACLE §4 (which
|
|
225
|
+
// matches the code: demote.ts) it FINISHES the node (push final → done) and
|
|
226
|
+
// RECYCLES the pane into a FRESH general/base/resident root — a DIFFERENT
|
|
227
|
+
// node. The demoted node keeps mode=orchestrator (it is merely `done`).
|
|
228
|
+
// There is NO live verb that flips a node orchestrator→base, so the
|
|
229
|
+
// persona.ts `baseModeGuidance` (orchestrator→base) is effectively
|
|
230
|
+
// UNREACHABLE via live mutation. This test pins the real behavior so the
|
|
231
|
+
// contradiction is visible; production is NOT changed.
|
|
232
|
+
// ===========================================================================
|
|
233
|
+
test('node demote is FINISH+RECYCLE, not an orchestrator→base mode flip (current behavior vs task framing)', { skip: SKIP, timeout: 120_000 }, async () => {
|
|
234
|
+
const h = await createHarness({ sessionPrefix: 'crtr-live-demote' });
|
|
235
|
+
try {
|
|
236
|
+
const A = h.spawnRoot('resident root');
|
|
237
|
+
const B = await h.spawnChild(A, 'do the work', { kind: 'developer' });
|
|
238
|
+
// Promote B so it is genuinely an orchestrator before we demote it.
|
|
239
|
+
assert.equal(h.cli(B, ['node', 'promote', '--kind', 'developer']).code, 0, 'promote B');
|
|
240
|
+
const b0 = h.node(B);
|
|
241
|
+
assert.equal(b0.mode, 'orchestrator', 'B is orchestrator before demote');
|
|
242
|
+
// Resolve B's live %pane_id from its window (the row's `pane` is null until
|
|
243
|
+
// a reconcile; the spawn path records only window+session).
|
|
244
|
+
const pane = firstPaneOf(b0.window);
|
|
245
|
+
assert.ok(typeof pane === 'string' && pane !== '', 'B has a live pane to recycle');
|
|
246
|
+
// DEMOTE via the real verb (TMUX_PANE is scrubbed from child env → pass --pane).
|
|
247
|
+
const res = h.cli(B, ['node', 'demote', '--node', B, '--pane', pane]);
|
|
248
|
+
assert.equal(res.code, 0, `demote exit 0\n${res.stderr}`);
|
|
249
|
+
// The leaf renders `<demoted ... finalized=".." new_root=".."/>` (not JSON).
|
|
250
|
+
assert.match(res.stdout, /<demoted /, `demote recycled the pane\n${res.stdout}`);
|
|
251
|
+
const newRoot = /new_root="([^"]+)"/.exec(res.stdout)?.[1];
|
|
252
|
+
const finalized = /finalized="true"/.test(res.stdout);
|
|
253
|
+
// ⚑ The demoted node is FINISHED, not mode-flipped.
|
|
254
|
+
{
|
|
255
|
+
const b = h.node(B);
|
|
256
|
+
assert.equal(b.status, 'done', 'demoted node → done (finished), NOT re-roled');
|
|
257
|
+
assert.equal(b.intent, 'done', 'intent=done (finalize), per the push-final path');
|
|
258
|
+
assert.equal(b.mode, 'orchestrator', '⚑ demoted node KEEPS mode=orchestrator — demote is NOT an orchestrator→base flip');
|
|
259
|
+
assert.ok(finalized, 'demote pushed a final for the node');
|
|
260
|
+
}
|
|
261
|
+
// The fresh root is a DIFFERENT, BASE×RESIDENT node — that is where "base"
|
|
262
|
+
// comes from, not a mutation of B.
|
|
263
|
+
assert.ok(typeof newRoot === 'string' && newRoot !== B, 'a fresh root (≠ B) was minted');
|
|
264
|
+
{
|
|
265
|
+
const fresh = h.node(newRoot);
|
|
266
|
+
assert.deepEqual(persona(fresh), { mode: 'base', lifecycle: 'resident' }, 'recycled root is born base×resident (general)');
|
|
267
|
+
// Born acked to its own persona → it will never see an orchestrator→base
|
|
268
|
+
// drift steer: that persona path is unreachable through live mutation.
|
|
269
|
+
assert.deepEqual(fresh.persona_ack, { mode: 'base', lifecycle: 'resident' }, 'fresh root born acked base×resident — no orchestrator→base drift will ever fire');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
const session = h.session;
|
|
274
|
+
await h.dispose();
|
|
275
|
+
assert.equal(sessionExists(session), false, 'isolated session killed — no stray');
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
// ===========================================================================
|
|
279
|
+
// (b) A4 BOUNDARY — promote-then-yield emits a steer that is discarded. The
|
|
280
|
+
// oracle/flagship boundary: the base→orchestrator guidance lands as a STEER
|
|
281
|
+
// only if a turn_end fires while the drift is pending. A `node yield` on a
|
|
282
|
+
// base node auto-promotes (mode→orchestrator, ack NOT committed) and its
|
|
283
|
+
// agent_end goes STRAIGHT to reviveInPlace (b') with NO preceding turn_end —
|
|
284
|
+
// so the only steer-delivery site (turn_end) is BYPASSED. Two deterministic
|
|
285
|
+
// facts pin the boundary, both confirmed by direct observation:
|
|
286
|
+
// (1) NO orchestration STEER is ever delivered (the LOSS).
|
|
287
|
+
// (2) The ack is silently advanced base→orchestrator at the refresh DRAIN
|
|
288
|
+
// (reviveInPlace→drainBearings→commitPersonaAck), NOT via a steer — so
|
|
289
|
+
// neither this turn nor (per A4) the fresh revive re-offers it as a
|
|
290
|
+
// steer; the guidance survives only in the kickoff PROMPT it built.
|
|
291
|
+
// ⚑ FLAGGED (not fixed): the in-place refresh of this LARGE pending-drift
|
|
292
|
+
// kickoff prompt did NOT complete a fresh fake-pi boot in the harness (it
|
|
293
|
+
// stayed at 1 boot, intent=refresh, ack=orchestrator, pane alive) — a
|
|
294
|
+
// base→orchestrator yield's giant <persona-transition> kickoff pushed
|
|
295
|
+
// through respawn-pane did not bring up the fresh vehicle. Whether a real
|
|
296
|
+
// edge (oversized argv through respawn-pane) or a harness artifact, it is
|
|
297
|
+
// out of scope to fix; this test asserts only the deterministic boundary.
|
|
298
|
+
// ===========================================================================
|
|
299
|
+
test('A4: a base→orchestrator yield with no preceding turn_end loses the orchestration STEER (ack advances silently at the refresh drain)', { skip: SKIP, timeout: 120_000 }, async () => {
|
|
300
|
+
const h = await createHarness({ sessionPrefix: 'crtr-live-a4' });
|
|
301
|
+
try {
|
|
302
|
+
const A = h.spawnRoot('resident root');
|
|
303
|
+
const B = await h.spawnChild(A, 'do the work', { kind: 'developer' });
|
|
304
|
+
assert.deepEqual(persona(h.node(B)), { mode: 'base', lifecycle: 'terminal' }, 'B born base×terminal');
|
|
305
|
+
const injBefore = h.injected(B).length;
|
|
306
|
+
// `crtr node yield` (base → auto-promote → intent=refresh). INTERMEDIATE
|
|
307
|
+
// state, BEFORE any agent_end: mode flipped, ack NOT yet committed (the
|
|
308
|
+
// turn_end injector has not run), intent=refresh, drift PENDING.
|
|
309
|
+
const y = h.cli(B, ['node', 'yield', 'refresh against the roadmap']);
|
|
310
|
+
assert.equal(y.code, 0, `node yield exit 0\n${y.stderr}`);
|
|
311
|
+
{
|
|
312
|
+
const b = h.node(B);
|
|
313
|
+
assert.equal(b.mode, 'orchestrator', 'yield auto-promoted base→orchestrator');
|
|
314
|
+
assert.equal(b.intent, 'refresh', 'intent=refresh set by the yield');
|
|
315
|
+
assert.deepEqual(b.persona_ack, { mode: 'base', lifecycle: 'terminal' }, 'ack STILL base — promote/yield never commits it; only an injector does');
|
|
316
|
+
}
|
|
317
|
+
// Fire the stop: agent_end sees intent=refresh → (b') reviveInPlace, whose
|
|
318
|
+
// drainBearings commits the ack synchronously BEFORE the respawn. NO
|
|
319
|
+
// turn_end fires this turn, so the turn_end steer site is bypassed.
|
|
320
|
+
await h.stop(B);
|
|
321
|
+
// (2) The ack is silently advanced to orchestrator at the refresh DRAIN —
|
|
322
|
+
// not by any steer. (waitFor: the agent_end handler runs after h.stop
|
|
323
|
+
// observes the recorded event.)
|
|
324
|
+
await h.waitFor(() => {
|
|
325
|
+
const a = h.node(B)?.persona_ack;
|
|
326
|
+
return a?.mode === 'orchestrator' && a?.lifecycle === 'terminal';
|
|
327
|
+
}, { timeoutMs: 20_000, label: 'persona_ack advanced at the refresh drain (not via a steer)' });
|
|
328
|
+
assert.deepEqual(h.node(B).persona_ack, { mode: 'orchestrator', lifecycle: 'terminal' }, 'ack committed base→orchestrator by drainBearings during reviveInPlace');
|
|
329
|
+
// (1) ⚑ LOSS site: across the whole yield→refresh, NO orchestration
|
|
330
|
+
// guidance was ever delivered as a turn-boundary STEER (the only steer
|
|
331
|
+
// site, turn_end, never ran). The ack moved without the agent ever being
|
|
332
|
+
// steered with the new-role guidance — it survives only in the kickoff
|
|
333
|
+
// prompt drainBearings built for the (here, non-booting) fresh vehicle.
|
|
334
|
+
assert.equal(orchestrationSteers(h.injected(B).slice(injBefore)).length, 0, '⚑ A4: no orchestration STEER delivered — the turn_end injector was bypassed by the yield');
|
|
335
|
+
}
|
|
336
|
+
finally {
|
|
337
|
+
const session = h.session;
|
|
338
|
+
await h.dispose();
|
|
339
|
+
assert.equal(sessionExists(session), false, 'isolated session killed — no stray');
|
|
340
|
+
}
|
|
341
|
+
});
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// Run: node --import tsx/esm --test src/core/__tests__/persona-subkind.test.ts
|
|
2
2
|
//
|
|
3
|
-
// Scoped persona sub-
|
|
4
|
-
// `<kind>/reviewers/<name>/
|
|
3
|
+
// Scoped persona sub-personas: a kind has specialist reviewer personas at
|
|
4
|
+
// `<kind>/reviewers/<name>/PERSONA.md`, enumerated by `subPersonasFor(kind)` and
|
|
5
5
|
// rendered into that kind's composed prompt (and nowhere else) by `resolve`.
|
|
6
|
-
// Visibility = membership
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Visibility = membership (the sub-persona's `availableTo`, default = its
|
|
7
|
+
// top-level ancestor kind): only `plan` sees the `plan/reviewers/*` menu; the
|
|
8
|
+
// `reviewers/` grouping dir is transparent so the kind string keeps it; the
|
|
9
|
+
// sub-personas never pollute the global `availableKinds()` list; and a
|
|
10
|
+
// sub-persona itself boots as a real composed persona with the terminal finish
|
|
11
|
+
// contract.
|
|
9
12
|
import { test } from 'node:test';
|
|
10
13
|
import assert from 'node:assert/strict';
|
|
11
14
|
import { resolve } from '../personas/resolve.js';
|
|
12
|
-
import {
|
|
15
|
+
import { subPersonasFor, availableKinds } from '../personas/loader.js';
|
|
13
16
|
const PLAN_REVIEWER_KINDS = [
|
|
14
17
|
'plan/reviewers/architecture-fit',
|
|
15
18
|
'plan/reviewers/code-smells',
|
|
@@ -17,19 +20,19 @@ const PLAN_REVIEWER_KINDS = [
|
|
|
17
20
|
'plan/reviewers/requirements-coverage',
|
|
18
21
|
'plan/reviewers/security',
|
|
19
22
|
];
|
|
20
|
-
const MENU_HEADER = '
|
|
21
|
-
test('
|
|
22
|
-
const subs =
|
|
23
|
-
assert.deepEqual(subs.map((s) => s.kind), PLAN_REVIEWER_KINDS, 'the five plan reviewer kind strings in sorted order');
|
|
23
|
+
const MENU_HEADER = 'Sub-personas you may spawn';
|
|
24
|
+
test('subPersonasFor("plan") returns the five reviewers sorted, each with a non-empty whenToUse', () => {
|
|
25
|
+
const subs = subPersonasFor('plan');
|
|
26
|
+
assert.deepEqual(subs.map((s) => s.kind), PLAN_REVIEWER_KINDS, 'the five plan reviewer kind strings in sorted order — the transparent reviewers/ dir keeps the full kind path');
|
|
24
27
|
for (const s of subs) {
|
|
25
|
-
assert.ok(s.
|
|
28
|
+
assert.ok(s.whenToUse.length > 0, `${s.kind} carries a non-empty whenToUse`);
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
|
-
test('
|
|
29
|
-
assert.deepEqual(
|
|
30
|
-
assert.deepEqual(
|
|
31
|
+
test('availability is membership: a kind with no available sub-personas yields []', () => {
|
|
32
|
+
assert.deepEqual(subPersonasFor('explore'), [], 'no sub-persona is availableTo explore');
|
|
33
|
+
assert.deepEqual(subPersonasFor('plan/reviewers/security'), [], 'the five reviewers default availableTo:[plan] — none are available to a reviewer kind');
|
|
31
34
|
});
|
|
32
|
-
test('availableKinds() contains no plan/reviewers/* — sub-
|
|
35
|
+
test('availableKinds() contains no plan/reviewers/* — sub-personas never pollute the global list', () => {
|
|
33
36
|
const kinds = availableKinds();
|
|
34
37
|
for (const k of PLAN_REVIEWER_KINDS) {
|
|
35
38
|
assert.ok(!kinds.includes(k), `${k} must not appear in availableKinds()`);
|