@encoredigitalgroup/opencode 0.2.11 → 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 +65 -15
- package/dist/tui/index.js +65 -15
- package/package.json +5 -5
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
|
}
|
|
@@ -346,14 +356,42 @@ class TodoTrackerEnforcement {
|
|
|
346
356
|
return existing;
|
|
347
357
|
}
|
|
348
358
|
const state = trackerStateFromMessages(await this.context.session.context({ sessionID }));
|
|
359
|
+
const current = this.states.get(sessionID);
|
|
360
|
+
if (current !== undefined) {
|
|
361
|
+
return current;
|
|
362
|
+
}
|
|
349
363
|
this.states.set(sessionID, state);
|
|
350
364
|
return state;
|
|
351
365
|
}
|
|
352
|
-
async requireTrackerRefresh(sessionID) {
|
|
366
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
353
367
|
const state = await this.stateFor(sessionID);
|
|
354
368
|
if (state.kind === "tracked") {
|
|
355
|
-
state.
|
|
369
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
recordTrackerUpdate(sessionID, 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
|
+
}
|
|
356
392
|
}
|
|
393
|
+
this.childCompletionRevision += 1;
|
|
394
|
+
return this.childCompletionRevision;
|
|
357
395
|
}
|
|
358
396
|
async register(enforceRefresh) {
|
|
359
397
|
let before;
|
|
@@ -386,7 +424,7 @@ class TodoTrackerEnforcement {
|
|
|
386
424
|
});
|
|
387
425
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
388
426
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
389
|
-
this.
|
|
427
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
390
428
|
}
|
|
391
429
|
});
|
|
392
430
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -419,9 +457,13 @@ class TodoTrackerEnforcement {
|
|
|
419
457
|
if (event.type !== "session.idle") {
|
|
420
458
|
continue;
|
|
421
459
|
}
|
|
460
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
461
|
+
if (childCompletionRevision === undefined) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
422
464
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
423
465
|
if (session.parentID !== undefined) {
|
|
424
|
-
await this.requireTrackerRefresh(session.parentID);
|
|
466
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
425
467
|
}
|
|
426
468
|
}
|
|
427
469
|
} catch (error) {
|
|
@@ -454,26 +496,34 @@ class TodoTracker {
|
|
|
454
496
|
return [...todos.slice(0, -1), { ...finalTodo, status: "completed" }];
|
|
455
497
|
}
|
|
456
498
|
static async register(context, config) {
|
|
499
|
+
const enforcement = new TodoTrackerEnforcement(context);
|
|
457
500
|
const tool = await context.tool.transform((tools) => {
|
|
458
501
|
tools.add({
|
|
459
502
|
name: todoTrackerName,
|
|
460
503
|
description: todoTrackerDescription,
|
|
461
504
|
input: todoTrackerInput,
|
|
462
505
|
options: { codemode: false },
|
|
463
|
-
async execute(input) {
|
|
506
|
+
async execute(input, executionContext) {
|
|
464
507
|
if (!isTodoTrackerInput(input)) {
|
|
465
508
|
throw new Error("Invalid todotracker input.");
|
|
466
509
|
}
|
|
467
|
-
|
|
510
|
+
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
511
|
+
return {
|
|
512
|
+
content: [
|
|
513
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
514
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
515
|
+
],
|
|
516
|
+
metadata: { todos: input.todos }
|
|
517
|
+
};
|
|
468
518
|
}
|
|
469
519
|
});
|
|
470
520
|
});
|
|
471
521
|
try {
|
|
472
|
-
const
|
|
522
|
+
const registration = await enforcement.register(config.enforceTodoTracker);
|
|
473
523
|
return {
|
|
474
524
|
dispose: async () => {
|
|
475
525
|
try {
|
|
476
|
-
await
|
|
526
|
+
await registration.dispose();
|
|
477
527
|
} finally {
|
|
478
528
|
await tool.dispose();
|
|
479
529
|
}
|
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
|
}
|
|
@@ -6845,15 +6855,43 @@ class TodoTrackerEnforcement {
|
|
|
6845
6855
|
return existing;
|
|
6846
6856
|
}
|
|
6847
6857
|
const state = trackerStateFromMessages(await this.context.session.context({ sessionID }));
|
|
6858
|
+
const current = this.states.get(sessionID);
|
|
6859
|
+
if (current !== undefined) {
|
|
6860
|
+
return current;
|
|
6861
|
+
}
|
|
6848
6862
|
this.states.set(sessionID, state);
|
|
6849
6863
|
return state;
|
|
6850
6864
|
}
|
|
6851
|
-
async requireTrackerRefresh(sessionID) {
|
|
6865
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
6852
6866
|
const state = await this.stateFor(sessionID);
|
|
6853
6867
|
if (state.kind === "tracked") {
|
|
6854
|
-
state.
|
|
6868
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
6855
6869
|
}
|
|
6856
6870
|
}
|
|
6871
|
+
recordTrackerUpdate(sessionID, 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;
|
|
6894
|
+
}
|
|
6857
6895
|
async register(enforceRefresh) {
|
|
6858
6896
|
let before;
|
|
6859
6897
|
let after;
|
|
@@ -6885,7 +6923,7 @@ class TodoTrackerEnforcement {
|
|
|
6885
6923
|
});
|
|
6886
6924
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
6887
6925
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
6888
|
-
this.
|
|
6926
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
6889
6927
|
}
|
|
6890
6928
|
});
|
|
6891
6929
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -6918,9 +6956,13 @@ class TodoTrackerEnforcement {
|
|
|
6918
6956
|
if (event.type !== "session.idle") {
|
|
6919
6957
|
continue;
|
|
6920
6958
|
}
|
|
6959
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
6960
|
+
if (childCompletionRevision === undefined) {
|
|
6961
|
+
continue;
|
|
6962
|
+
}
|
|
6921
6963
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
6922
6964
|
if (session.parentID !== undefined) {
|
|
6923
|
-
await this.requireTrackerRefresh(session.parentID);
|
|
6965
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
6924
6966
|
}
|
|
6925
6967
|
}
|
|
6926
6968
|
} catch (error) {
|
|
@@ -6953,26 +6995,34 @@ class TodoTracker {
|
|
|
6953
6995
|
return [...todos.slice(0, -1), { ...finalTodo, status: "completed" }];
|
|
6954
6996
|
}
|
|
6955
6997
|
static async register(context, config) {
|
|
6998
|
+
const enforcement = new TodoTrackerEnforcement(context);
|
|
6956
6999
|
const tool = await context.tool.transform((tools) => {
|
|
6957
7000
|
tools.add({
|
|
6958
7001
|
name: todoTrackerName,
|
|
6959
7002
|
description: todoTrackerDescription,
|
|
6960
7003
|
input: todoTrackerInput,
|
|
6961
7004
|
options: { codemode: false },
|
|
6962
|
-
async execute(input) {
|
|
7005
|
+
async execute(input, executionContext) {
|
|
6963
7006
|
if (!isTodoTrackerInput(input)) {
|
|
6964
7007
|
throw new Error("Invalid todotracker input.");
|
|
6965
7008
|
}
|
|
6966
|
-
|
|
7009
|
+
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
7010
|
+
return {
|
|
7011
|
+
content: [
|
|
7012
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
7013
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
7014
|
+
],
|
|
7015
|
+
metadata: { todos: input.todos }
|
|
7016
|
+
};
|
|
6967
7017
|
}
|
|
6968
7018
|
});
|
|
6969
7019
|
});
|
|
6970
7020
|
try {
|
|
6971
|
-
const
|
|
7021
|
+
const registration = await enforcement.register(config.enforceTodoTracker);
|
|
6972
7022
|
return {
|
|
6973
7023
|
dispose: async () => {
|
|
6974
7024
|
try {
|
|
6975
|
-
await
|
|
7025
|
+
await registration.dispose();
|
|
6976
7026
|
} finally {
|
|
6977
7027
|
await tool.dispose();
|
|
6978
7028
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encoredigitalgroup/opencode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.13",
|
|
5
5
|
"description": "OpenCode planning pickers, a todo tracker, and a quota sidebar.",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"solid-js": "1.9.12"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@opencode/cli": "2.
|
|
26
|
-
"@opencode/client": "2.
|
|
27
|
-
"@opencode/plugin": "2.
|
|
25
|
+
"@opencode/cli": "2.3.0",
|
|
26
|
+
"@opencode/client": "2.3.0",
|
|
27
|
+
"@opencode/plugin": "2.3.0",
|
|
28
28
|
"@opentui/core": "0.5.14",
|
|
29
29
|
"@types/node": "^22.20.5",
|
|
30
30
|
"@types/bun": "1.4.0",
|
|
31
|
-
"tsfmt": "
|
|
31
|
+
"tsfmt": "0.3.0-beta15",
|
|
32
32
|
"typescript": "5.8.2"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|