@encoredigitalgroup/opencode 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +55 -14
- package/dist/tui/index.js +55 -14
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -229,8 +229,9 @@ var todoTrackerInput = {
|
|
|
229
229
|
};
|
|
230
230
|
var todoTrackerName = "todotracker";
|
|
231
231
|
var todoTrackerDescription = "Replace the current session's complete ordered todo list. " + "Pass every remaining todo on each call; pass an empty array to clear the list.";
|
|
232
|
-
var trackerRefreshMessage = "Update todotracker with the complete current todo list, including newly discovered work and current statuses, before continuing tool work.";
|
|
233
|
-
var
|
|
232
|
+
var trackerRefreshMessage = "Update todotracker with the complete current todo list, including newly discovered work and current statuses, before continuing tool work. A successful update clears this gate.";
|
|
233
|
+
var trackerRefreshConfirmation = "TodoTracker refreshed. The enforcement gate is clear; continue tool work.";
|
|
234
|
+
var todoTrackerContract = "TodoTracker rules: Each call replaces the complete ordered todo list. Include discovered work and current statuses in every replacement. Mark a todo completed only after verifying its result. Mark a todo cancelled only when the user explicitly cancels that work. Never clear a list or change a status to avoid tracker updates, tool restrictions, or difficult work.";
|
|
234
235
|
var compactionTrackerContract = `Retain this TodoTracker contract verbatim in the continuation summary:
|
|
235
236
|
|
|
236
237
|
${todoTrackerContract}`;
|
|
@@ -289,9 +290,9 @@ function todosFromToolResult(metadata, content) {
|
|
|
289
290
|
function isTerminalTodoList(todos) {
|
|
290
291
|
return todos.every((todo) => todo.status === "completed" || todo.status === "cancelled");
|
|
291
292
|
}
|
|
292
|
-
function stateFromTodoResult(metadata, content, refreshedAt = Date.now()) {
|
|
293
|
+
function stateFromTodoResult(metadata, content, refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
293
294
|
const parsed = parseTodoList(metadata, content);
|
|
294
|
-
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt);
|
|
295
|
+
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt, childCompletionRevision, acknowledgedChildCompletionRevision);
|
|
295
296
|
}
|
|
296
297
|
function todosFromMessages(messages) {
|
|
297
298
|
for (const message of messages.toReversed()) {
|
|
@@ -306,11 +307,17 @@ function todosFromMessages(messages) {
|
|
|
306
307
|
return [];
|
|
307
308
|
}
|
|
308
309
|
var trackerRefreshIntervalMs = 60000;
|
|
309
|
-
|
|
310
|
-
|
|
310
|
+
var rememberedChildCompletionEvents = 1024;
|
|
311
|
+
function refreshedTrackerState(refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
312
|
+
return {
|
|
313
|
+
kind: "tracked",
|
|
314
|
+
refreshedAt,
|
|
315
|
+
childCompletionRevision,
|
|
316
|
+
acknowledgedChildCompletionRevision
|
|
317
|
+
};
|
|
311
318
|
}
|
|
312
319
|
function trackerRefreshDue(state, now = Date.now()) {
|
|
313
|
-
return state.kind === "tracked" && (state.
|
|
320
|
+
return state.kind === "tracked" && (state.childCompletionRevision > state.acknowledgedChildCompletionRevision || now - state.refreshedAt >= trackerRefreshIntervalMs);
|
|
314
321
|
}
|
|
315
322
|
function requiresTrackerRefresh(state, tool, now = Date.now()) {
|
|
316
323
|
return tool !== todoTrackerName && trackerRefreshDue(state, now);
|
|
@@ -337,6 +344,9 @@ class TodoTrackerEnforcement {
|
|
|
337
344
|
context;
|
|
338
345
|
states = new Map;
|
|
339
346
|
instructedSessionIDs = new Set;
|
|
347
|
+
observedChildCompletionEventIDs = new Set;
|
|
348
|
+
observedChildCompletionEventOrder = [];
|
|
349
|
+
childCompletionRevision = 0;
|
|
340
350
|
constructor(context) {
|
|
341
351
|
this.context = context;
|
|
342
352
|
}
|
|
@@ -353,14 +363,35 @@ class TodoTrackerEnforcement {
|
|
|
353
363
|
this.states.set(sessionID, state);
|
|
354
364
|
return state;
|
|
355
365
|
}
|
|
356
|
-
async requireTrackerRefresh(sessionID,
|
|
366
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
357
367
|
const state = await this.stateFor(sessionID);
|
|
358
|
-
if (state.kind === "tracked"
|
|
359
|
-
state.
|
|
368
|
+
if (state.kind === "tracked") {
|
|
369
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
360
370
|
}
|
|
361
371
|
}
|
|
362
372
|
recordTrackerUpdate(sessionID, todos) {
|
|
363
|
-
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos)));
|
|
373
|
+
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos), Date.now(), this.childCompletionRevision));
|
|
374
|
+
}
|
|
375
|
+
recordTrackerResult(sessionID, metadata, content) {
|
|
376
|
+
const existing = this.states.get(sessionID);
|
|
377
|
+
const childCompletionRevision = existing?.kind === "tracked" ? existing.childCompletionRevision : 0;
|
|
378
|
+
const acknowledgedChildCompletionRevision = existing?.kind === "tracked" ? existing.acknowledgedChildCompletionRevision : this.childCompletionRevision;
|
|
379
|
+
this.states.set(sessionID, stateFromTodoResult(metadata, content, Date.now(), childCompletionRevision, acknowledgedChildCompletionRevision));
|
|
380
|
+
}
|
|
381
|
+
nextChildCompletionRevision(eventID) {
|
|
382
|
+
if (this.observedChildCompletionEventIDs.has(eventID)) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
this.observedChildCompletionEventIDs.add(eventID);
|
|
386
|
+
this.observedChildCompletionEventOrder.push(eventID);
|
|
387
|
+
if (this.observedChildCompletionEventOrder.length > rememberedChildCompletionEvents) {
|
|
388
|
+
const oldestEventID = this.observedChildCompletionEventOrder.shift();
|
|
389
|
+
if (oldestEventID !== undefined) {
|
|
390
|
+
this.observedChildCompletionEventIDs.delete(oldestEventID);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
this.childCompletionRevision += 1;
|
|
394
|
+
return this.childCompletionRevision;
|
|
364
395
|
}
|
|
365
396
|
async register(enforceRefresh) {
|
|
366
397
|
let before;
|
|
@@ -393,7 +424,7 @@ class TodoTrackerEnforcement {
|
|
|
393
424
|
});
|
|
394
425
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
395
426
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
396
|
-
this.
|
|
427
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
397
428
|
}
|
|
398
429
|
});
|
|
399
430
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -426,9 +457,13 @@ class TodoTrackerEnforcement {
|
|
|
426
457
|
if (event.type !== "session.idle") {
|
|
427
458
|
continue;
|
|
428
459
|
}
|
|
460
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
461
|
+
if (childCompletionRevision === undefined) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
429
464
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
430
465
|
if (session.parentID !== undefined) {
|
|
431
|
-
await this.requireTrackerRefresh(session.parentID,
|
|
466
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
432
467
|
}
|
|
433
468
|
}
|
|
434
469
|
} catch (error) {
|
|
@@ -473,7 +508,13 @@ class TodoTracker {
|
|
|
473
508
|
throw new Error("Invalid todotracker input.");
|
|
474
509
|
}
|
|
475
510
|
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
476
|
-
return {
|
|
511
|
+
return {
|
|
512
|
+
content: [
|
|
513
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
514
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
515
|
+
],
|
|
516
|
+
metadata: { todos: input.todos }
|
|
517
|
+
};
|
|
477
518
|
}
|
|
478
519
|
});
|
|
479
520
|
});
|
package/dist/tui/index.js
CHANGED
|
@@ -6728,8 +6728,9 @@ var todoTrackerInput = {
|
|
|
6728
6728
|
};
|
|
6729
6729
|
var todoTrackerName = "todotracker";
|
|
6730
6730
|
var todoTrackerDescription = "Replace the current session's complete ordered todo list. " + "Pass every remaining todo on each call; pass an empty array to clear the list.";
|
|
6731
|
-
var trackerRefreshMessage = "Update todotracker with the complete current todo list, including newly discovered work and current statuses, before continuing tool work.";
|
|
6732
|
-
var
|
|
6731
|
+
var trackerRefreshMessage = "Update todotracker with the complete current todo list, including newly discovered work and current statuses, before continuing tool work. A successful update clears this gate.";
|
|
6732
|
+
var trackerRefreshConfirmation = "TodoTracker refreshed. The enforcement gate is clear; continue tool work.";
|
|
6733
|
+
var todoTrackerContract = "TodoTracker rules: Each call replaces the complete ordered todo list. Include discovered work and current statuses in every replacement. Mark a todo completed only after verifying its result. Mark a todo cancelled only when the user explicitly cancels that work. Never clear a list or change a status to avoid tracker updates, tool restrictions, or difficult work.";
|
|
6733
6734
|
var compactionTrackerContract = `Retain this TodoTracker contract verbatim in the continuation summary:
|
|
6734
6735
|
|
|
6735
6736
|
${todoTrackerContract}`;
|
|
@@ -6788,9 +6789,9 @@ function todosFromToolResult(metadata, content) {
|
|
|
6788
6789
|
function isTerminalTodoList(todos) {
|
|
6789
6790
|
return todos.every((todo) => todo.status === "completed" || todo.status === "cancelled");
|
|
6790
6791
|
}
|
|
6791
|
-
function stateFromTodoResult(metadata, content, refreshedAt = Date.now()) {
|
|
6792
|
+
function stateFromTodoResult(metadata, content, refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
6792
6793
|
const parsed = parseTodoList(metadata, content);
|
|
6793
|
-
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt);
|
|
6794
|
+
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt, childCompletionRevision, acknowledgedChildCompletionRevision);
|
|
6794
6795
|
}
|
|
6795
6796
|
function todosFromMessages(messages) {
|
|
6796
6797
|
for (const message of messages.toReversed()) {
|
|
@@ -6805,11 +6806,17 @@ function todosFromMessages(messages) {
|
|
|
6805
6806
|
return [];
|
|
6806
6807
|
}
|
|
6807
6808
|
var trackerRefreshIntervalMs = 60000;
|
|
6808
|
-
|
|
6809
|
-
|
|
6809
|
+
var rememberedChildCompletionEvents = 1024;
|
|
6810
|
+
function refreshedTrackerState(refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
6811
|
+
return {
|
|
6812
|
+
kind: "tracked",
|
|
6813
|
+
refreshedAt,
|
|
6814
|
+
childCompletionRevision,
|
|
6815
|
+
acknowledgedChildCompletionRevision
|
|
6816
|
+
};
|
|
6810
6817
|
}
|
|
6811
6818
|
function trackerRefreshDue(state, now = Date.now()) {
|
|
6812
|
-
return state.kind === "tracked" && (state.
|
|
6819
|
+
return state.kind === "tracked" && (state.childCompletionRevision > state.acknowledgedChildCompletionRevision || now - state.refreshedAt >= trackerRefreshIntervalMs);
|
|
6813
6820
|
}
|
|
6814
6821
|
function requiresTrackerRefresh(state, tool, now = Date.now()) {
|
|
6815
6822
|
return tool !== todoTrackerName && trackerRefreshDue(state, now);
|
|
@@ -6836,6 +6843,9 @@ class TodoTrackerEnforcement {
|
|
|
6836
6843
|
context;
|
|
6837
6844
|
states = new Map;
|
|
6838
6845
|
instructedSessionIDs = new Set;
|
|
6846
|
+
observedChildCompletionEventIDs = new Set;
|
|
6847
|
+
observedChildCompletionEventOrder = [];
|
|
6848
|
+
childCompletionRevision = 0;
|
|
6839
6849
|
constructor(context) {
|
|
6840
6850
|
this.context = context;
|
|
6841
6851
|
}
|
|
@@ -6852,14 +6862,35 @@ class TodoTrackerEnforcement {
|
|
|
6852
6862
|
this.states.set(sessionID, state);
|
|
6853
6863
|
return state;
|
|
6854
6864
|
}
|
|
6855
|
-
async requireTrackerRefresh(sessionID,
|
|
6865
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
6856
6866
|
const state = await this.stateFor(sessionID);
|
|
6857
|
-
if (state.kind === "tracked"
|
|
6858
|
-
state.
|
|
6867
|
+
if (state.kind === "tracked") {
|
|
6868
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
6859
6869
|
}
|
|
6860
6870
|
}
|
|
6861
6871
|
recordTrackerUpdate(sessionID, todos) {
|
|
6862
|
-
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos)));
|
|
6872
|
+
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos), Date.now(), this.childCompletionRevision));
|
|
6873
|
+
}
|
|
6874
|
+
recordTrackerResult(sessionID, metadata, content) {
|
|
6875
|
+
const existing = this.states.get(sessionID);
|
|
6876
|
+
const childCompletionRevision = existing?.kind === "tracked" ? existing.childCompletionRevision : 0;
|
|
6877
|
+
const acknowledgedChildCompletionRevision = existing?.kind === "tracked" ? existing.acknowledgedChildCompletionRevision : this.childCompletionRevision;
|
|
6878
|
+
this.states.set(sessionID, stateFromTodoResult(metadata, content, Date.now(), childCompletionRevision, acknowledgedChildCompletionRevision));
|
|
6879
|
+
}
|
|
6880
|
+
nextChildCompletionRevision(eventID) {
|
|
6881
|
+
if (this.observedChildCompletionEventIDs.has(eventID)) {
|
|
6882
|
+
return;
|
|
6883
|
+
}
|
|
6884
|
+
this.observedChildCompletionEventIDs.add(eventID);
|
|
6885
|
+
this.observedChildCompletionEventOrder.push(eventID);
|
|
6886
|
+
if (this.observedChildCompletionEventOrder.length > rememberedChildCompletionEvents) {
|
|
6887
|
+
const oldestEventID = this.observedChildCompletionEventOrder.shift();
|
|
6888
|
+
if (oldestEventID !== undefined) {
|
|
6889
|
+
this.observedChildCompletionEventIDs.delete(oldestEventID);
|
|
6890
|
+
}
|
|
6891
|
+
}
|
|
6892
|
+
this.childCompletionRevision += 1;
|
|
6893
|
+
return this.childCompletionRevision;
|
|
6863
6894
|
}
|
|
6864
6895
|
async register(enforceRefresh) {
|
|
6865
6896
|
let before;
|
|
@@ -6892,7 +6923,7 @@ class TodoTrackerEnforcement {
|
|
|
6892
6923
|
});
|
|
6893
6924
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
6894
6925
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
6895
|
-
this.
|
|
6926
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
6896
6927
|
}
|
|
6897
6928
|
});
|
|
6898
6929
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -6925,9 +6956,13 @@ class TodoTrackerEnforcement {
|
|
|
6925
6956
|
if (event.type !== "session.idle") {
|
|
6926
6957
|
continue;
|
|
6927
6958
|
}
|
|
6959
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
6960
|
+
if (childCompletionRevision === undefined) {
|
|
6961
|
+
continue;
|
|
6962
|
+
}
|
|
6928
6963
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
6929
6964
|
if (session.parentID !== undefined) {
|
|
6930
|
-
await this.requireTrackerRefresh(session.parentID,
|
|
6965
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
6931
6966
|
}
|
|
6932
6967
|
}
|
|
6933
6968
|
} catch (error) {
|
|
@@ -6972,7 +7007,13 @@ class TodoTracker {
|
|
|
6972
7007
|
throw new Error("Invalid todotracker input.");
|
|
6973
7008
|
}
|
|
6974
7009
|
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
6975
|
-
return {
|
|
7010
|
+
return {
|
|
7011
|
+
content: [
|
|
7012
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
7013
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
7014
|
+
],
|
|
7015
|
+
metadata: { todos: input.todos }
|
|
7016
|
+
};
|
|
6976
7017
|
}
|
|
6977
7018
|
});
|
|
6978
7019
|
});
|