pi-harness-runtime 1.1.514 → 1.1.516
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -0
- package/harness/approval-decision-store.ts +94 -0
- package/harness/delegated-approval-runtime.ts +375 -0
- package/harness/delegated-approval-types.ts +179 -0
- package/harness/delegation-store.ts +108 -0
- package/harness/exploration-checkpoint-tool.ts +216 -0
- package/harness/exploration-guard-runtime.ts +23 -0
- package/harness/jev-rejection-escalation.ts +248 -0
- package/harness/plan-handoff-bridge.ts +27 -6
- package/harness/plan-handoff-receiver.ts +258 -0
- package/harness/plan-handoff-registration.ts +28 -13
- package/index.ts +516 -23
- package/package.json +1 -4
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/dist/atomic-write.d.ts +16 -0
- package/packages/cookie-sanitizer/dist/atomic-write.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/atomic-write.js +28 -0
- package/packages/cookie-sanitizer/dist/atomic-write.js.map +1 -1
- package/packages/cookie-sanitizer/dist/index.d.ts +1 -1
- package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/index.js +1 -1
- package/packages/cookie-sanitizer/dist/index.js.map +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cookie-sanitizer/src/atomic-write.ts +29 -0
- package/packages/cookie-sanitizer/src/index.ts +1 -0
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/exploration-guard/dist/checkpoint.d.ts +12 -0
- package/packages/exploration-guard/dist/checkpoint.d.ts.map +1 -1
- package/packages/exploration-guard/dist/checkpoint.js +33 -1
- package/packages/exploration-guard/dist/checkpoint.js.map +1 -1
- package/packages/exploration-guard/dist/observation.d.ts +7 -0
- package/packages/exploration-guard/dist/observation.d.ts.map +1 -1
- package/packages/exploration-guard/dist/observation.js +90 -27
- package/packages/exploration-guard/dist/observation.js.map +1 -1
- package/packages/exploration-guard/dist/tracker.d.ts.map +1 -1
- package/packages/exploration-guard/dist/tracker.js +3 -1
- package/packages/exploration-guard/dist/tracker.js.map +1 -1
- package/packages/exploration-guard/dist/types.d.ts +1 -1
- package/packages/exploration-guard/dist/types.d.ts.map +1 -1
- package/packages/exploration-guard/package.json +1 -1
- package/packages/exploration-guard/src/checkpoint.ts +44 -1
- package/packages/exploration-guard/src/observation.ts +120 -26
- package/packages/exploration-guard/src/tracker.ts +3 -1
- package/packages/exploration-guard/src/types.ts +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/continuation-controller.d.ts +43 -0
- package/packages/jev-judge/dist/continuation-controller.d.ts.map +1 -1
- package/packages/jev-judge/dist/continuation-controller.js +54 -7
- package/packages/jev-judge/dist/continuation-controller.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/continuation-controller.ts +89 -7
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
- package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
- package/packages/notification/dist/notification-center.d.ts.map +1 -1
- package/packages/notification/dist/notification-center.js +7 -0
- package/packages/notification/dist/notification-center.js.map +1 -1
- package/packages/notification/dist/notification-policy.d.ts.map +1 -1
- package/packages/notification/dist/notification-policy.js +6 -0
- package/packages/notification/dist/notification-policy.js.map +1 -1
- package/packages/notification/dist/types.d.ts +9 -1
- package/packages/notification/dist/types.d.ts.map +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
- package/packages/notification/src/notification-center.ts +7 -0
- package/packages/notification/src/notification-policy.ts +6 -0
- package/packages/notification/src/types.ts +8 -0
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/plan-handoff/dist/mailbox.d.ts +7 -0
- package/packages/plan-handoff/dist/mailbox.d.ts.map +1 -1
- package/packages/plan-handoff/dist/mailbox.js +9 -0
- package/packages/plan-handoff/dist/mailbox.js.map +1 -1
- package/packages/plan-handoff/package.json +1 -1
- package/packages/plan-handoff/src/mailbox.ts +12 -0
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
- package/prompts/slash-commands.md +0 -2
- package/packages/knowledge-retrieval/dist/index.d.ts +0 -8
- package/packages/knowledge-retrieval/dist/index.d.ts.map +0 -1
- package/packages/knowledge-retrieval/dist/index.js +0 -7
- package/packages/knowledge-retrieval/dist/index.js.map +0 -1
- package/packages/knowledge-retrieval/dist/mcp-client.d.ts +0 -61
- package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +0 -1
- package/packages/knowledge-retrieval/dist/mcp-client.js +0 -131
- package/packages/knowledge-retrieval/dist/mcp-client.js.map +0 -1
- package/packages/knowledge-retrieval/dist/types.d.ts +0 -105
- package/packages/knowledge-retrieval/dist/types.d.ts.map +0 -1
- package/packages/knowledge-retrieval/dist/types.js +0 -7
- package/packages/knowledge-retrieval/dist/types.js.map +0 -1
- package/packages/knowledge-retrieval/package.json +0 -22
- package/packages/knowledge-retrieval/src/index.ts +0 -18
- package/packages/knowledge-retrieval/src/mcp-client.ts +0 -211
- package/packages/knowledge-retrieval/src/types.ts +0 -112
- package/prompts/tencentdb-connect.md +0 -35
- package/prompts/tencentdb-setup.md +0 -101
- package/prompts/tencentdb.md +0 -88
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The receiver of the plans of this instance.
|
|
3
|
+
*
|
|
4
|
+
* The recipient of a plan is the only instance that reads the plan. The
|
|
5
|
+
* receiver of the instance owns the loop that reads the mailbox of the
|
|
6
|
+
* instance, claims every plan that is addressed to it, hands it to the
|
|
7
|
+
* session and acknowledges the delivery.
|
|
8
|
+
*
|
|
9
|
+
* Without this loop a plan that was routed to an instance stays in its
|
|
10
|
+
* mailbox: the routing decided who receives the plan, but nobody read it.
|
|
11
|
+
* The instance that receives the plan is the one that executes it, never
|
|
12
|
+
* the instance that sent it.
|
|
13
|
+
*
|
|
14
|
+
* The receiver never authorises anything: it hands a plan to the session
|
|
15
|
+
* that was chosen, and the session decides what to do with it.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
acknowledgePlan,
|
|
20
|
+
claimPlan,
|
|
21
|
+
receivePlans,
|
|
22
|
+
} from "./plan-handoff-bridge.ts";
|
|
23
|
+
import type {
|
|
24
|
+
AgentRegistration,
|
|
25
|
+
Mailbox,
|
|
26
|
+
PlanHandoffMessage,
|
|
27
|
+
} from "../packages/plan-handoff/dist/index.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The bridge the receiver uses.
|
|
31
|
+
*
|
|
32
|
+
* The seam keeps the loop testable without a file system: a test replaces
|
|
33
|
+
* the bridge and watches what the loop does.
|
|
34
|
+
*/
|
|
35
|
+
export interface PlanReceiverBridge {
|
|
36
|
+
/** The plans that are addressed to this instance. */
|
|
37
|
+
receive(options: {
|
|
38
|
+
registration: AgentRegistration;
|
|
39
|
+
now?: () => number;
|
|
40
|
+
mailbox?: Mailbox;
|
|
41
|
+
}): PlanHandoffMessage[];
|
|
42
|
+
/** Claim a plan for this instance. */
|
|
43
|
+
claim(agentId: string, messageId: string, mailbox?: Mailbox): boolean;
|
|
44
|
+
/** Acknowledge the delivery of a plan. */
|
|
45
|
+
acknowledge(agentId: string, messageId: string, mailbox?: Mailbox): boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The options of the receiver.
|
|
50
|
+
*/
|
|
51
|
+
export interface PlanReceiverOptions {
|
|
52
|
+
/** The registration of this instance. */
|
|
53
|
+
registration: AgentRegistration;
|
|
54
|
+
/**
|
|
55
|
+
* Hand a plan to the session of this instance.
|
|
56
|
+
*
|
|
57
|
+
* The delivery is awaited: a plan that was not handed over stays
|
|
58
|
+
* claimed and is delivered again in the next round.
|
|
59
|
+
*/
|
|
60
|
+
deliver: (message: PlanHandoffMessage) => Promise<void> | void;
|
|
61
|
+
/** The interval between two rounds. */
|
|
62
|
+
intervalMs?: number;
|
|
63
|
+
/** The clock. */
|
|
64
|
+
now?: () => number;
|
|
65
|
+
/** The bridge. The real one by default. */
|
|
66
|
+
bridge?: PlanReceiverBridge;
|
|
67
|
+
/**
|
|
68
|
+
* The mailbox of this instance.
|
|
69
|
+
*
|
|
70
|
+
* The mailbox of the agent by default. A test passes its own mailbox
|
|
71
|
+
* and still exercises the real bridge.
|
|
72
|
+
*/
|
|
73
|
+
mailbox?: Mailbox;
|
|
74
|
+
/**
|
|
75
|
+
* Should this plan wait instead of being handed over?
|
|
76
|
+
*
|
|
77
|
+
* A plan that is held stays pending in the mailbox: it is never
|
|
78
|
+
* claimed, never delivered and never acknowledged. The human decides
|
|
79
|
+
* when it is handed over.
|
|
80
|
+
*/
|
|
81
|
+
hold?: (message: PlanHandoffMessage) => boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The receiver of one instance.
|
|
86
|
+
*/
|
|
87
|
+
export interface PlanReceiver {
|
|
88
|
+
/** The runtime-generated identity of the instance. */
|
|
89
|
+
readonly agentId: string;
|
|
90
|
+
/** The session of the instance. */
|
|
91
|
+
readonly sessionId: string;
|
|
92
|
+
/** The generation of the instance. */
|
|
93
|
+
readonly generation: number;
|
|
94
|
+
/** Start the loop. */
|
|
95
|
+
start(): void;
|
|
96
|
+
/** Stop the loop. */
|
|
97
|
+
stop(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Run one round now.
|
|
100
|
+
*
|
|
101
|
+
* The number of the plans that were handed over is returned, so a test
|
|
102
|
+
* and a caller can see what the round did.
|
|
103
|
+
*/
|
|
104
|
+
poll(): Promise<number>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The interval between two rounds of the receiver.
|
|
109
|
+
*/
|
|
110
|
+
export const PLAN_RECEIVER_INTERVAL_MS = 2_000;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The bridge of the real store.
|
|
114
|
+
*/
|
|
115
|
+
const realBridge: PlanReceiverBridge = {
|
|
116
|
+
receive: (options) => receivePlans(options),
|
|
117
|
+
claim: (agentId, messageId, mailbox) =>
|
|
118
|
+
claimPlan(agentId, messageId, mailbox),
|
|
119
|
+
acknowledge: (agentId, messageId, mailbox) =>
|
|
120
|
+
acknowledgePlan(agentId, messageId, mailbox),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The text that hands a plan to a session.
|
|
125
|
+
*
|
|
126
|
+
* The text says what the plan is and where it lives. It never tells the
|
|
127
|
+
* session to commit, to push or to build: the plan itself carries that
|
|
128
|
+
* decision, and the human owns the rest.
|
|
129
|
+
*/
|
|
130
|
+
export function planDeliveryText(message: PlanHandoffMessage): string {
|
|
131
|
+
const lines = ["A plan was handed to this session."];
|
|
132
|
+
if (message.plan.summary) {
|
|
133
|
+
lines.push(`Summary: ${message.plan.summary}`);
|
|
134
|
+
}
|
|
135
|
+
if (message.plan.reference) {
|
|
136
|
+
lines.push(
|
|
137
|
+
"",
|
|
138
|
+
`Read and follow the plan at: ${message.plan.reference}`,
|
|
139
|
+
"",
|
|
140
|
+
"Treat that file as the task requirements. Start by summarizing the plan and then carry it out. Do not edit the plan unless the user asks.",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return lines.join("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Start the receiver of the plans of this instance.
|
|
148
|
+
*
|
|
149
|
+
* The loop is owned by the session: it starts with the session and stops
|
|
150
|
+
* with it, so a plan never arrives in a session that is gone.
|
|
151
|
+
*/
|
|
152
|
+
export function startPlanReceiver(
|
|
153
|
+
options: PlanReceiverOptions,
|
|
154
|
+
): PlanReceiver {
|
|
155
|
+
const bridge = options.bridge ?? realBridge;
|
|
156
|
+
const now = options.now ?? (() => Date.now());
|
|
157
|
+
const intervalMs = options.intervalMs ?? PLAN_RECEIVER_INTERVAL_MS;
|
|
158
|
+
/**
|
|
159
|
+
* The plans this instance already handed over.
|
|
160
|
+
*
|
|
161
|
+
* A plan that was delivered but whose acknowledgement failed stays in
|
|
162
|
+
* the mailbox: the next round sees it again and acknowledges it, but it
|
|
163
|
+
* is never delivered twice.
|
|
164
|
+
*/
|
|
165
|
+
const delivered = new Set<string>();
|
|
166
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
167
|
+
let stopped = false;
|
|
168
|
+
|
|
169
|
+
const poll = async (): Promise<number> => {
|
|
170
|
+
if (stopped) return 0;
|
|
171
|
+
let messages: PlanHandoffMessage[];
|
|
172
|
+
try {
|
|
173
|
+
messages = bridge.receive({
|
|
174
|
+
registration: options.registration,
|
|
175
|
+
now,
|
|
176
|
+
mailbox: options.mailbox,
|
|
177
|
+
});
|
|
178
|
+
} catch {
|
|
179
|
+
// The mailbox could not be read: the round is skipped, never a
|
|
180
|
+
// failure of the session.
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let handed = 0;
|
|
185
|
+
for (const message of messages) {
|
|
186
|
+
if (options.hold?.(message)) {
|
|
187
|
+
// The plan waits for the human: it stays pending and is
|
|
188
|
+
// never claimed.
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (delivered.has(message.id)) {
|
|
192
|
+
// The plan was handed over already: the acknowledgement is
|
|
193
|
+
// retried, the plan is not delivered twice.
|
|
194
|
+
try {
|
|
195
|
+
bridge.acknowledge(
|
|
196
|
+
options.registration.agentId,
|
|
197
|
+
message.id,
|
|
198
|
+
options.mailbox,
|
|
199
|
+
);
|
|
200
|
+
} catch {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
if (
|
|
207
|
+
!bridge.claim(
|
|
208
|
+
options.registration.agentId,
|
|
209
|
+
message.id,
|
|
210
|
+
options.mailbox,
|
|
211
|
+
)
|
|
212
|
+
) {
|
|
213
|
+
// The plan was delivered by somebody else or cancelled.
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
await options.deliver(message);
|
|
217
|
+
} catch {
|
|
218
|
+
// The plan stays claimed: the next round hands it over
|
|
219
|
+
// again. A plan that cannot be delivered is never lost.
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
delivered.add(message.id);
|
|
223
|
+
handed += 1;
|
|
224
|
+
try {
|
|
225
|
+
bridge.acknowledge(
|
|
226
|
+
options.registration.agentId,
|
|
227
|
+
message.id,
|
|
228
|
+
options.mailbox,
|
|
229
|
+
);
|
|
230
|
+
} catch {
|
|
231
|
+
// The acknowledgement failed: the plan stays in the mailbox
|
|
232
|
+
// and is acknowledged in a later round.
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return handed;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
agentId: options.registration.agentId,
|
|
240
|
+
sessionId: options.registration.sessionId,
|
|
241
|
+
generation: options.registration.generation,
|
|
242
|
+
start: () => {
|
|
243
|
+
if (timer || stopped) return;
|
|
244
|
+
timer = setInterval(() => {
|
|
245
|
+
void poll();
|
|
246
|
+
}, intervalMs);
|
|
247
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
248
|
+
},
|
|
249
|
+
stop: () => {
|
|
250
|
+
stopped = true;
|
|
251
|
+
if (timer) {
|
|
252
|
+
clearInterval(timer);
|
|
253
|
+
timer = null;
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
poll,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -57,6 +57,14 @@ export interface PlanHandoffAgent {
|
|
|
57
57
|
generation: number;
|
|
58
58
|
/** The store the registration lives in. */
|
|
59
59
|
store: RegistrationStore;
|
|
60
|
+
/**
|
|
61
|
+
* The registration of this instance.
|
|
62
|
+
*
|
|
63
|
+
* The receiver of the plans reads the mailbox of the instance with
|
|
64
|
+
* this identity, so the receiver and the registration always agree on
|
|
65
|
+
* which instance they are.
|
|
66
|
+
*/
|
|
67
|
+
registration: AgentRegistration;
|
|
60
68
|
/** Remove the registration and stop the heartbeat. */
|
|
61
69
|
stop: () => void;
|
|
62
70
|
}
|
|
@@ -135,20 +143,26 @@ export function startPlanHandoffRegistration(
|
|
|
135
143
|
const host = options.host ?? hostname();
|
|
136
144
|
const pid = options.pid ?? process.pid;
|
|
137
145
|
|
|
146
|
+
// The registration of this instance. The receiver of the plans reads
|
|
147
|
+
// the mailbox of the instance with this identity.
|
|
148
|
+
const registration: AgentRegistration = {
|
|
149
|
+
agentId,
|
|
150
|
+
sessionId: options.sessionId,
|
|
151
|
+
generation,
|
|
152
|
+
workspace: workspace.path,
|
|
153
|
+
host,
|
|
154
|
+
pid,
|
|
155
|
+
modelLabel: options.modelLabel,
|
|
156
|
+
busy: false,
|
|
157
|
+
paused: false,
|
|
158
|
+
startedAt: now(),
|
|
159
|
+
heartbeatAt: now(),
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// The heartbeat raises the beat of the same registration: the start of
|
|
163
|
+
// the instance does not change with every beat.
|
|
138
164
|
const write = (): void => {
|
|
139
|
-
|
|
140
|
-
agentId,
|
|
141
|
-
sessionId: options.sessionId,
|
|
142
|
-
generation,
|
|
143
|
-
workspace: workspace.path,
|
|
144
|
-
host,
|
|
145
|
-
pid,
|
|
146
|
-
modelLabel: options.modelLabel,
|
|
147
|
-
busy: false,
|
|
148
|
-
paused: false,
|
|
149
|
-
startedAt: now(),
|
|
150
|
-
heartbeatAt: now(),
|
|
151
|
-
};
|
|
165
|
+
registration.heartbeatAt = now();
|
|
152
166
|
store.upsert(registration);
|
|
153
167
|
};
|
|
154
168
|
|
|
@@ -161,6 +175,7 @@ export function startPlanHandoffRegistration(
|
|
|
161
175
|
sessionId: options.sessionId,
|
|
162
176
|
generation,
|
|
163
177
|
store,
|
|
178
|
+
registration,
|
|
164
179
|
stop: () => {
|
|
165
180
|
clearInterval(heartbeat);
|
|
166
181
|
store.remove(agentId);
|