agent-tempo 1.5.1 → 1.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/dashboard/package.json +1 -1
- package/dist/activities/outbox.d.ts +14 -1
- package/dist/activities/outbox.js +41 -0
- package/dist/cli/commands.js +25 -8
- package/dist/cli/config-command.d.ts +16 -0
- package/dist/cli/config-command.js +51 -5
- package/dist/cli/resolve-ensemble.d.ts +17 -0
- package/dist/cli/resolve-ensemble.js +20 -0
- package/dist/cli/sa-preflight.d.ts +8 -0
- package/dist/cli/sa-preflight.js +31 -0
- package/dist/cli.js +5 -1
- package/dist/config.d.ts +12 -3
- package/dist/config.js +15 -12
- package/dist/pi/cue-pump.d.ts +86 -13
- package/dist/pi/cue-pump.js +110 -15
- package/dist/pi/extension.d.ts +29 -15
- package/dist/pi/extension.js +96 -19
- package/dist/pi/index.d.ts +2 -2
- package/dist/pi/index.js +2 -1
- package/dist/pi/pi-types.d.ts +50 -0
- package/dist/pi/reset-pump.d.ts +55 -17
- package/dist/pi/reset-pump.js +70 -20
- package/dist/server-tools.d.ts +7 -1
- package/dist/server-tools.js +2 -2
- package/dist/server.js +5 -2
- package/dist/tools/recruit.d.ts +19 -2
- package/dist/tools/recruit.js +26 -2
- package/package.json +1 -1
package/dist/pi/cue-pump.js
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CuePump = void 0;
|
|
4
|
+
exports.buildPiInjector = buildPiInjector;
|
|
5
|
+
/**
|
|
6
|
+
* Build the per-tick {@link MessageInjector} from the live runtime, PREFERRING the
|
|
7
|
+
* stable `pi.sendMessage` handle (interactive root-cause fix, #677) and falling
|
|
8
|
+
* back to `session.sendCustomMessage` only when `pi.sendMessage` is unavailable.
|
|
9
|
+
* Pure + feature-detected (`typeof`) so it's safe whatever Pi build is loaded and
|
|
10
|
+
* unit-testable without a real Pi.
|
|
11
|
+
*/
|
|
12
|
+
function buildPiInjector(rt) {
|
|
13
|
+
if (!rt)
|
|
14
|
+
return null;
|
|
15
|
+
const pi = rt.pi;
|
|
16
|
+
const send = typeof pi?.sendMessage === 'function' ? pi.sendMessage.bind(pi) : null;
|
|
17
|
+
if (send) {
|
|
18
|
+
const sendUser = typeof pi?.sendUserMessage === 'function' ? pi.sendUserMessage.bind(pi) : null;
|
|
19
|
+
return {
|
|
20
|
+
inject: (msg, opts) => send(msg, opts),
|
|
21
|
+
// #688 — escalate with `deliverAs: 'followUp'`. maybeEscalate can fire while a
|
|
22
|
+
// turn is ALREADY in flight (one that started BEFORE the inject — a busy
|
|
23
|
+
// false-positive), and a bare sendUserMessage (no deliverAs) while Pi is
|
|
24
|
+
// streaming throws "Agent is already processing". followUp is correct in BOTH
|
|
25
|
+
// cases: cold-idle (behavior ignored → the user message still starts a turn,
|
|
26
|
+
// escalation works) and busy (queues + drains in order, no throw). NOT 'steer'
|
|
27
|
+
// — steer would let a peer cue preempt the operator's in-flight turn, breaking
|
|
28
|
+
// the operator-vs-peer guarantee (see file header).
|
|
29
|
+
...(sendUser ? { escalate: (text) => sendUser(text, { deliverAs: 'followUp' }) } : {}),
|
|
30
|
+
lastTurnStartAt: () => rt.lastTurnStartAt,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const session = rt.session;
|
|
34
|
+
if (session) {
|
|
35
|
+
return {
|
|
36
|
+
inject: (msg, opts) => session.sendCustomMessage(msg, opts),
|
|
37
|
+
lastTurnStartAt: () => rt.lastTurnStartAt,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
4
42
|
const DEFAULT_POLL_MS = 1_000;
|
|
5
43
|
const log = (...args) => {
|
|
6
44
|
// eslint-disable-next-line no-console
|
|
@@ -8,14 +46,22 @@ const log = (...args) => {
|
|
|
8
46
|
};
|
|
9
47
|
class CuePump {
|
|
10
48
|
source;
|
|
11
|
-
|
|
49
|
+
resolveInjector;
|
|
12
50
|
intervalMs;
|
|
51
|
+
now;
|
|
13
52
|
timer = null;
|
|
14
53
|
draining = false;
|
|
54
|
+
/**
|
|
55
|
+
* The last cue injected via the escalation-eligible `pi.sendMessage` route,
|
|
56
|
+
* pending a turn-start check on the next tick. Cleared once a turn starts or
|
|
57
|
+
* once escalated (escalate-once invariant).
|
|
58
|
+
*/
|
|
59
|
+
lastInject = null;
|
|
15
60
|
constructor(opts) {
|
|
16
61
|
this.source = opts.source;
|
|
17
|
-
this.
|
|
62
|
+
this.resolveInjector = opts.resolveInjector;
|
|
18
63
|
this.intervalMs = opts.intervalMs ?? DEFAULT_POLL_MS;
|
|
64
|
+
this.now = opts.now ?? Date.now;
|
|
19
65
|
}
|
|
20
66
|
start() {
|
|
21
67
|
if (this.timer)
|
|
@@ -33,28 +79,40 @@ class CuePump {
|
|
|
33
79
|
}
|
|
34
80
|
}
|
|
35
81
|
/**
|
|
36
|
-
* One poll cycle:
|
|
37
|
-
*
|
|
38
|
-
* overlaps the
|
|
82
|
+
* One poll cycle: (1) escalate a previously-injected cue that never woke a turn,
|
|
83
|
+
* then (2) fetch pending cues, inject each into the live agent, ack the ones
|
|
84
|
+
* successfully injected. Re-entrancy guarded so a slow tick never overlaps the
|
|
85
|
+
* next interval.
|
|
39
86
|
*/
|
|
40
87
|
async tick() {
|
|
41
88
|
if (this.draining)
|
|
42
89
|
return;
|
|
43
90
|
this.draining = true;
|
|
44
91
|
try {
|
|
92
|
+
const injector = this.resolveInjector();
|
|
93
|
+
// (1) Escalation check — runs even with no new pending. If the previous
|
|
94
|
+
// tick injected a cue via pi.sendMessage and NO turn has started since, the
|
|
95
|
+
// cue may be sitting in a cold-idle agent's queue unprocessed → re-inject as
|
|
96
|
+
// a user message (which always wakes a turn). Once per cue.
|
|
97
|
+
await this.maybeEscalate(injector);
|
|
45
98
|
const pending = await this.source.fetchPending();
|
|
46
99
|
if (pending.length === 0)
|
|
47
100
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
101
|
+
if (!injector) {
|
|
102
|
+
// No live injection target yet (no `pi` handle / session) — leave cues
|
|
103
|
+
// queued; next tick retries once an instance attaches/rebinds. Logged so a
|
|
104
|
+
// live bring-up can see cues are HELD (not lost) while waiting to attach.
|
|
105
|
+
log(`no live injector — holding ${pending.length} cue(s) for next tick`);
|
|
51
106
|
return;
|
|
52
107
|
}
|
|
53
108
|
const delivered = [];
|
|
109
|
+
let lastDeliveredText = null;
|
|
54
110
|
for (const msg of pending) {
|
|
111
|
+
const content = msg.from ? `[cue from ${msg.from}] ${msg.text}` : msg.text;
|
|
55
112
|
try {
|
|
56
|
-
await this.injectCue(
|
|
113
|
+
await this.injectCue(injector, msg, content);
|
|
57
114
|
delivered.push(msg.id);
|
|
115
|
+
lastDeliveredText = content;
|
|
58
116
|
}
|
|
59
117
|
catch (err) {
|
|
60
118
|
log(`failed to inject cue ${msg.id}:`, err);
|
|
@@ -63,18 +121,54 @@ class CuePump {
|
|
|
63
121
|
}
|
|
64
122
|
}
|
|
65
123
|
await this.source.ackDelivered(delivered);
|
|
124
|
+
// Track ONLY the LAST cue injected via the escalation-eligible route so the
|
|
125
|
+
// NEXT tick can re-inject it as a user message if no turn started. Tracking
|
|
126
|
+
// just the last is intentional and does NOT drop earlier cues' delivery:
|
|
127
|
+
// every cue in this batch was already injected via pi.sendMessage (queued in
|
|
128
|
+
// Pi), so they ALL drain once any turn starts — escalation only needs to WAKE
|
|
129
|
+
// a turn, and re-injecting one cue as a user message does exactly that. The
|
|
130
|
+
// session-fallback route omits `escalate` → no tracking.
|
|
131
|
+
if (injector.escalate && lastDeliveredText !== null) {
|
|
132
|
+
this.lastInject = { text: lastDeliveredText, injectedAt: this.now(), escalated: false };
|
|
133
|
+
}
|
|
66
134
|
}
|
|
67
135
|
finally {
|
|
68
136
|
this.draining = false;
|
|
69
137
|
}
|
|
70
138
|
}
|
|
71
139
|
/**
|
|
72
|
-
*
|
|
140
|
+
* If a previously sendMessage-injected cue has not been followed by a turn, the
|
|
141
|
+
* `triggerTurn` wake didn't take — re-inject the SAME cue as a user-role message
|
|
142
|
+
* (always starts a turn). Escalates at most once per cue; clears the tracker
|
|
143
|
+
* once a turn is observed.
|
|
144
|
+
*/
|
|
145
|
+
async maybeEscalate(injector) {
|
|
146
|
+
const pending = this.lastInject;
|
|
147
|
+
if (!pending || pending.escalated)
|
|
148
|
+
return;
|
|
149
|
+
if (!injector?.escalate)
|
|
150
|
+
return;
|
|
151
|
+
const turnAt = injector.lastTurnStartAt();
|
|
152
|
+
if (turnAt !== null && turnAt >= pending.injectedAt) {
|
|
153
|
+
// A turn started after the inject → the cue was picked up; stop tracking.
|
|
154
|
+
this.lastInject = null;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
await injector.escalate(pending.text);
|
|
159
|
+
pending.escalated = true;
|
|
160
|
+
log('escalated un-woken cue via sendUserMessage');
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
log('cue escalation failed:', err);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Inject one cue into the live agent (D10 — see file header). Operator cues
|
|
73
168
|
* `steer` (same-turn priority); peer cues `followUp` (queue). `triggerTurn` is
|
|
74
169
|
* always set: a no-op mid-turn, the required cold-idle wake otherwise.
|
|
75
170
|
*/
|
|
76
|
-
async injectCue(
|
|
77
|
-
const content = msg.from ? `[cue from ${msg.from}] ${msg.text}` : msg.text;
|
|
171
|
+
async injectCue(injector, msg, content) {
|
|
78
172
|
// LOAD-BEARING Pi-runtime invariant (D10) — confirmed sound through Pi 0.78.x
|
|
79
173
|
// (researcher-cited; a D6 "behaviors-to-revalidate-on-bump" item):
|
|
80
174
|
// peer cue = { deliverAs: 'followUp', triggerTurn: true } → QUEUES; drains
|
|
@@ -87,9 +181,10 @@ class CuePump {
|
|
|
87
181
|
// The guarantee this comment protects: a future Pi version MUST keep followUp
|
|
88
182
|
// non-interrupting AND triggerTurn a no-op-while-busy. If that regresses, peer
|
|
89
183
|
// cues silently become preemptions, defeating operator-vs-peer. Not unit-testable
|
|
90
|
-
// here (the
|
|
91
|
-
// version floor (≥ #2860 + #5115) + a real-Pi mid-turn integration smoke.
|
|
92
|
-
|
|
184
|
+
// here (the injector is mocked) — locked by researcher confirmation + the D6 Pi
|
|
185
|
+
// version floor (≥ #2860 + #5115) + a real-Pi mid-turn integration smoke. The
|
|
186
|
+
// #677 sendUserMessage escalation is the belt-and-suspenders for a missed wake.
|
|
187
|
+
await injector.inject({ customType: 'cue', content, display: true }, { deliverAs: msg.isMaestro ? 'steer' : 'followUp', triggerTurn: true });
|
|
93
188
|
}
|
|
94
189
|
}
|
|
95
190
|
exports.CuePump = CuePump;
|
package/dist/pi/extension.d.ts
CHANGED
|
@@ -9,21 +9,9 @@ import { InnerLoopPublisher } from './inner-loop-publisher';
|
|
|
9
9
|
/** Runtime mode. Headless = recruited unsupervised player (MD-C gate active). */
|
|
10
10
|
export type PiExtensionMode = 'interactive' | 'headless';
|
|
11
11
|
export type PiToolAccess = 'restricted' | 'standard' | 'full';
|
|
12
|
-
|
|
13
|
-
* B1 runtime guard (#645 H4) — the type gate's blind spot.
|
|
14
|
-
*
|
|
15
|
-
* `PiEventPayload.session` is UNDECLARED in Pi 0.78's `.d.ts` — it's an
|
|
16
|
-
* interactive-only RUNTIME field, so the pi-drift type gate can't assert it. In
|
|
17
|
-
* INTERACTIVE mode the `session_start` payload MUST carry `session` (the cue +
|
|
18
|
-
* reset pumps inject into it); a null session there means injection is silently
|
|
19
|
-
* inert — a likely Pi API drift. (Headless legitimately omits it — it wires
|
|
20
|
-
* `rt.session` via `setRuntimeSession` — so the guard is interactive-only.)
|
|
21
|
-
*
|
|
22
|
-
* Pure + injected `warn` so it unit-tests without the workflow harness.
|
|
23
|
-
*/
|
|
24
|
-
export declare function warnIfInteractiveSessionMissing(mode: PiExtensionMode, payload: {
|
|
12
|
+
export declare function noteInteractiveSessionAbsent(mode: PiExtensionMode, payload: {
|
|
25
13
|
session?: unknown;
|
|
26
|
-
},
|
|
14
|
+
}, note: (msg: string) => void): void;
|
|
27
15
|
export interface PiExtensionOptions {
|
|
28
16
|
/** Default `'interactive'`. Headless installs the MD-C tool_call gate. */
|
|
29
17
|
mode?: PiExtensionMode;
|
|
@@ -35,7 +23,7 @@ export interface PiExtensionOptions {
|
|
|
35
23
|
* extension-instance rebuilds. Holds the durable attachment (handle + lease +
|
|
36
24
|
* heartbeat, inside `wf`), the phase driver, the cue pump, and the session ptr.
|
|
37
25
|
*/
|
|
38
|
-
interface PiPlayerRuntime {
|
|
26
|
+
export interface PiPlayerRuntime {
|
|
39
27
|
readonly workflowId: string;
|
|
40
28
|
readonly wf: PiWorkflowClient;
|
|
41
29
|
readonly driver: PhaseDriver;
|
|
@@ -50,6 +38,19 @@ interface PiPlayerRuntime {
|
|
|
50
38
|
/** 3d D14 — polls the workflow's pending reset → clean-wipe (newSession) + ack. */
|
|
51
39
|
readonly reset: ResetPump;
|
|
52
40
|
session: PiAgentSession | null;
|
|
41
|
+
/**
|
|
42
|
+
* #677 — THIS player's CURRENT Pi `ExtensionAPI` handle. Repointed on every
|
|
43
|
+
* instance rebuild (`session_start` re-bind) so the cue pump injects through the
|
|
44
|
+
* live `pi.sendMessage` (the stable interactive-injection path; Pi 0.78.1's
|
|
45
|
+
* SessionStartEvent has no `session` field). Re-resolved per tick — never captured.
|
|
46
|
+
*/
|
|
47
|
+
pi: ExtensionAPI | null;
|
|
48
|
+
/**
|
|
49
|
+
* #677 — epoch-ms of the last observed `turn_start`/`agent_start`. The cue pump
|
|
50
|
+
* reads it to decide whether a sendMessage-injected cue actually woke a turn; if
|
|
51
|
+
* not, it escalates to `sendUserMessage`. `null` until the first turn starts.
|
|
52
|
+
*/
|
|
53
|
+
lastTurnStartAt: number | null;
|
|
53
54
|
lastSessionId?: string;
|
|
54
55
|
}
|
|
55
56
|
/**
|
|
@@ -94,6 +95,19 @@ export declare function __seedRuntimeForTests(workflowId: string, rt: PiPlayerRu
|
|
|
94
95
|
* for the full singleton reset). TEST ESCAPE HATCH — do NOT call from production code.
|
|
95
96
|
*/
|
|
96
97
|
export declare function __clearRuntimesForTests(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Read the live runtime for a workflowId out of the module-scope map. TEST ESCAPE
|
|
100
|
+
* HATCH — do NOT call from production code. Used by the #677 rebind test to assert
|
|
101
|
+
* the post-switch tick injects through the NEW pi (cue pump) AND that the
|
|
102
|
+
* InnerLoopPublisher rebound to it.
|
|
103
|
+
*/
|
|
104
|
+
export declare function __getPiRuntimeForTests(workflowId: string): PiPlayerRuntime | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Reset the one-time interactive-session breadcrumb flag (#677). TEST ESCAPE HATCH
|
|
107
|
+
* — do NOT call from production code. The flag is module-scope and fires at most
|
|
108
|
+
* once per process, so tests asserting the note must reset it between cases.
|
|
109
|
+
*/
|
|
110
|
+
export declare function __resetInteractiveSessionNoteForTests(): void;
|
|
97
111
|
/** Default export — interactive-mode extension (the human `pi` CLI entry). */
|
|
98
112
|
declare const piExtension: (pi: ExtensionAPI) => void;
|
|
99
113
|
export default piExtension;
|
package/dist/pi/extension.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.noteInteractiveSessionAbsent = noteInteractiveSessionAbsent;
|
|
37
37
|
exports.createPiExtension = createPiExtension;
|
|
38
38
|
exports.detachAllPiRuntimesForExit = detachAllPiRuntimesForExit;
|
|
39
39
|
exports.setRuntimeSession = setRuntimeSession;
|
|
@@ -41,6 +41,8 @@ exports.__setPiClientFactoryForTests = __setPiClientFactoryForTests;
|
|
|
41
41
|
exports.__resetPiRuntimesForTests = __resetPiRuntimesForTests;
|
|
42
42
|
exports.__seedRuntimeForTests = __seedRuntimeForTests;
|
|
43
43
|
exports.__clearRuntimesForTests = __clearRuntimesForTests;
|
|
44
|
+
exports.__getPiRuntimeForTests = __getPiRuntimeForTests;
|
|
45
|
+
exports.__resetInteractiveSessionNoteForTests = __resetInteractiveSessionNoteForTests;
|
|
44
46
|
/**
|
|
45
47
|
* agent-tempo Pi extension — interactive (Phase 2) + headless (Phase 3a) runtime.
|
|
46
48
|
*
|
|
@@ -93,24 +95,37 @@ const log = (...args) => {
|
|
|
93
95
|
console.error('[agent-tempo:pi]', ...args);
|
|
94
96
|
};
|
|
95
97
|
const nowIso = () => new Date().toISOString();
|
|
96
|
-
|
|
98
|
+
// Pi IS a first-class AgentType (#666). #676 FIX-2: was a stale 'claude'
|
|
99
|
+
// placeholder — that made a Pi session misreport its agentType metadata AND
|
|
100
|
+
// recruit's mirror-fallback resolve to 'claude'.
|
|
101
|
+
const PI_AGENT_TYPE = 'pi';
|
|
97
102
|
/**
|
|
98
|
-
*
|
|
103
|
+
* Interactive-session breadcrumb (#645 H4 → reworded for #677).
|
|
99
104
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
105
|
+
* Pi 0.78.1's `SessionStartEvent` carries NO `session` field, so in INTERACTIVE
|
|
106
|
+
* mode `payload.session` is null. Pre-#677 that meant cue/reset injection was inert
|
|
107
|
+
* (it read `payload.session`), so this was a WARNING. Post-#677 injection routes
|
|
108
|
+
* through the stable `pi.sendMessage` handle (re-resolved per tick) and a missing
|
|
109
|
+
* session is the EXPECTED path — NOT an error. The "is `pi.sendMessage` still
|
|
110
|
+
* wired?" correctness signal now lives at BUILD time in the H4 drift gate
|
|
111
|
+
* (`test/pi-drift/assert.ts` `_passSendMsg` / `_sendSurfaceCallShape`), so this
|
|
112
|
+
* runtime check's correctness role is redundant.
|
|
106
113
|
*
|
|
107
|
-
*
|
|
114
|
+
* What remains is value as a ONE-TIME, non-alarming boot breadcrumb: during Pi
|
|
115
|
+
* bring-up it confirms at a glance "you're on the expected 0.78.1 no-session path;
|
|
116
|
+
* cues route via pi.sendMessage." Fires AT MOST ONCE per process (the
|
|
117
|
+
* module-scope `notedInteractiveSessionAbsent` flag) — not per switch, not per
|
|
118
|
+
* tick. Pure + injected `note` so it unit-tests without the workflow harness.
|
|
108
119
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
let notedInteractiveSessionAbsent = false;
|
|
121
|
+
function noteInteractiveSessionAbsent(mode, payload, note) {
|
|
122
|
+
if (mode !== 'interactive' || payload.session != null)
|
|
123
|
+
return;
|
|
124
|
+
if (notedInteractiveSessionAbsent)
|
|
125
|
+
return;
|
|
126
|
+
notedInteractiveSessionAbsent = true;
|
|
127
|
+
note('interactive session_start has no `session` field — expected on Pi ≥0.78.1; ' +
|
|
128
|
+
'cues/reset route via pi.sendMessage (re-resolved per tick).');
|
|
114
129
|
}
|
|
115
130
|
// MD-C shell/exec tool-class membership is owned by `tool-capability.ts`
|
|
116
131
|
// (`classify(name) === 'exec'`, content signed off by tempo-security). F1
|
|
@@ -173,6 +188,21 @@ function createPiExtension(options = {}) {
|
|
|
173
188
|
};
|
|
174
189
|
(0, render_tools_1.renderToPi)(pi, (0, server_tools_1.buildAllTempoTools)(toolOpts));
|
|
175
190
|
log(`registered tools (player=${currentPlayerId}, conductor=${isConductor}, mode=${mode})`);
|
|
191
|
+
// ── #677 PART B — interactive-only `/tempo-reset` command ──
|
|
192
|
+
// Pi's `newSession` (clean-wipe) is ExtensionCommandContext-ONLY (not on the
|
|
193
|
+
// SDK session), so an interactive Pi conductor can ONLY be reset by the operator
|
|
194
|
+
// running this command. The reset pump's interactive branch notifies the
|
|
195
|
+
// operator to run it when a peer/conductor requests a reset (operator-mediated
|
|
196
|
+
// is the ceiling). Headless players have no command surface → not registered.
|
|
197
|
+
if (mode === 'interactive' && typeof pi.registerCommand === 'function') {
|
|
198
|
+
pi.registerCommand('tempo-reset', {
|
|
199
|
+
description: "Clean-wipe this Pi session's context (agent-tempo reset).",
|
|
200
|
+
handler: async (_args, ctx) => {
|
|
201
|
+
log('/tempo-reset — clean-wiping session context (newSession)');
|
|
202
|
+
await ctx.newSession();
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
}
|
|
176
206
|
// ── MD-C tool-access gate (HEADLESS ONLY) ──
|
|
177
207
|
// Interactive Pi = a human owns their machine → no gate. Headless = recruited
|
|
178
208
|
// unsupervised → MD-C governs tool access. TOOL-CLASS CHECK FIRST: shell/exec
|
|
@@ -258,6 +288,16 @@ function createPiExtension(options = {}) {
|
|
|
258
288
|
const existing = runtimes.get(workflowId);
|
|
259
289
|
if (existing) {
|
|
260
290
|
existing.session = payload.session ?? existing.session;
|
|
291
|
+
// #677 — repoint to THIS instance's `pi`. Pi rebuilds the extension
|
|
292
|
+
// instance on every session switch; the surviving runtime + its cue pump
|
|
293
|
+
// (created on first attach) re-resolve the injector from `rt.pi` each tick,
|
|
294
|
+
// so the cue pump injects through the LIVE handle, not the stale one.
|
|
295
|
+
existing.pi = pi;
|
|
296
|
+
// #677 FREEBIE — the InnerLoopPublisher was captured-once on the FIRST pi
|
|
297
|
+
// and goes stale after a switch (README:251 carry-item — same root cause).
|
|
298
|
+
// Re-start it on the new pi so its `pi.on(...)` observers track the live
|
|
299
|
+
// instance. `start()` re-registers handlers; its flush timer is idempotent.
|
|
300
|
+
existing.pub.start(pi);
|
|
261
301
|
log(`re-bound ${currentPlayerId} (Pi instance rebuilt; lease intact)`);
|
|
262
302
|
return existing;
|
|
263
303
|
}
|
|
@@ -271,7 +311,11 @@ function createPiExtension(options = {}) {
|
|
|
271
311
|
const driver = new phase_driver_1.PhaseDriver();
|
|
272
312
|
const pump = new cue_pump_1.CuePump({
|
|
273
313
|
source: wf,
|
|
274
|
-
|
|
314
|
+
// #677 — re-resolve the injector from the SURVIVING runtime each tick:
|
|
315
|
+
// prefer `rt.pi.sendMessage` (stable interactive path), fall back to
|
|
316
|
+
// `rt.session.sendCustomMessage`. Reading `runtimes.get(workflowId)` (not a
|
|
317
|
+
// captured `rt`) is what makes a post-rebind tick use the NEW pi.
|
|
318
|
+
resolveInjector: () => (0, cue_pump_1.buildPiInjector)(runtimes.get(workflowId) ?? null),
|
|
275
319
|
});
|
|
276
320
|
// 3c — inner-loop publisher + its loopback-HTTP sink. The client no-ops
|
|
277
321
|
// unless AGENT_TEMPO_INGEST_TOKEN is present (daemon-spawned headless
|
|
@@ -285,8 +329,16 @@ function createPiExtension(options = {}) {
|
|
|
285
329
|
const reset = new reset_pump_1.ResetPump({
|
|
286
330
|
source: wf,
|
|
287
331
|
resolveSession: () => runtimes.get(workflowId)?.session ?? null,
|
|
332
|
+
// #677 PART B — interactive can't auto-wipe (no session field / newSession is
|
|
333
|
+
// command-context-only); the reset pump notifies the operator via this handle.
|
|
334
|
+
resolvePi: () => runtimes.get(workflowId)?.pi ?? null,
|
|
288
335
|
});
|
|
289
|
-
const rt = {
|
|
336
|
+
const rt = {
|
|
337
|
+
workflowId, wf, driver, pump, pub, reset,
|
|
338
|
+
session: payload.session ?? null,
|
|
339
|
+
pi, // #677 — first-attach instance's pi (repointed on each rebind)
|
|
340
|
+
lastTurnStartAt: null,
|
|
341
|
+
};
|
|
290
342
|
runtimes.set(workflowId, rt);
|
|
291
343
|
await wf.ensureSessionWorkflow();
|
|
292
344
|
const result = driver.handle('session_start', payload, nowIso());
|
|
@@ -303,8 +355,9 @@ function createPiExtension(options = {}) {
|
|
|
303
355
|
}
|
|
304
356
|
// ── Lifecycle: session_start → first attach OR re-bind ──
|
|
305
357
|
pi.on('session_start', async (payload) => {
|
|
306
|
-
//
|
|
307
|
-
|
|
358
|
+
// #677: one-time INFO breadcrumb when interactive session_start has no
|
|
359
|
+
// `session` field (the expected 0.78.1 path — injection routes via pi.sendMessage).
|
|
360
|
+
noteInteractiveSessionAbsent(mode, payload, log);
|
|
308
361
|
try {
|
|
309
362
|
const rt = await attachOrRebind(payload);
|
|
310
363
|
await refreshSessionId(rt, rt.session?.id);
|
|
@@ -321,6 +374,10 @@ function createPiExtension(options = {}) {
|
|
|
321
374
|
return;
|
|
322
375
|
if (payload.session)
|
|
323
376
|
rt.session = payload.session;
|
|
377
|
+
// #677 — a turn has begun → stamp for the cue pump's escalation check (so
|
|
378
|
+
// a sendMessage-injected cue that DID wake a turn is not re-escalated).
|
|
379
|
+
if (event === 'agent_start')
|
|
380
|
+
rt.lastTurnStartAt = Date.now();
|
|
324
381
|
const result = rt.driver.handle(event, payload, nowIso());
|
|
325
382
|
try {
|
|
326
383
|
await rt.wf.performAction(result.action);
|
|
@@ -342,6 +399,9 @@ function createPiExtension(options = {}) {
|
|
|
342
399
|
return;
|
|
343
400
|
if (payload.session)
|
|
344
401
|
rt.session = payload.session;
|
|
402
|
+
// #677 — turn_start marks a live turn for the cue pump's escalation check.
|
|
403
|
+
if (event === 'turn_start')
|
|
404
|
+
rt.lastTurnStartAt = Date.now();
|
|
345
405
|
rt.driver.handle(event, payload, nowIso());
|
|
346
406
|
});
|
|
347
407
|
}
|
|
@@ -441,6 +501,23 @@ function __seedRuntimeForTests(workflowId, rt) {
|
|
|
441
501
|
function __clearRuntimesForTests() {
|
|
442
502
|
runtimes.clear();
|
|
443
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Read the live runtime for a workflowId out of the module-scope map. TEST ESCAPE
|
|
506
|
+
* HATCH — do NOT call from production code. Used by the #677 rebind test to assert
|
|
507
|
+
* the post-switch tick injects through the NEW pi (cue pump) AND that the
|
|
508
|
+
* InnerLoopPublisher rebound to it.
|
|
509
|
+
*/
|
|
510
|
+
function __getPiRuntimeForTests(workflowId) {
|
|
511
|
+
return runtimes.get(workflowId);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Reset the one-time interactive-session breadcrumb flag (#677). TEST ESCAPE HATCH
|
|
515
|
+
* — do NOT call from production code. The flag is module-scope and fires at most
|
|
516
|
+
* once per process, so tests asserting the note must reset it between cases.
|
|
517
|
+
*/
|
|
518
|
+
function __resetInteractiveSessionNoteForTests() {
|
|
519
|
+
notedInteractiveSessionAbsent = false;
|
|
520
|
+
}
|
|
444
521
|
/** Default export — interactive-mode extension (the human `pi` CLI entry). */
|
|
445
522
|
const piExtension = createPiExtension();
|
|
446
523
|
exports.default = piExtension;
|
package/dist/pi/index.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ export { PhaseDriver } from './phase-driver';
|
|
|
18
18
|
export type { PiPhase, WorkflowAction, PhaseDriverResult } from './phase-driver';
|
|
19
19
|
export { PiWorkflowClient } from './workflow-client';
|
|
20
20
|
export type { PiWorkflowClientOptions } from './workflow-client';
|
|
21
|
-
export { CuePump } from './cue-pump';
|
|
22
|
-
export type { CueSource,
|
|
21
|
+
export { CuePump, buildPiInjector } from './cue-pump';
|
|
22
|
+
export type { CueSource, MessageInjector, InjectorResolver, InjectorRuntime, CuePumpOptions, } from './cue-pump';
|
|
23
23
|
export { renderToPi, toPiResult } from './render-tools';
|
|
24
24
|
export { createLazyProxy } from './lazy-proxy';
|
|
25
25
|
export { zodShapeToTypeBox, UnsupportedZodFeatureError } from './zod-to-typebox';
|
package/dist/pi/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PI_NODE_FLOOR = exports.TESTED_PI_VERSION = exports.PI_AI_PACKAGE = exports.PI_PACKAGE = exports.probePi = exports.UnsupportedZodFeatureError = exports.zodShapeToTypeBox = exports.createLazyProxy = exports.toPiResult = exports.renderToPi = exports.CuePump = exports.PiWorkflowClient = exports.PhaseDriver = exports.default = void 0;
|
|
6
|
+
exports.PI_NODE_FLOOR = exports.TESTED_PI_VERSION = exports.PI_AI_PACKAGE = exports.PI_PACKAGE = exports.probePi = exports.UnsupportedZodFeatureError = exports.zodShapeToTypeBox = exports.createLazyProxy = exports.toPiResult = exports.renderToPi = exports.buildPiInjector = exports.CuePump = exports.PiWorkflowClient = exports.PhaseDriver = exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* agent-tempo Pi integration — barrel.
|
|
9
9
|
*
|
|
@@ -27,6 +27,7 @@ var workflow_client_1 = require("./workflow-client");
|
|
|
27
27
|
Object.defineProperty(exports, "PiWorkflowClient", { enumerable: true, get: function () { return workflow_client_1.PiWorkflowClient; } });
|
|
28
28
|
var cue_pump_1 = require("./cue-pump");
|
|
29
29
|
Object.defineProperty(exports, "CuePump", { enumerable: true, get: function () { return cue_pump_1.CuePump; } });
|
|
30
|
+
Object.defineProperty(exports, "buildPiInjector", { enumerable: true, get: function () { return cue_pump_1.buildPiInjector; } });
|
|
30
31
|
var render_tools_1 = require("./render-tools");
|
|
31
32
|
Object.defineProperty(exports, "renderToPi", { enumerable: true, get: function () { return render_tools_1.renderToPi; } });
|
|
32
33
|
Object.defineProperty(exports, "toPiResult", { enumerable: true, get: function () { return render_tools_1.toPiResult; } });
|
package/dist/pi/pi-types.d.ts
CHANGED
|
@@ -243,10 +243,60 @@ export interface PiToolDefinition {
|
|
|
243
243
|
*/
|
|
244
244
|
execute: (toolCallId: string, params: Record<string, unknown>, signal?: unknown, onUpdate?: unknown, ctx?: unknown) => Promise<PiToolResult> | PiToolResult;
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* The context Pi passes to a registered command handler (#677 PART B). NARROW
|
|
248
|
+
* structural slice — `/tempo-reset` only calls `newSession()` (clean-wipe).
|
|
249
|
+
* Pi's real `ExtensionCommandContext` (much larger) is assignable to this.
|
|
250
|
+
*
|
|
251
|
+
* `newSession` is command-context-ONLY in Pi — it is NOT on the SDK session
|
|
252
|
+
* object — which is exactly why an interactive Pi conductor CANNOT be auto-reset:
|
|
253
|
+
* the reset pump can only NOTIFY the operator to run `/tempo-reset` themselves
|
|
254
|
+
* (operator-mediated is the ceiling; see reset-pump.ts).
|
|
255
|
+
*/
|
|
256
|
+
export interface PiCommandContext {
|
|
257
|
+
/** Start a FRESH session (clean-wipe, no replay). */
|
|
258
|
+
newSession(): Promise<{
|
|
259
|
+
cancelled: boolean;
|
|
260
|
+
}>;
|
|
261
|
+
}
|
|
262
|
+
/** Options for {@link ExtensionAPI.registerCommand} (#677 PART B) — the slice we set. */
|
|
263
|
+
export interface PiCommandOptions {
|
|
264
|
+
description?: string;
|
|
265
|
+
handler: (args: string, ctx: PiCommandContext) => Promise<void>;
|
|
266
|
+
}
|
|
246
267
|
/** The `pi` object passed to `export default function(pi: ExtensionAPI) {}`. */
|
|
247
268
|
export interface ExtensionAPI {
|
|
248
269
|
on(event: PiLifecycleEvent | string, handler: PiEventHandler): void;
|
|
249
270
|
registerTool(def: PiToolDefinition): void;
|
|
271
|
+
/**
|
|
272
|
+
* Register an interactive slash command (#677 PART B — `/tempo-reset`). Optional
|
|
273
|
+
* in the slice: only the interactive Pi CLI surfaces commands (headless has no
|
|
274
|
+
* command surface). Kept loose by the architect's registerCommand ruling — see
|
|
275
|
+
* test/pi-drift/assert.ts `_registerSurfaceExists`.
|
|
276
|
+
*/
|
|
277
|
+
registerCommand?(name: string, options: PiCommandOptions): void;
|
|
278
|
+
/**
|
|
279
|
+
* Inject a custom message into the live session through the STABLE `pi` handle
|
|
280
|
+
* (#677). Same message shape as `PiAgentSession.sendCustomMessage`'s param0
|
|
281
|
+
* (`Pick<CustomMessage, "customType"|"content"|"display"|"details">`). This is
|
|
282
|
+
* the interactive cue-injection path: Pi 0.78.1's `SessionStartEvent` carries
|
|
283
|
+
* NO `session` field, so `PiEventPayload.session` is null in interactive mode —
|
|
284
|
+
* routing cues through `pi.sendMessage` (re-resolved per tick from the surviving
|
|
285
|
+
* runtime) injects reliably regardless. Optional in the slice (Pi provides it; a
|
|
286
|
+
* fake/older Pi may not — the cue pump feature-detects with `typeof`).
|
|
287
|
+
*/
|
|
288
|
+
sendMessage?(message: PiOutboundMessage, options?: PiCustomMessageOptions): void;
|
|
289
|
+
/**
|
|
290
|
+
* Inject a USER-role message — ALWAYS triggers a turn (#677 escalation path).
|
|
291
|
+
* When `sendMessage`'s `triggerTurn` fails to wake a cold-idle agent, the cue
|
|
292
|
+
* pump re-injects the SAME cue via this user-role call (a user message always
|
|
293
|
+
* starts a turn). It LOSES the `cue` customType + operator-vs-peer steer/followUp
|
|
294
|
+
* semantics, so it is FALLBACK-ONLY (never the primary route). Optional in the
|
|
295
|
+
* slice for the same reason as `sendMessage`.
|
|
296
|
+
*/
|
|
297
|
+
sendUserMessage?(content: string, options?: {
|
|
298
|
+
deliverAs?: 'steer' | 'followUp';
|
|
299
|
+
}): void;
|
|
250
300
|
}
|
|
251
301
|
/** An extension is a default-exported function receiving the `ExtensionAPI`. */
|
|
252
302
|
export type PiExtension = (pi: ExtensionAPI) => void | Promise<void>;
|