pi-harness-runtime 1.1.493 → 1.1.494
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 +71 -0
- package/harness/jev-wait-eligibility.ts +249 -0
- package/index.ts +263 -63
- 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/wait-lifecycle.d.ts +22 -1
- package/packages/jev-judge/dist/wait-lifecycle.d.ts.map +1 -1
- package/packages/jev-judge/dist/wait-lifecycle.js +28 -0
- package/packages/jev-judge/dist/wait-lifecycle.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/wait-lifecycle.ts +49 -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/pending-question.d.ts +9 -0
- package/packages/notification/dist/pending-question.d.ts.map +1 -1
- package/packages/notification/dist/pending-question.js +1 -0
- package/packages/notification/dist/pending-question.js.map +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/notification/src/pending-question.ts +10 -0
- 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
package/index.ts
CHANGED
|
@@ -39,6 +39,15 @@ import {
|
|
|
39
39
|
mayContinue,
|
|
40
40
|
userReplyEffect,
|
|
41
41
|
} from "./harness/pending-question-state.ts";
|
|
42
|
+
import {
|
|
43
|
+
clearObsoleteWait,
|
|
44
|
+
isObsoleteQuestion,
|
|
45
|
+
jevWaitEligibility,
|
|
46
|
+
questionRelevance,
|
|
47
|
+
workStateFromTodos,
|
|
48
|
+
type JevQuestionRelevance,
|
|
49
|
+
type JevWorkState,
|
|
50
|
+
} from "./harness/jev-wait-eligibility.ts";
|
|
42
51
|
import { describeInboundAccess, getAllowedUserIds } from "./harness/telegram-auth.ts";
|
|
43
52
|
import { buildTelegramCallbackUpdate, buildTelegramMessageUpdate } from "./harness/telegram-update.ts";
|
|
44
53
|
import { installConsoleGuard } from "./harness/console-guard.ts";
|
|
@@ -1245,6 +1254,7 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1245
1254
|
},
|
|
1246
1255
|
currentSessionId: () => _sessionId,
|
|
1247
1256
|
evaluate: (request, waitedMs) => evaluatePendingQuestion(request, waitedMs),
|
|
1257
|
+
eligibility: () => currentWaitEligibility(),
|
|
1248
1258
|
onState: (state, detail) => {
|
|
1249
1259
|
logToFile("[auto-continue]", `The wait is ${state}: ${detail.reason}`);
|
|
1250
1260
|
},
|
|
@@ -1277,6 +1287,98 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1277
1287
|
return isQuestionOpen(sharedState.pqController?.getCurrentQuestion?.());
|
|
1278
1288
|
}
|
|
1279
1289
|
|
|
1290
|
+
/**
|
|
1291
|
+
* The last state of the work that was read.
|
|
1292
|
+
*
|
|
1293
|
+
* The countdown asks synchronously, so it reads the state that is
|
|
1294
|
+
* known instead of waiting for a new one.
|
|
1295
|
+
*/
|
|
1296
|
+
let _lastWorkState: JevWorkState = "unknown";
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* The state of the work of the current request.
|
|
1300
|
+
*
|
|
1301
|
+
* The task list is the only source. A list that could not be read
|
|
1302
|
+
* says nothing: an unreadable list is never an empty list, and an
|
|
1303
|
+
* empty list is never a finished request.
|
|
1304
|
+
*/
|
|
1305
|
+
async function currentWorkState(): Promise<JevWorkState> {
|
|
1306
|
+
const controller = todoContinuationController;
|
|
1307
|
+
if (!controller) return "unknown";
|
|
1308
|
+
try {
|
|
1309
|
+
const snapshot = await controller.getSnapshot();
|
|
1310
|
+
return workStateFromTodos(snapshot.items, { available: true });
|
|
1311
|
+
} catch {
|
|
1312
|
+
return "unknown";
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* May the current question be decided automatically?
|
|
1318
|
+
*
|
|
1319
|
+
* One decision, shared by the creation of the wait, the
|
|
1320
|
+
* reconciliation with the finished work, the evaluation at the
|
|
1321
|
+
* deadline and the application of the result.
|
|
1322
|
+
*/
|
|
1323
|
+
async function currentWaitEligibility(): Promise<{
|
|
1324
|
+
eligible: boolean;
|
|
1325
|
+
reason: string;
|
|
1326
|
+
}> {
|
|
1327
|
+
const question = sharedState.pqController?.getCurrentQuestion?.();
|
|
1328
|
+
if (!question) {
|
|
1329
|
+
return { eligible: false, reason: "there is no question" };
|
|
1330
|
+
}
|
|
1331
|
+
const relevance =
|
|
1332
|
+
(question.relevance as JevQuestionRelevance | undefined) ??
|
|
1333
|
+
"current-request";
|
|
1334
|
+
const work = await currentWorkState();
|
|
1335
|
+
_lastWorkState = work;
|
|
1336
|
+
return jevWaitEligibility({ relevance, work });
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Cancel a question whose work is done.
|
|
1341
|
+
*
|
|
1342
|
+
* The question was asked while the work of the request remained.
|
|
1343
|
+
* That work is done now, so the question is obsolete: it blocks
|
|
1344
|
+
* nothing, and it keeps no countdown.
|
|
1345
|
+
*
|
|
1346
|
+
* Only the Jev owner is touched. A countdown of another owner keeps
|
|
1347
|
+
* its deadline and its state.
|
|
1348
|
+
*/
|
|
1349
|
+
async function reconcileObsoleteQuestion(): Promise<void> {
|
|
1350
|
+
const question = sharedState.pqController?.getCurrentQuestion?.();
|
|
1351
|
+
if (!question || !isQuestionOpen(question)) return;
|
|
1352
|
+
const relevance =
|
|
1353
|
+
(question.relevance as JevQuestionRelevance | undefined) ??
|
|
1354
|
+
"current-request";
|
|
1355
|
+
const work = await currentWorkState();
|
|
1356
|
+
_lastWorkState = work;
|
|
1357
|
+
const obsolete = isObsoleteQuestion({ relevance, work });
|
|
1358
|
+
if (!obsolete.obsolete) return;
|
|
1359
|
+
logToFile(
|
|
1360
|
+
"[auto-continue]",
|
|
1361
|
+
"The work of the question is done - the question is obsolete:",
|
|
1362
|
+
question.requestId,
|
|
1363
|
+
);
|
|
1364
|
+
// The question is closed without an answer: nobody clicked
|
|
1365
|
+
// anything, so no answer is injected. Only the Jev owner is
|
|
1366
|
+
// touched: a countdown of another owner keeps its deadline.
|
|
1367
|
+
clearObsoleteWait({
|
|
1368
|
+
requestId: question.requestId,
|
|
1369
|
+
cancelQuestion: (reason) => {
|
|
1370
|
+
sharedState.pqController?.cancel(reason);
|
|
1371
|
+
},
|
|
1372
|
+
cancelWait: () => {
|
|
1373
|
+
waitLifecycle.cancel();
|
|
1374
|
+
},
|
|
1375
|
+
removeRow: (requestId) => {
|
|
1376
|
+
pendingActions.remove(jevDecisionActionId(requestId));
|
|
1377
|
+
},
|
|
1378
|
+
});
|
|
1379
|
+
updateAutoContinueStatus("IDLE");
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1280
1382
|
// A continuation was dispatched and its turn has not settled yet.
|
|
1281
1383
|
// The gate owns that state: the status stays "RUN" until the turn
|
|
1282
1384
|
// settles, and no timer may clear it in the meantime.
|
|
@@ -1466,6 +1568,14 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1466
1568
|
if (_countdownSessionId !== _piSessionId) return false;
|
|
1467
1569
|
const current = sharedState.pqController?.getCurrentQuestion?.();
|
|
1468
1570
|
if (!current) return false;
|
|
1571
|
+
// A wait that is no longer eligible draws no row: an
|
|
1572
|
+
// obsolete question must not keep a countdown on the screen.
|
|
1573
|
+
const relevance =
|
|
1574
|
+
(current.relevance as JevQuestionRelevance | undefined) ??
|
|
1575
|
+
"current-request";
|
|
1576
|
+
if (!jevWaitEligibility({ relevance, work: _lastWorkState }).eligible) {
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1469
1579
|
return (
|
|
1470
1580
|
current.requestId === requestId &&
|
|
1471
1581
|
(current.state === "pending" || current.state === "evaluating")
|
|
@@ -1767,6 +1877,31 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1767
1877
|
proposedAction,
|
|
1768
1878
|
questionAction,
|
|
1769
1879
|
});
|
|
1880
|
+
// The state of the work decides whether the question belongs
|
|
1881
|
+
// to the request. It is read before the wait starts, because
|
|
1882
|
+
// the wait is the thing that must not start for a question
|
|
1883
|
+
// that nobody may answer by silence.
|
|
1884
|
+
const workState = await currentWorkState();
|
|
1885
|
+
_lastWorkState = workState;
|
|
1886
|
+
const relevance = questionRelevance({
|
|
1887
|
+
text: result.questionText,
|
|
1888
|
+
work: workState,
|
|
1889
|
+
});
|
|
1890
|
+
const eligibility = jevWaitEligibility({
|
|
1891
|
+
relevance,
|
|
1892
|
+
work: workState,
|
|
1893
|
+
});
|
|
1894
|
+
if (!eligibility.eligible) {
|
|
1895
|
+
// The question is not answered by silence: it waits for
|
|
1896
|
+
// the user, and no countdown, no row and no notification
|
|
1897
|
+
// claim that the agent is waiting.
|
|
1898
|
+
logToFile(
|
|
1899
|
+
"[auto-continue]",
|
|
1900
|
+
"The question does not wait for an automatic decision:",
|
|
1901
|
+
eligibility.reason,
|
|
1902
|
+
);
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
1770
1905
|
const question = pqController.createQuestion({
|
|
1771
1906
|
text: result.questionText,
|
|
1772
1907
|
sessionId: _sessionId,
|
|
@@ -1775,6 +1910,7 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1775
1910
|
askType: result.askType,
|
|
1776
1911
|
alternatives: result.alternatives,
|
|
1777
1912
|
contextText: result.contextText,
|
|
1913
|
+
relevance,
|
|
1778
1914
|
risk: {
|
|
1779
1915
|
requiresExplicitAuthorization: riskFacts.requiresExplicitAuthorization,
|
|
1780
1916
|
destructive: riskFacts.destructive,
|
|
@@ -1805,6 +1941,7 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1805
1941
|
text: result.questionText,
|
|
1806
1942
|
contextText: result.contextText,
|
|
1807
1943
|
alternatives: result.alternatives,
|
|
1944
|
+
relevance,
|
|
1808
1945
|
});
|
|
1809
1946
|
|
|
1810
1947
|
// Get task context for additional info
|
|
@@ -2267,6 +2404,19 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2267
2404
|
);
|
|
2268
2405
|
return;
|
|
2269
2406
|
}
|
|
2407
|
+
// The decision is checked once more: the work of the question can
|
|
2408
|
+
// be done while the judge was thinking. A decision about an
|
|
2409
|
+
// obsolete question steers nothing, pauses nothing and resolves
|
|
2410
|
+
// nothing.
|
|
2411
|
+
const eligibility = await currentWaitEligibility();
|
|
2412
|
+
if (!eligibility.eligible) {
|
|
2413
|
+
logToFile(
|
|
2414
|
+
"[auto-continue]",
|
|
2415
|
+
"The question is no longer eligible - discarding the decision:",
|
|
2416
|
+
eligibility.reason,
|
|
2417
|
+
);
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2270
2420
|
const outcome = evaluation.outcome;
|
|
2271
2421
|
const requestId = evaluation.requestId;
|
|
2272
2422
|
const waitMinutes = waitLifecycle.waitedMinutes();
|
|
@@ -2438,6 +2588,12 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2438
2588
|
waitLifecycle.cancel();
|
|
2439
2589
|
updateAutoContinueStatus("IDLE");
|
|
2440
2590
|
}
|
|
2591
|
+
if (result.discardReason === "not-eligible") {
|
|
2592
|
+
// The question became obsolete while it waited: it is
|
|
2593
|
+
// closed without an answer and the work is idle.
|
|
2594
|
+
sharedState.pqController?.cancel("the question is obsolete");
|
|
2595
|
+
updateAutoContinueStatus("IDLE");
|
|
2596
|
+
}
|
|
2441
2597
|
return;
|
|
2442
2598
|
}
|
|
2443
2599
|
|
|
@@ -2728,6 +2884,11 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2728
2884
|
updateAutoContinueStatus("IDLE");
|
|
2729
2885
|
}
|
|
2730
2886
|
|
|
2887
|
+
// A question whose work is done is obsolete. It must not block
|
|
2888
|
+
// the completion of the request, and the code that discovers it
|
|
2889
|
+
// is stale must run before the open question stops the handler.
|
|
2890
|
+
await reconcileObsoleteQuestion();
|
|
2891
|
+
|
|
2731
2892
|
// Don't continue if user is waiting for response, and do not
|
|
2732
2893
|
// continue behind a question that is still open: the work waits
|
|
2733
2894
|
// for the answer, also when the wait itself is over.
|
|
@@ -5971,6 +6132,93 @@ export default async function (pi: ExtensionAPI) {
|
|
|
5971
6132
|
}
|
|
5972
6133
|
}
|
|
5973
6134
|
|
|
6135
|
+
/**
|
|
6136
|
+
* The settle timer of a plan message.
|
|
6137
|
+
*
|
|
6138
|
+
* A review has no file to watch, so only a plan starts the
|
|
6139
|
+
* timer. The candidate of the plan is remembered, so the settle
|
|
6140
|
+
* timer can find the message again.
|
|
6141
|
+
*/
|
|
6142
|
+
const startPlanSettleTimer = (msg: {
|
|
6143
|
+
ordinal: number;
|
|
6144
|
+
text: string;
|
|
6145
|
+
}): void => {
|
|
6146
|
+
if (!codexSessionState.currentProjectRoot) return;
|
|
6147
|
+
const planPath = findPlanFile(codexSessionState.currentProjectRoot);
|
|
6148
|
+
if (!planPath) {
|
|
6149
|
+
// No wiki/plan.md found yet - wait for file to appear
|
|
6150
|
+
logToFile(
|
|
6151
|
+
"[codex-trigger]",
|
|
6152
|
+
"Plan message but no wiki/plan.md yet, waiting...",
|
|
6153
|
+
);
|
|
6154
|
+
return;
|
|
6155
|
+
}
|
|
6156
|
+
// Track plan candidate
|
|
6157
|
+
codexSessionState.currentPlanCandidate = {
|
|
6158
|
+
ordinal: msg.ordinal,
|
|
6159
|
+
text: msg.text,
|
|
6160
|
+
timestamp: Date.now(),
|
|
6161
|
+
};
|
|
6162
|
+
logToFile("[codex-trigger]", "Plan message + wiki file detected:", planPath);
|
|
6163
|
+
startSettleTimer(planPath, msg.ordinal);
|
|
6164
|
+
};
|
|
6165
|
+
|
|
6166
|
+
/**
|
|
6167
|
+
* The alert of a plan or a review message.
|
|
6168
|
+
*
|
|
6169
|
+
* The buttons are the actions of the stage: a plan can be
|
|
6170
|
+
* coded, a review can be coded again. Both stages can be
|
|
6171
|
+
* closed.
|
|
6172
|
+
*/
|
|
6173
|
+
const notifyCodexStage = (
|
|
6174
|
+
msg: { ordinal: number; text: string },
|
|
6175
|
+
hasReviewMarker: boolean,
|
|
6176
|
+
sessionId: string,
|
|
6177
|
+
projectRoot: string,
|
|
6178
|
+
planPath: string | undefined,
|
|
6179
|
+
): void => {
|
|
6180
|
+
// Create tokens for each action
|
|
6181
|
+
const codeToken = _createPendingAction(sessionId, "code", projectRoot, "plan");
|
|
6182
|
+
const doneToken = _createPendingAction(sessionId, "done", projectRoot, "plan");
|
|
6183
|
+
|
|
6184
|
+
// Use event type based on stage
|
|
6185
|
+
if (hasReviewMarker) {
|
|
6186
|
+
// Review stage: buttons are Code again and Done
|
|
6187
|
+
const codeAgainToken = _createPendingAction(sessionId, "code_again", projectRoot, "review");
|
|
6188
|
+
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
6189
|
+
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexReviewDetected", {
|
|
6190
|
+
requirement: msg.text,
|
|
6191
|
+
taskTitle: sessionId,
|
|
6192
|
+
details: {
|
|
6193
|
+
ordinal: msg.ordinal,
|
|
6194
|
+
stage: "review",
|
|
6195
|
+
projectRoot,
|
|
6196
|
+
messageLength: msg.text.length,
|
|
6197
|
+
},
|
|
6198
|
+
}, [
|
|
6199
|
+
{ text: "Code again", action: PING_PONG_ACTIONS.CODE_AGAIN, targetId: codeAgainToken },
|
|
6200
|
+
{ text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
|
|
6201
|
+
]);
|
|
6202
|
+
return;
|
|
6203
|
+
}
|
|
6204
|
+
// Plan stage: buttons are Code and Done
|
|
6205
|
+
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
6206
|
+
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexPlanDetected", {
|
|
6207
|
+
requirement: msg.text, // Full text, no truncation
|
|
6208
|
+
taskTitle: sessionId,
|
|
6209
|
+
details: {
|
|
6210
|
+
ordinal: msg.ordinal,
|
|
6211
|
+
stage: "plan",
|
|
6212
|
+
projectRoot,
|
|
6213
|
+
planPath: planPath || undefined,
|
|
6214
|
+
messageLength: msg.text.length,
|
|
6215
|
+
},
|
|
6216
|
+
}, [
|
|
6217
|
+
{ text: "Code", action: PING_PONG_ACTIONS.CODE, targetId: codeToken },
|
|
6218
|
+
{ text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
|
|
6219
|
+
]);
|
|
6220
|
+
};
|
|
6221
|
+
|
|
5974
6222
|
const codexHandle = startWatcher({
|
|
5975
6223
|
pollIntervalMs: 5000,
|
|
5976
6224
|
maxIdlePolls: Infinity,
|
|
@@ -6047,7 +6295,7 @@ export default async function (pi: ExtensionAPI) {
|
|
|
6047
6295
|
}
|
|
6048
6296
|
},
|
|
6049
6297
|
onMessages: (msgs) => {
|
|
6050
|
-
|
|
6298
|
+
if (!codexSessionState.currentCodexSessionId) return;
|
|
6051
6299
|
|
|
6052
6300
|
for (const msg of msgs) {
|
|
6053
6301
|
lastActivityTime = Date.now();
|
|
@@ -6055,79 +6303,31 @@ export default async function (pi: ExtensionAPI) {
|
|
|
6055
6303
|
if (msg.role !== "assistant") continue;
|
|
6056
6304
|
|
|
6057
6305
|
const classification = classifyMessage(msg.text);
|
|
6058
|
-
|
|
6306
|
+
|
|
6059
6307
|
// Check for review markers in unknown messages
|
|
6060
6308
|
const hasReviewMarker = classification === "unknown" && detectReviewMarker(msg.text);
|
|
6061
6309
|
if (classification !== "plan" && classification !== "mixed" && !hasReviewMarker) continue;
|
|
6062
|
-
|
|
6310
|
+
|
|
6063
6311
|
// Determine stage (for future use in event metadata)
|
|
6064
6312
|
void classification; // used for classification only
|
|
6065
6313
|
|
|
6066
6314
|
// Only start settle timer for plans (not reviews)
|
|
6067
6315
|
// Reviews don't have a file to watch
|
|
6068
|
-
if (!hasReviewMarker
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
// Track plan candidate
|
|
6072
|
-
codexSessionState.currentPlanCandidate = { ordinal: msg.ordinal, text: msg.text, timestamp: Date.now() };
|
|
6073
|
-
logToFile("[codex-trigger]", "Plan message + wiki file detected:", planPath);
|
|
6074
|
-
startSettleTimer(planPath, msg.ordinal);
|
|
6075
|
-
} else {
|
|
6076
|
-
// No wiki/plan.md found yet - wait for file to appear
|
|
6077
|
-
logToFile("[codex-trigger]", "Plan message but no wiki/plan.md yet, waiting...");
|
|
6078
|
-
}
|
|
6079
|
-
}
|
|
6316
|
+
if (!hasReviewMarker) {
|
|
6317
|
+
startPlanSettleTimer(msg);
|
|
6318
|
+
}
|
|
6080
6319
|
|
|
6081
|
-
|
|
6082
|
-
|
|
6320
|
+
// Emit Telegram alert with full content (async, non-blocking)
|
|
6321
|
+
const planPath = codexSessionState.currentProjectRoot ? findPlanFile(codexSessionState.currentProjectRoot) : undefined;
|
|
6083
6322
|
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
// Create tokens for each action
|
|
6089
|
-
const codeToken = _createPendingAction(sessionId, "code", projectRoot, "plan");
|
|
6090
|
-
const doneToken = _createPendingAction(sessionId, "done", projectRoot, "plan");
|
|
6323
|
+
// Create pending actions for PING_PONG buttons
|
|
6324
|
+
const sessionId = codexSessionState.currentCodexSessionId || "unknown";
|
|
6325
|
+
const projectRoot = codexSessionState.currentProjectRoot || "";
|
|
6091
6326
|
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
6097
|
-
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexReviewDetected", {
|
|
6098
|
-
requirement: msg.text,
|
|
6099
|
-
taskTitle: sessionId,
|
|
6100
|
-
details: {
|
|
6101
|
-
ordinal: msg.ordinal,
|
|
6102
|
-
stage: "review",
|
|
6103
|
-
projectRoot,
|
|
6104
|
-
messageLength: msg.text.length,
|
|
6105
|
-
},
|
|
6106
|
-
}, [
|
|
6107
|
-
{ text: "Code again", action: PING_PONG_ACTIONS.CODE_AGAIN, targetId: codeAgainToken },
|
|
6108
|
-
{ text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
|
|
6109
|
-
]);
|
|
6110
|
-
} else {
|
|
6111
|
-
// Plan stage: buttons are Code and Done
|
|
6112
|
-
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
6113
|
-
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexPlanDetected", {
|
|
6114
|
-
requirement: msg.text, // Full text, no truncation
|
|
6115
|
-
taskTitle: sessionId,
|
|
6116
|
-
details: {
|
|
6117
|
-
ordinal: msg.ordinal,
|
|
6118
|
-
stage: "plan",
|
|
6119
|
-
projectRoot,
|
|
6120
|
-
planPath: planPath || undefined,
|
|
6121
|
-
messageLength: msg.text.length,
|
|
6122
|
-
},
|
|
6123
|
-
}, [
|
|
6124
|
-
{ text: "Code", action: PING_PONG_ACTIONS.CODE, targetId: codeToken },
|
|
6125
|
-
{ text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
|
|
6126
|
-
]);
|
|
6127
|
-
}
|
|
6128
|
-
}
|
|
6129
|
-
},
|
|
6130
|
-
});
|
|
6327
|
+
notifyCodexStage(msg, hasReviewMarker, sessionId, projectRoot, planPath);
|
|
6328
|
+
}
|
|
6329
|
+
},
|
|
6330
|
+
});
|
|
6131
6331
|
|
|
6132
6332
|
// Clean up when pi session ends
|
|
6133
6333
|
pi.on("session_shutdown", () => codexHandle.stop());
|
package/package.json
CHANGED
|
@@ -53,6 +53,13 @@ export interface WaitRequest {
|
|
|
53
53
|
contextText?: string;
|
|
54
54
|
/** The concrete alternatives of a choice question. */
|
|
55
55
|
alternatives?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* What the question is about.
|
|
58
|
+
*
|
|
59
|
+
* The relevance decides whether the wait may reach the judge at all: an
|
|
60
|
+
* offer of work that was not asked for is never decided by silence.
|
|
61
|
+
*/
|
|
62
|
+
relevance?: string;
|
|
56
63
|
}
|
|
57
64
|
/** The result of one evaluation. */
|
|
58
65
|
export interface WaitEvaluation {
|
|
@@ -136,11 +143,25 @@ export interface WaitLifecycleDeps {
|
|
|
136
143
|
evaluate: (request: WaitRequest, waitedMs: number) => Promise<WaitEvaluation>;
|
|
137
144
|
/** The state of the wait changed. */
|
|
138
145
|
onState?: (state: WaitLifecycleState, detail: WaitStateDetail) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Is the wait still eligible for an automatic decision?
|
|
148
|
+
*
|
|
149
|
+
* The owner of the wait answers: it knows the state of the work and the
|
|
150
|
+
* relevance of the question. The controller asks before it evaluates,
|
|
151
|
+
* so an obsolete wait never reaches the judge.
|
|
152
|
+
*/
|
|
153
|
+
eligibility?: () => Promise<{
|
|
154
|
+
eligible: boolean;
|
|
155
|
+
reason: string;
|
|
156
|
+
}> | {
|
|
157
|
+
eligible: boolean;
|
|
158
|
+
reason: string;
|
|
159
|
+
};
|
|
139
160
|
/** A failure of the controller itself. */
|
|
140
161
|
onError?: (error: unknown) => void;
|
|
141
162
|
}
|
|
142
163
|
/** Why an evaluation was not applied. */
|
|
143
|
-
export type WaitDiscardReason = "no-request" | "not-waiting" | "not-due" | "stale" | "other-session";
|
|
164
|
+
export type WaitDiscardReason = "no-request" | "not-waiting" | "not-due" | "not-eligible" | "stale" | "other-session";
|
|
144
165
|
/** What the controller did with an evaluation. */
|
|
145
166
|
export interface WaitLifecycleResult {
|
|
146
167
|
/** Did the evaluation change the state? */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait-lifecycle.d.ts","sourceRoot":"","sources":["../src/wait-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAC3B,MAAM,GACN,SAAS,GACT,YAAY,GACZ,SAAS,GACT,gBAAgB,GAChB,kBAAkB,CAAC;AAEtB,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC3B,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;I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AI,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAElD;IAED;;;;;;;;;;OAUG;IACH,cAAc,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAIlD;IAED,qDAAqD;IACrD,SAAS,IAAI,MAAM,CAGlB;IAED;;;;;OAKG;IACH,aAAa,IAAI,MAAM,CAEtB;IAED,+CAA+C;IAC/C,KAAK,IAAI,OAAO,CAEf;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAUhC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAG9B;IAED;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAG/B;IAED,uCAAuC;IACvC,MAAM,IAAI,IAAI,CAEb;IAED;;;;;;;OAOG;IACG,WAAW,IAAI,OAAO,CAAC,mBAAmB,CAAC,CA0JhD;IAED,uEAAuE;IACvE,OAAO,CAAC,GAAG;IAWX,6BAA6B;IAC7B,OAAO,CAAC,QAAQ;IAkBhB,wEAAwE;IACxE,OAAO,CAAC,MAAM;CAOd"}
|
|
@@ -196,7 +196,35 @@ export class WaitLifecycleController {
|
|
|
196
196
|
discardReason: "other-session",
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
+
// The identity of the request is captured before anything can
|
|
200
|
+
// await: a result of an older generation belongs to a request that
|
|
201
|
+
// is gone, and it must be discarded even when the request was
|
|
202
|
+
// answered while the runtime was still preparing the evaluation.
|
|
199
203
|
const generation = this.generation;
|
|
204
|
+
// The wait is checked once more before the judge is asked: the work
|
|
205
|
+
// of the question can be done while it waited, and an obsolete wait
|
|
206
|
+
// must not decide anything. The wait ends here, so the timer, the
|
|
207
|
+
// state and the in-flight evaluation of that request end with it.
|
|
208
|
+
const eligibility = await this.deps.eligibility?.();
|
|
209
|
+
if (eligibility && !eligibility.eligible) {
|
|
210
|
+
this.end("idle", eligibility.reason);
|
|
211
|
+
return {
|
|
212
|
+
applied: false,
|
|
213
|
+
state: "idle",
|
|
214
|
+
reason: eligibility.reason,
|
|
215
|
+
discardReason: "not-eligible",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// The question may have been answered or replaced while the
|
|
219
|
+
// eligibility was read.
|
|
220
|
+
if (generation !== this.generation || this.request?.requestId !== request.requestId) {
|
|
221
|
+
return {
|
|
222
|
+
applied: false,
|
|
223
|
+
state: this.state,
|
|
224
|
+
reason: "the evaluation is stale",
|
|
225
|
+
discardReason: "stale",
|
|
226
|
+
};
|
|
227
|
+
}
|
|
200
228
|
this.setState("evaluating", "the decision of the question is running");
|
|
201
229
|
let evaluation;
|
|
202
230
|
try {
|