pi-harness-runtime 1.1.508 → 1.1.510
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 +175 -0
- package/harness/auto-resume-marker.ts +55 -13
- package/harness/local-refusal-marker.ts +104 -0
- package/harness/scope-expansion-runtime.ts +142 -15
- package/harness/scope-expansion.ts +150 -35
- package/index.ts +229 -43
- package/package.json +1 -1
- 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/package.json +1 -1
- 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/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/auto-continue.d.ts.map +1 -1
- package/packages/jev-judge/dist/auto-continue.js +11 -1
- package/packages/jev-judge/dist/auto-continue.js.map +1 -1
- package/packages/jev-judge/dist/question-risk.d.ts +8 -0
- package/packages/jev-judge/dist/question-risk.d.ts.map +1 -1
- package/packages/jev-judge/dist/question-risk.js +17 -0
- package/packages/jev-judge/dist/question-risk.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/auto-continue.ts +13 -1
- package/packages/jev-judge/src/question-risk.ts +19 -0
- package/packages/knowledge-retrieval/package.json +1 -1
- 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/notification-center.d.ts +8 -4
- package/packages/notification/dist/notification-center.d.ts.map +1 -1
- package/packages/notification/dist/notification-center.js +18 -9
- 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 +3 -0
- package/packages/notification/dist/notification-policy.js.map +1 -1
- package/packages/notification/dist/pending-question.d.ts +89 -1
- package/packages/notification/dist/pending-question.d.ts.map +1 -1
- package/packages/notification/dist/pending-question.js +220 -4
- package/packages/notification/dist/pending-question.js.map +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/notification/src/notification-center.ts +18 -9
- package/packages/notification/src/notification-policy.ts +3 -0
- package/packages/notification/src/pending-question.ts +287 -3
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- 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
|
@@ -131,6 +131,14 @@ export interface PendingQuestion {
|
|
|
131
131
|
resolution?: "yes" | "no" | "clarification";
|
|
132
132
|
/** Who resolved it */
|
|
133
133
|
resolvedBy?: ResolutionSource;
|
|
134
|
+
/**
|
|
135
|
+
* The local decision of the harness.
|
|
136
|
+
*
|
|
137
|
+
* A local decision is neither an answer of the human nor a decision of
|
|
138
|
+
* the judge: nobody was asked and nobody answered. The question is closed
|
|
139
|
+
* with the resolution, and this field names the decision as a local one.
|
|
140
|
+
*/
|
|
141
|
+
localDecision?: "no";
|
|
134
142
|
/** The channel a human answer came from. Unset for a Jev resolution. */
|
|
135
143
|
resolvedChannel?: ResolutionChannel;
|
|
136
144
|
/** The Jev outcome, when the decision was autonomous. */
|
|
@@ -213,6 +221,185 @@ export function hasExplicitAuthorizationWording(text: string): boolean {
|
|
|
213
221
|
return EXPLICIT_AUTHORIZATION_PATTERNS.some((pattern) => pattern.test(text));
|
|
214
222
|
}
|
|
215
223
|
|
|
224
|
+
/**
|
|
225
|
+
* The stem of a permission request.
|
|
226
|
+
*
|
|
227
|
+
* "May I …?" asks the human for a permission. The question is an approval
|
|
228
|
+
* question: the agent proposes an action and waits for a yes or a no.
|
|
229
|
+
*/
|
|
230
|
+
const PERMISSION_REQUEST = /^may\s+i\b/i;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The verbs that name a deletion.
|
|
234
|
+
*/
|
|
235
|
+
const DELETION_VERBS = new Set(["delete", "remove", "rm", "unlink"]);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The words a narrowly scoped deletion of a temporary path may carry.
|
|
239
|
+
*
|
|
240
|
+
* Every other word is a reason to ask the human: the harness refuses only a
|
|
241
|
+
* deletion that it can read without doubt.
|
|
242
|
+
*/
|
|
243
|
+
const TEMPORARY_DELETION_FILLERS = new Set([
|
|
244
|
+
"a",
|
|
245
|
+
"all",
|
|
246
|
+
"an",
|
|
247
|
+
"and",
|
|
248
|
+
"any",
|
|
249
|
+
"cache",
|
|
250
|
+
"dir",
|
|
251
|
+
"directory",
|
|
252
|
+
"file",
|
|
253
|
+
"files",
|
|
254
|
+
"folder",
|
|
255
|
+
"for",
|
|
256
|
+
"free",
|
|
257
|
+
"from",
|
|
258
|
+
"in",
|
|
259
|
+
"into",
|
|
260
|
+
"it",
|
|
261
|
+
"its",
|
|
262
|
+
"leftover",
|
|
263
|
+
"leftovers",
|
|
264
|
+
"log",
|
|
265
|
+
"logs",
|
|
266
|
+
"me",
|
|
267
|
+
"my",
|
|
268
|
+
"of",
|
|
269
|
+
"old",
|
|
270
|
+
"or",
|
|
271
|
+
"our",
|
|
272
|
+
"please",
|
|
273
|
+
"space",
|
|
274
|
+
"stale",
|
|
275
|
+
"temp",
|
|
276
|
+
"temporary",
|
|
277
|
+
"the",
|
|
278
|
+
"these",
|
|
279
|
+
"this",
|
|
280
|
+
"those",
|
|
281
|
+
"tmp",
|
|
282
|
+
"under",
|
|
283
|
+
"us",
|
|
284
|
+
"we",
|
|
285
|
+
"you",
|
|
286
|
+
"your",
|
|
287
|
+
]);
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The words that name a serious operation.
|
|
291
|
+
*
|
|
292
|
+
* A question that names one of them waits for the human: the harness
|
|
293
|
+
* refuses the deletion of a temporary file, and a credential, a production
|
|
294
|
+
* path or a payment is never a temporary file.
|
|
295
|
+
*/
|
|
296
|
+
const SERIOUS_OPERATION =
|
|
297
|
+
/\b(?:credential|credentials|secret|secrets|token|tokens|password|passwd|api[- _]?key|private[- _]?key|id_rsa|\.pem|\.env|\.ssh|production|prod|staging|database|postgres|mysql|sqlite|customer|customers|payment|payments|invoice|invoices|billing|refund|charge|money|deploy|deployment|publish|release|merge|push|install|upgrade|migrat\w*|rollback|curl|wget|https?|email|slack|webhook|systemctl|docker|kubectl|sudo|ssh)\b/i;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The reason codes of the classifier of a temporary deletion.
|
|
301
|
+
*/
|
|
302
|
+
export const TEMPORARY_DELETION_REASONS = {
|
|
303
|
+
/** The question does not ask for a permission. */
|
|
304
|
+
notAPermissionRequest: "not-a-permission-request",
|
|
305
|
+
/** The question does not ask for a deletion. */
|
|
306
|
+
notADeletion: "not-a-deletion",
|
|
307
|
+
/** The question reserves the decision for the human. */
|
|
308
|
+
explicitAuthorization: "explicit-authorization",
|
|
309
|
+
/** The question names a serious operation. */
|
|
310
|
+
seriousOperation: "serious-operation",
|
|
311
|
+
/** The question names no path under the temporary directory. */
|
|
312
|
+
noTemporaryPath: "no-temporary-path",
|
|
313
|
+
/** The question names a path outside the temporary directory. */
|
|
314
|
+
pathOutsideTemporary: "path-outside-temporary-directory",
|
|
315
|
+
/** The question names an operation the harness does not read. */
|
|
316
|
+
unknownOperation: "unknown-operation",
|
|
317
|
+
} as const;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* The verdict of the classifier of a temporary deletion.
|
|
321
|
+
*/
|
|
322
|
+
export interface TemporaryDeletionRequest {
|
|
323
|
+
/** Does the question ask for the deletion of a path under /tmp? */
|
|
324
|
+
applies: boolean;
|
|
325
|
+
/** Why the request does not qualify, when it does not. */
|
|
326
|
+
reason: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Does the token look like a path?
|
|
331
|
+
*
|
|
332
|
+
* A relative path without a root ("tmp/build") is not a path of the
|
|
333
|
+
* temporary directory of the machine, so it does not count.
|
|
334
|
+
*/
|
|
335
|
+
function isPathLike(token: string): boolean {
|
|
336
|
+
return /^[~$./]/.test(token);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Classify a narrowly scoped deletion of a temporary path.
|
|
341
|
+
*
|
|
342
|
+
* The harness refuses the deletion of a temporary path on its own: the
|
|
343
|
+
* answer is always "No", so neither the judge nor the human is asked. The
|
|
344
|
+
* classifier is deliberately narrow:
|
|
345
|
+
*
|
|
346
|
+
* - the question asks for a permission ("May I …?") and for a deletion,
|
|
347
|
+
* - it names at least one path under the temporary directory,
|
|
348
|
+
* - it names no other path, and
|
|
349
|
+
* - every other word is a filler word.
|
|
350
|
+
*
|
|
351
|
+
* A cleanup that is ambiguous ("clean up /tmp"), a path outside the
|
|
352
|
+
* temporary directory, a mixed operation and an explicit request for an
|
|
353
|
+
* authorization all wait for the human.
|
|
354
|
+
*/
|
|
355
|
+
export function classifyTemporaryDeletionRequest(
|
|
356
|
+
questionText: string,
|
|
357
|
+
): TemporaryDeletionRequest {
|
|
358
|
+
const text = (questionText ?? "").trim();
|
|
359
|
+
if (!PERMISSION_REQUEST.test(text)) {
|
|
360
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.notAPermissionRequest };
|
|
361
|
+
}
|
|
362
|
+
// An explicit authorization is reserved for the human: the harness does
|
|
363
|
+
// not answer in the place of the human.
|
|
364
|
+
if (hasExplicitAuthorizationWording(text)) {
|
|
365
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.explicitAuthorization };
|
|
366
|
+
}
|
|
367
|
+
// A serious operation waits for the human, even when it happens to
|
|
368
|
+
// name a temporary path.
|
|
369
|
+
if (SERIOUS_OPERATION.test(text)) {
|
|
370
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.seriousOperation };
|
|
371
|
+
}
|
|
372
|
+
const tokens = text
|
|
373
|
+
.replace(PERMISSION_REQUEST, "")
|
|
374
|
+
.trim()
|
|
375
|
+
.split(/\s+/)
|
|
376
|
+
.map((token) => token.replace(/^[('"`]+/, "").replace(/[.,;:!?)"'`]+$/, ""))
|
|
377
|
+
.filter((token) => token.length > 0);
|
|
378
|
+
if (tokens.length === 0 || !DELETION_VERBS.has(tokens[0].toLowerCase())) {
|
|
379
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.notADeletion };
|
|
380
|
+
}
|
|
381
|
+
const paths = tokens.filter((token) => isPathLike(token));
|
|
382
|
+
const temporary = paths.filter(
|
|
383
|
+
(token) => token.startsWith("/tmp/") && token.length > "/tmp/".length,
|
|
384
|
+
);
|
|
385
|
+
if (temporary.length === 0) {
|
|
386
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.noTemporaryPath };
|
|
387
|
+
}
|
|
388
|
+
if (paths.some((token) => !token.startsWith("/tmp/"))) {
|
|
389
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.pathOutsideTemporary };
|
|
390
|
+
}
|
|
391
|
+
// Every other word must be a filler: a word that names another
|
|
392
|
+
// operation is a reason to ask the human.
|
|
393
|
+
for (const token of tokens.slice(1)) {
|
|
394
|
+
if (isPathLike(token)) continue;
|
|
395
|
+
const word = token.toLowerCase();
|
|
396
|
+
if (!TEMPORARY_DELETION_FILLERS.has(word)) {
|
|
397
|
+
return { applies: false, reason: TEMPORARY_DELETION_REASONS.unknownOperation };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { applies: true, reason: "temporary-path-deletion" };
|
|
401
|
+
}
|
|
402
|
+
|
|
216
403
|
/**
|
|
217
404
|
* The typed ask of a question kind.
|
|
218
405
|
*/
|
|
@@ -268,6 +455,9 @@ const APPROVAL_STEMS: RegExp[] = [
|
|
|
268
455
|
/\bshould we\b/i,
|
|
269
456
|
/\bdo you want me to\b/i,
|
|
270
457
|
/\bcan i (?:start|proceed|add|implement)\b/i,
|
|
458
|
+
// "May I …?" asks for a permission. It is an approval question: the
|
|
459
|
+
// agent proposes an action and waits for a yes or a no.
|
|
460
|
+
/\bmay i\b/i,
|
|
271
461
|
];
|
|
272
462
|
|
|
273
463
|
/**
|
|
@@ -481,7 +671,17 @@ export class PendingQuestionController {
|
|
|
481
671
|
// Look backwards for sentence start
|
|
482
672
|
for (let i = questionIndex - 1; i >= searchFrom; i--) {
|
|
483
673
|
const char = text[i];
|
|
484
|
-
if (char === '
|
|
674
|
+
if (char === '!' || char === '\n') {
|
|
675
|
+
sentenceStart = i + 1;
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
// A dot ends a sentence only when a space follows it: the
|
|
679
|
+
// dot of a file name ("/tmp/pi-harness.log") belongs to the
|
|
680
|
+
// name and not to the end of a sentence.
|
|
681
|
+
if (
|
|
682
|
+
char === '.' &&
|
|
683
|
+
(i + 1 >= text.length || isSpace(text[i + 1]))
|
|
684
|
+
) {
|
|
485
685
|
sentenceStart = i + 1;
|
|
486
686
|
break;
|
|
487
687
|
}
|
|
@@ -844,6 +1044,15 @@ export class PendingQuestionController {
|
|
|
844
1044
|
requestId?: string;
|
|
845
1045
|
/** The channel a human answer came from. */
|
|
846
1046
|
channel?: ResolutionChannel;
|
|
1047
|
+
/**
|
|
1048
|
+
* Notify the callback of the user answer.
|
|
1049
|
+
*
|
|
1050
|
+
* A question that is not a question of the work - a proposal of the
|
|
1051
|
+
* backlog, for example - is answered by the human without becoming an
|
|
1052
|
+
* answer of the request: the callback would clear the wait of the
|
|
1053
|
+
* request and steer an answer into the conversation.
|
|
1054
|
+
*/
|
|
1055
|
+
notifyUser?: boolean;
|
|
847
1056
|
}): boolean {
|
|
848
1057
|
if (!this.currentQuestion) {
|
|
849
1058
|
logWarn("[PendingQuestion]", "No question to resolve - no pending question");
|
|
@@ -896,7 +1105,7 @@ export class PendingQuestionController {
|
|
|
896
1105
|
eligible: true,
|
|
897
1106
|
});
|
|
898
1107
|
}
|
|
899
|
-
} else if (this.userAnswerCallback) {
|
|
1108
|
+
} else if (this.userAnswerCallback && params.notifyUser !== false) {
|
|
900
1109
|
this.userAnswerCallback(this.currentQuestion, params.resolution);
|
|
901
1110
|
}
|
|
902
1111
|
|
|
@@ -1049,19 +1258,94 @@ export class PendingQuestionController {
|
|
|
1049
1258
|
action: string,
|
|
1050
1259
|
requestId: string,
|
|
1051
1260
|
channel: ResolutionChannel,
|
|
1261
|
+
options?: {
|
|
1262
|
+
/**
|
|
1263
|
+
* Notify the callback of the user answer.
|
|
1264
|
+
*
|
|
1265
|
+
* A question that is not a question of the work of the request - a
|
|
1266
|
+
* proposal of the backlog - is answered without an answer of the
|
|
1267
|
+
* request: the callback would clear the wait of the request and steer
|
|
1268
|
+
* an answer into the conversation.
|
|
1269
|
+
*/
|
|
1270
|
+
notifyUser?: boolean;
|
|
1271
|
+
},
|
|
1052
1272
|
): { applied: boolean; resolution?: "yes" | "no"; reason?: string } {
|
|
1053
1273
|
if (action !== "approve" && action !== "reject") {
|
|
1054
1274
|
return { applied: false, reason: `unknown action '${action}'` };
|
|
1055
1275
|
}
|
|
1056
1276
|
|
|
1057
1277
|
const resolution = action === "approve" ? "yes" : "no";
|
|
1058
|
-
const applied = this.resolve({
|
|
1278
|
+
const applied = this.resolve({
|
|
1279
|
+
resolution,
|
|
1280
|
+
by: "user",
|
|
1281
|
+
requestId,
|
|
1282
|
+
channel,
|
|
1283
|
+
...(options?.notifyUser === false && { notifyUser: false }),
|
|
1284
|
+
});
|
|
1059
1285
|
|
|
1060
1286
|
return applied
|
|
1061
1287
|
? { applied: true, resolution }
|
|
1062
1288
|
: { applied: false, resolution, reason: "stale or duplicate request ID" };
|
|
1063
1289
|
}
|
|
1064
1290
|
|
|
1291
|
+
/**
|
|
1292
|
+
* Close the question with a local decision of the harness.
|
|
1293
|
+
*
|
|
1294
|
+
* A local decision is not an answer of the human and not a decision of
|
|
1295
|
+
* the judge: nobody was asked and nobody answered. The question is closed
|
|
1296
|
+
* with the resolution and with the reason code of the local rule, and
|
|
1297
|
+
* neither callback is notified - the caller decides what the agent is
|
|
1298
|
+
* told.
|
|
1299
|
+
*
|
|
1300
|
+
* The guards of the other resolutions hold: a stale request ID, a
|
|
1301
|
+
* question that was answered already and a question that was closed are
|
|
1302
|
+
* refused.
|
|
1303
|
+
*
|
|
1304
|
+
* @returns true when the question was closed, false when it was stale.
|
|
1305
|
+
*/
|
|
1306
|
+
resolveLocally(
|
|
1307
|
+
requestId: string,
|
|
1308
|
+
resolution: "no",
|
|
1309
|
+
reason: string,
|
|
1310
|
+
): boolean {
|
|
1311
|
+
if (!this.currentQuestion) {
|
|
1312
|
+
logWarn("[PendingQuestion]", "No question to close - no pending question");
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
if (this.currentQuestion.requestId !== requestId) {
|
|
1317
|
+
logWarn("[PendingQuestion]",
|
|
1318
|
+
`Local decision for an unknown request: ${requestId} (current=${this.currentQuestion.requestId})`);
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
if (this.currentQuestion.state === "resolved") {
|
|
1323
|
+
logWarn("[PendingQuestion]",
|
|
1324
|
+
`Question already resolved as ${this.currentQuestion.resolution} - local decision ignored`);
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
if (
|
|
1329
|
+
this.currentQuestion.state === "expired" ||
|
|
1330
|
+
this.currentQuestion.state === "cancelled"
|
|
1331
|
+
) {
|
|
1332
|
+
logWarn("[PendingQuestion]",
|
|
1333
|
+
`Question is ${this.currentQuestion.state} - local decision ignored`);
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
this.currentQuestion.state = "resolved";
|
|
1338
|
+
this.currentQuestion.resolution = resolution;
|
|
1339
|
+
this.currentQuestion.localDecision = resolution;
|
|
1340
|
+
this.currentQuestion.closedReason = reason;
|
|
1341
|
+
this.currentQuestion.resolvedAt = new Date();
|
|
1342
|
+
|
|
1343
|
+
logWarn("[PendingQuestion]",
|
|
1344
|
+
`Closed question ${this.currentQuestion.requestId} with the local decision ${resolution} (${reason})`);
|
|
1345
|
+
|
|
1346
|
+
return true;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1065
1349
|
/**
|
|
1066
1350
|
* Is the request ID still actionable?
|
|
1067
1351
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/two-phase-review",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.510",
|
|
4
4
|
"description": "pi-harness-runtime — two-phase implementation and review workflow (queue review signals, gate the phase, scope the diff)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|