@encoredigitalgroup/opencode 0.2.12 → 0.2.14
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/README.md +6 -4
- package/dist/config/ConfigTypes.d.ts +2 -0
- package/dist/lib/PlanningConfigRpc.d.ts +1 -0
- package/dist/server/index.js +65 -14
- package/dist/tui/index.js +78 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@encoredigitalgroup/opencode` adds file pickers for OpenCode planning commands, a todo tracker, and quota reporting for Anthropic, OpenAI, and xAI (Grok).
|
|
4
4
|
|
|
5
5
|
The TUI provides `/plan-review`, `/plan-resync`, `/plan-split`, and `/plan-execute` commands. Each command opens a picker for plans in `docs/_planning` and
|
|
6
|
-
|
|
6
|
+
submits the selection with the matching installed skill. By default, the selection starts an OpenCode goal.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -32,8 +32,9 @@ The plugin resolves the mapped skills through OpenCode, so those skills can live
|
|
|
32
32
|
## Configuration
|
|
33
33
|
|
|
34
34
|
Set `planDirectory` and `skillMappings` in the object's `options` field. `planDirectory` is a non-empty path relative to the workspace. `skillMappings` can override
|
|
35
|
-
any supported command's installed skill name. `
|
|
36
|
-
use `docs/_planning` and the command's
|
|
35
|
+
any supported command's installed skill name. `goals` defaults to `true`; set it to `false` to submit picker selections as ordinary prompts instead of goals.
|
|
36
|
+
`enforceTodoTracker` defaults to `true`; set it to `false` to disable tracker-refresh enforcement. Unspecified values use `docs/_planning` and the command's
|
|
37
|
+
existing skill name.
|
|
37
38
|
|
|
38
39
|
```json
|
|
39
40
|
{
|
|
@@ -43,6 +44,7 @@ use `docs/_planning` and the command's existing skill name.
|
|
|
43
44
|
"package": "@encoredigitalgroup/opencode",
|
|
44
45
|
"options": {
|
|
45
46
|
"planDirectory": "plans",
|
|
47
|
+
"goals": false,
|
|
46
48
|
"enforceTodoTracker": false,
|
|
47
49
|
"skillMappings": {
|
|
48
50
|
"plan-review": "custom-plan-review",
|
|
@@ -55,7 +57,7 @@ use `docs/_planning` and the command's existing skill name.
|
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
Launching a picker from an existing session submits to that session. Launching one from the home screen creates and displays a new session before submitting the
|
|
58
|
-
selected plan.
|
|
60
|
+
selected plan. Starting a goal replaces any existing goal in that session. For `/plan-execute`, the goal points to the selected sub-plan directory.
|
|
59
61
|
|
|
60
62
|
## Todo tracker
|
|
61
63
|
|
|
@@ -3,6 +3,7 @@ export type SkillCommand = (typeof skillCommands)[number];
|
|
|
3
3
|
export type SkillMappings = Record<SkillCommand, string>;
|
|
4
4
|
export type PluginConfig = {
|
|
5
5
|
enforceTodoTracker: boolean;
|
|
6
|
+
goals: boolean;
|
|
6
7
|
planDirectory: string;
|
|
7
8
|
/** @deprecated Tool classifications no longer affect todo tracker enforcement. */
|
|
8
9
|
readOnlyTools: string[];
|
|
@@ -12,6 +13,7 @@ export type PluginConfig = {
|
|
|
12
13
|
};
|
|
13
14
|
export type UserPluginConfig = {
|
|
14
15
|
enforceTodoTracker?: boolean;
|
|
16
|
+
goals?: boolean;
|
|
15
17
|
planDirectory?: string;
|
|
16
18
|
/** @deprecated Tool classifications no longer affect todo tracker enforcement. */
|
|
17
19
|
readOnlyTools?: string[];
|
|
@@ -2,6 +2,7 @@ import type { Rpc } from "@opencode/plugin";
|
|
|
2
2
|
import type { SkillMappings } from "../config";
|
|
3
3
|
export declare const planningConfigRpcID = "encoredigitalgroup.opencode-planning";
|
|
4
4
|
export type PlanningConfigRpcOutput = {
|
|
5
|
+
goals: boolean;
|
|
5
6
|
planDirectory: string;
|
|
6
7
|
skillMappings: SkillMappings;
|
|
7
8
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -16,6 +16,7 @@ class ConfigDefaults {
|
|
|
16
16
|
static getDefaultConfig() {
|
|
17
17
|
return {
|
|
18
18
|
enforceTodoTracker: true,
|
|
19
|
+
goals: true,
|
|
19
20
|
planDirectory: "docs/_planning",
|
|
20
21
|
readOnlyTools: [],
|
|
21
22
|
skillMappings: this.getDefaultSkillMappings(),
|
|
@@ -45,6 +46,9 @@ class ConfigMerger {
|
|
|
45
46
|
if (userConfig.enforceTodoTracker !== undefined) {
|
|
46
47
|
config.enforceTodoTracker = userConfig.enforceTodoTracker;
|
|
47
48
|
}
|
|
49
|
+
if (userConfig.goals !== undefined) {
|
|
50
|
+
config.goals = userConfig.goals;
|
|
51
|
+
}
|
|
48
52
|
if (userConfig.planDirectory !== undefined) {
|
|
49
53
|
config.planDirectory = userConfig.planDirectory;
|
|
50
54
|
}
|
|
@@ -134,12 +138,14 @@ class ConfigLoader {
|
|
|
134
138
|
}
|
|
135
139
|
static getUserConfig(options) {
|
|
136
140
|
const enforceTodoTracker = this.booleanOption(options?.enforceTodoTracker);
|
|
141
|
+
const goals = this.booleanOption(options?.goals);
|
|
137
142
|
const planDirectory = this.planDirectoryOption(options?.planDirectory);
|
|
138
143
|
const readOnlyTools = this.toolNamesOption(options?.readOnlyTools);
|
|
139
144
|
const skillMappings = this.skillMappingsOption(options?.skillMappings);
|
|
140
145
|
const writeCapableTools = this.toolNamesOption(options?.writeCapableTools);
|
|
141
146
|
return {
|
|
142
147
|
...enforceTodoTracker === undefined ? {} : { enforceTodoTracker },
|
|
148
|
+
...goals === undefined ? {} : { goals },
|
|
143
149
|
...planDirectory === undefined ? {} : { planDirectory },
|
|
144
150
|
...readOnlyTools === undefined ? {} : { readOnlyTools },
|
|
145
151
|
...skillMappings === undefined ? {} : { skillMappings },
|
|
@@ -178,6 +184,9 @@ function checkConfigOutput(value) {
|
|
|
178
184
|
return "output must be an object";
|
|
179
185
|
}
|
|
180
186
|
const config = value;
|
|
187
|
+
if (typeof config.goals !== "boolean") {
|
|
188
|
+
return "output goals must be a boolean";
|
|
189
|
+
}
|
|
181
190
|
if (typeof config.planDirectory !== "string") {
|
|
182
191
|
return "output planDirectory must be a string";
|
|
183
192
|
}
|
|
@@ -229,8 +238,9 @@ var todoTrackerInput = {
|
|
|
229
238
|
};
|
|
230
239
|
var todoTrackerName = "todotracker";
|
|
231
240
|
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
|
|
241
|
+
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.";
|
|
242
|
+
var trackerRefreshConfirmation = "TodoTracker refreshed. The enforcement gate is clear; continue tool work.";
|
|
243
|
+
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
244
|
var compactionTrackerContract = `Retain this TodoTracker contract verbatim in the continuation summary:
|
|
235
245
|
|
|
236
246
|
${todoTrackerContract}`;
|
|
@@ -289,9 +299,9 @@ function todosFromToolResult(metadata, content) {
|
|
|
289
299
|
function isTerminalTodoList(todos) {
|
|
290
300
|
return todos.every((todo) => todo.status === "completed" || todo.status === "cancelled");
|
|
291
301
|
}
|
|
292
|
-
function stateFromTodoResult(metadata, content, refreshedAt = Date.now()) {
|
|
302
|
+
function stateFromTodoResult(metadata, content, refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
293
303
|
const parsed = parseTodoList(metadata, content);
|
|
294
|
-
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt);
|
|
304
|
+
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt, childCompletionRevision, acknowledgedChildCompletionRevision);
|
|
295
305
|
}
|
|
296
306
|
function todosFromMessages(messages) {
|
|
297
307
|
for (const message of messages.toReversed()) {
|
|
@@ -306,11 +316,17 @@ function todosFromMessages(messages) {
|
|
|
306
316
|
return [];
|
|
307
317
|
}
|
|
308
318
|
var trackerRefreshIntervalMs = 60000;
|
|
309
|
-
|
|
310
|
-
|
|
319
|
+
var rememberedChildCompletionEvents = 1024;
|
|
320
|
+
function refreshedTrackerState(refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
321
|
+
return {
|
|
322
|
+
kind: "tracked",
|
|
323
|
+
refreshedAt,
|
|
324
|
+
childCompletionRevision,
|
|
325
|
+
acknowledgedChildCompletionRevision
|
|
326
|
+
};
|
|
311
327
|
}
|
|
312
328
|
function trackerRefreshDue(state, now = Date.now()) {
|
|
313
|
-
return state.kind === "tracked" && (state.
|
|
329
|
+
return state.kind === "tracked" && (state.childCompletionRevision > state.acknowledgedChildCompletionRevision || now - state.refreshedAt >= trackerRefreshIntervalMs);
|
|
314
330
|
}
|
|
315
331
|
function requiresTrackerRefresh(state, tool, now = Date.now()) {
|
|
316
332
|
return tool !== todoTrackerName && trackerRefreshDue(state, now);
|
|
@@ -337,6 +353,9 @@ class TodoTrackerEnforcement {
|
|
|
337
353
|
context;
|
|
338
354
|
states = new Map;
|
|
339
355
|
instructedSessionIDs = new Set;
|
|
356
|
+
observedChildCompletionEventIDs = new Set;
|
|
357
|
+
observedChildCompletionEventOrder = [];
|
|
358
|
+
childCompletionRevision = 0;
|
|
340
359
|
constructor(context) {
|
|
341
360
|
this.context = context;
|
|
342
361
|
}
|
|
@@ -353,14 +372,35 @@ class TodoTrackerEnforcement {
|
|
|
353
372
|
this.states.set(sessionID, state);
|
|
354
373
|
return state;
|
|
355
374
|
}
|
|
356
|
-
async requireTrackerRefresh(sessionID,
|
|
375
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
357
376
|
const state = await this.stateFor(sessionID);
|
|
358
|
-
if (state.kind === "tracked"
|
|
359
|
-
state.
|
|
377
|
+
if (state.kind === "tracked") {
|
|
378
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
360
379
|
}
|
|
361
380
|
}
|
|
362
381
|
recordTrackerUpdate(sessionID, todos) {
|
|
363
|
-
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos)));
|
|
382
|
+
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos), Date.now(), this.childCompletionRevision));
|
|
383
|
+
}
|
|
384
|
+
recordTrackerResult(sessionID, metadata, content) {
|
|
385
|
+
const existing = this.states.get(sessionID);
|
|
386
|
+
const childCompletionRevision = existing?.kind === "tracked" ? existing.childCompletionRevision : 0;
|
|
387
|
+
const acknowledgedChildCompletionRevision = existing?.kind === "tracked" ? existing.acknowledgedChildCompletionRevision : this.childCompletionRevision;
|
|
388
|
+
this.states.set(sessionID, stateFromTodoResult(metadata, content, Date.now(), childCompletionRevision, acknowledgedChildCompletionRevision));
|
|
389
|
+
}
|
|
390
|
+
nextChildCompletionRevision(eventID) {
|
|
391
|
+
if (this.observedChildCompletionEventIDs.has(eventID)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.observedChildCompletionEventIDs.add(eventID);
|
|
395
|
+
this.observedChildCompletionEventOrder.push(eventID);
|
|
396
|
+
if (this.observedChildCompletionEventOrder.length > rememberedChildCompletionEvents) {
|
|
397
|
+
const oldestEventID = this.observedChildCompletionEventOrder.shift();
|
|
398
|
+
if (oldestEventID !== undefined) {
|
|
399
|
+
this.observedChildCompletionEventIDs.delete(oldestEventID);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
this.childCompletionRevision += 1;
|
|
403
|
+
return this.childCompletionRevision;
|
|
364
404
|
}
|
|
365
405
|
async register(enforceRefresh) {
|
|
366
406
|
let before;
|
|
@@ -393,7 +433,7 @@ class TodoTrackerEnforcement {
|
|
|
393
433
|
});
|
|
394
434
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
395
435
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
396
|
-
this.
|
|
436
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
397
437
|
}
|
|
398
438
|
});
|
|
399
439
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -426,9 +466,13 @@ class TodoTrackerEnforcement {
|
|
|
426
466
|
if (event.type !== "session.idle") {
|
|
427
467
|
continue;
|
|
428
468
|
}
|
|
469
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
470
|
+
if (childCompletionRevision === undefined) {
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
429
473
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
430
474
|
if (session.parentID !== undefined) {
|
|
431
|
-
await this.requireTrackerRefresh(session.parentID,
|
|
475
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
432
476
|
}
|
|
433
477
|
}
|
|
434
478
|
} catch (error) {
|
|
@@ -473,7 +517,13 @@ class TodoTracker {
|
|
|
473
517
|
throw new Error("Invalid todotracker input.");
|
|
474
518
|
}
|
|
475
519
|
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
476
|
-
return {
|
|
520
|
+
return {
|
|
521
|
+
content: [
|
|
522
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
523
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
524
|
+
],
|
|
525
|
+
metadata: { todos: input.todos }
|
|
526
|
+
};
|
|
477
527
|
}
|
|
478
528
|
});
|
|
479
529
|
});
|
|
@@ -9573,6 +9623,7 @@ var server_default = Plugin2.define({
|
|
|
9573
9623
|
try {
|
|
9574
9624
|
const configRegistration = await ctx.rpc.register(PlanningConfigRpc, {
|
|
9575
9625
|
get: async () => ({
|
|
9626
|
+
goals: pluginConfig.goals,
|
|
9576
9627
|
planDirectory: pluginConfig.planDirectory,
|
|
9577
9628
|
skillMappings: pluginConfig.skillMappings
|
|
9578
9629
|
})
|
package/dist/tui/index.js
CHANGED
|
@@ -644,6 +644,7 @@ class ConfigDefaults {
|
|
|
644
644
|
static getDefaultConfig() {
|
|
645
645
|
return {
|
|
646
646
|
enforceTodoTracker: true,
|
|
647
|
+
goals: true,
|
|
647
648
|
planDirectory: "docs/_planning",
|
|
648
649
|
readOnlyTools: [],
|
|
649
650
|
skillMappings: this.getDefaultSkillMappings(),
|
|
@@ -673,6 +674,9 @@ class ConfigMerger {
|
|
|
673
674
|
if (userConfig.enforceTodoTracker !== undefined) {
|
|
674
675
|
config.enforceTodoTracker = userConfig.enforceTodoTracker;
|
|
675
676
|
}
|
|
677
|
+
if (userConfig.goals !== undefined) {
|
|
678
|
+
config.goals = userConfig.goals;
|
|
679
|
+
}
|
|
676
680
|
if (userConfig.planDirectory !== undefined) {
|
|
677
681
|
config.planDirectory = userConfig.planDirectory;
|
|
678
682
|
}
|
|
@@ -762,12 +766,14 @@ class ConfigLoader {
|
|
|
762
766
|
}
|
|
763
767
|
static getUserConfig(options) {
|
|
764
768
|
const enforceTodoTracker = this.booleanOption(options?.enforceTodoTracker);
|
|
769
|
+
const goals = this.booleanOption(options?.goals);
|
|
765
770
|
const planDirectory = this.planDirectoryOption(options?.planDirectory);
|
|
766
771
|
const readOnlyTools = this.toolNamesOption(options?.readOnlyTools);
|
|
767
772
|
const skillMappings = this.skillMappingsOption(options?.skillMappings);
|
|
768
773
|
const writeCapableTools = this.toolNamesOption(options?.writeCapableTools);
|
|
769
774
|
return {
|
|
770
775
|
...enforceTodoTracker === undefined ? {} : { enforceTodoTracker },
|
|
776
|
+
...goals === undefined ? {} : { goals },
|
|
771
777
|
...planDirectory === undefined ? {} : { planDirectory },
|
|
772
778
|
...readOnlyTools === undefined ? {} : { readOnlyTools },
|
|
773
779
|
...skillMappings === undefined ? {} : { skillMappings },
|
|
@@ -894,7 +900,7 @@ class FilePickerCommands {
|
|
|
894
900
|
static toast(context, message) {
|
|
895
901
|
context.ui.toast.show({ message, variant: "error" });
|
|
896
902
|
}
|
|
897
|
-
static async submit(context, location, command, option) {
|
|
903
|
+
static async submit(context, location, command, option, goals) {
|
|
898
904
|
let skills;
|
|
899
905
|
try {
|
|
900
906
|
skills = context.data.location.skill.list(location);
|
|
@@ -946,12 +952,20 @@ class FilePickerCommands {
|
|
|
946
952
|
skills: [{ id: skill.id }]
|
|
947
953
|
};
|
|
948
954
|
try {
|
|
949
|
-
|
|
955
|
+
if (goals) {
|
|
956
|
+
await context.client.session.command({
|
|
957
|
+
...prompt,
|
|
958
|
+
name: "goal",
|
|
959
|
+
text: `@${skill.name} @${option.argument}`
|
|
960
|
+
});
|
|
961
|
+
} else {
|
|
962
|
+
await context.client.session.prompt(prompt);
|
|
963
|
+
}
|
|
950
964
|
} catch {
|
|
951
965
|
FilePickerCommands.toast(context, "Unable to submit the plan request.");
|
|
952
966
|
}
|
|
953
967
|
}
|
|
954
|
-
static async run(context, command) {
|
|
968
|
+
static async run(context, command, goals) {
|
|
955
969
|
const location = context.location ?? context.data.location.default();
|
|
956
970
|
const options = command.options(location.directory, command.excludesPlanningDirectory);
|
|
957
971
|
if (options.length === 0) {
|
|
@@ -965,7 +979,7 @@ class FilePickerCommands {
|
|
|
965
979
|
if (option === undefined) {
|
|
966
980
|
return;
|
|
967
981
|
}
|
|
968
|
-
await FilePickerCommands.submit(context, location, command, option);
|
|
982
|
+
await FilePickerCommands.submit(context, location, command, option, goals);
|
|
969
983
|
}
|
|
970
984
|
static register(context, config) {
|
|
971
985
|
for (const command of FilePickerCommands.getCommands(config)) {
|
|
@@ -980,7 +994,7 @@ class FilePickerCommands {
|
|
|
980
994
|
slash: {
|
|
981
995
|
name: command.command
|
|
982
996
|
},
|
|
983
|
-
run: () => FilePickerCommands.run(context, command)
|
|
997
|
+
run: () => FilePickerCommands.run(context, command, config.goals)
|
|
984
998
|
}]
|
|
985
999
|
}));
|
|
986
1000
|
}
|
|
@@ -1009,6 +1023,9 @@ function checkConfigOutput(value) {
|
|
|
1009
1023
|
return "output must be an object";
|
|
1010
1024
|
}
|
|
1011
1025
|
const config = value;
|
|
1026
|
+
if (typeof config.goals !== "boolean") {
|
|
1027
|
+
return "output goals must be a boolean";
|
|
1028
|
+
}
|
|
1012
1029
|
if (typeof config.planDirectory !== "string") {
|
|
1013
1030
|
return "output planDirectory must be a string";
|
|
1014
1031
|
}
|
|
@@ -6728,8 +6745,9 @@ var todoTrackerInput = {
|
|
|
6728
6745
|
};
|
|
6729
6746
|
var todoTrackerName = "todotracker";
|
|
6730
6747
|
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
|
|
6748
|
+
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.";
|
|
6749
|
+
var trackerRefreshConfirmation = "TodoTracker refreshed. The enforcement gate is clear; continue tool work.";
|
|
6750
|
+
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
6751
|
var compactionTrackerContract = `Retain this TodoTracker contract verbatim in the continuation summary:
|
|
6734
6752
|
|
|
6735
6753
|
${todoTrackerContract}`;
|
|
@@ -6788,9 +6806,9 @@ function todosFromToolResult(metadata, content) {
|
|
|
6788
6806
|
function isTerminalTodoList(todos) {
|
|
6789
6807
|
return todos.every((todo) => todo.status === "completed" || todo.status === "cancelled");
|
|
6790
6808
|
}
|
|
6791
|
-
function stateFromTodoResult(metadata, content, refreshedAt = Date.now()) {
|
|
6809
|
+
function stateFromTodoResult(metadata, content, refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
6792
6810
|
const parsed = parseTodoList(metadata, content);
|
|
6793
|
-
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt);
|
|
6811
|
+
return parsed.valid && isTerminalTodoList(parsed.todos) ? { kind: "untracked" } : refreshedTrackerState(refreshedAt, childCompletionRevision, acknowledgedChildCompletionRevision);
|
|
6794
6812
|
}
|
|
6795
6813
|
function todosFromMessages(messages) {
|
|
6796
6814
|
for (const message of messages.toReversed()) {
|
|
@@ -6805,11 +6823,17 @@ function todosFromMessages(messages) {
|
|
|
6805
6823
|
return [];
|
|
6806
6824
|
}
|
|
6807
6825
|
var trackerRefreshIntervalMs = 60000;
|
|
6808
|
-
|
|
6809
|
-
|
|
6826
|
+
var rememberedChildCompletionEvents = 1024;
|
|
6827
|
+
function refreshedTrackerState(refreshedAt = Date.now(), childCompletionRevision = 0, acknowledgedChildCompletionRevision = childCompletionRevision) {
|
|
6828
|
+
return {
|
|
6829
|
+
kind: "tracked",
|
|
6830
|
+
refreshedAt,
|
|
6831
|
+
childCompletionRevision,
|
|
6832
|
+
acknowledgedChildCompletionRevision
|
|
6833
|
+
};
|
|
6810
6834
|
}
|
|
6811
6835
|
function trackerRefreshDue(state, now = Date.now()) {
|
|
6812
|
-
return state.kind === "tracked" && (state.
|
|
6836
|
+
return state.kind === "tracked" && (state.childCompletionRevision > state.acknowledgedChildCompletionRevision || now - state.refreshedAt >= trackerRefreshIntervalMs);
|
|
6813
6837
|
}
|
|
6814
6838
|
function requiresTrackerRefresh(state, tool, now = Date.now()) {
|
|
6815
6839
|
return tool !== todoTrackerName && trackerRefreshDue(state, now);
|
|
@@ -6836,6 +6860,9 @@ class TodoTrackerEnforcement {
|
|
|
6836
6860
|
context;
|
|
6837
6861
|
states = new Map;
|
|
6838
6862
|
instructedSessionIDs = new Set;
|
|
6863
|
+
observedChildCompletionEventIDs = new Set;
|
|
6864
|
+
observedChildCompletionEventOrder = [];
|
|
6865
|
+
childCompletionRevision = 0;
|
|
6839
6866
|
constructor(context) {
|
|
6840
6867
|
this.context = context;
|
|
6841
6868
|
}
|
|
@@ -6852,14 +6879,35 @@ class TodoTrackerEnforcement {
|
|
|
6852
6879
|
this.states.set(sessionID, state);
|
|
6853
6880
|
return state;
|
|
6854
6881
|
}
|
|
6855
|
-
async requireTrackerRefresh(sessionID,
|
|
6882
|
+
async requireTrackerRefresh(sessionID, childCompletionRevision) {
|
|
6856
6883
|
const state = await this.stateFor(sessionID);
|
|
6857
|
-
if (state.kind === "tracked"
|
|
6858
|
-
state.
|
|
6884
|
+
if (state.kind === "tracked") {
|
|
6885
|
+
state.childCompletionRevision = Math.max(state.childCompletionRevision, childCompletionRevision);
|
|
6859
6886
|
}
|
|
6860
6887
|
}
|
|
6861
6888
|
recordTrackerUpdate(sessionID, todos) {
|
|
6862
|
-
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos)));
|
|
6889
|
+
this.states.set(sessionID, stateFromTodoResult({ todos }, JSON.stringify(todos), Date.now(), this.childCompletionRevision));
|
|
6890
|
+
}
|
|
6891
|
+
recordTrackerResult(sessionID, metadata, content) {
|
|
6892
|
+
const existing = this.states.get(sessionID);
|
|
6893
|
+
const childCompletionRevision = existing?.kind === "tracked" ? existing.childCompletionRevision : 0;
|
|
6894
|
+
const acknowledgedChildCompletionRevision = existing?.kind === "tracked" ? existing.acknowledgedChildCompletionRevision : this.childCompletionRevision;
|
|
6895
|
+
this.states.set(sessionID, stateFromTodoResult(metadata, content, Date.now(), childCompletionRevision, acknowledgedChildCompletionRevision));
|
|
6896
|
+
}
|
|
6897
|
+
nextChildCompletionRevision(eventID) {
|
|
6898
|
+
if (this.observedChildCompletionEventIDs.has(eventID)) {
|
|
6899
|
+
return;
|
|
6900
|
+
}
|
|
6901
|
+
this.observedChildCompletionEventIDs.add(eventID);
|
|
6902
|
+
this.observedChildCompletionEventOrder.push(eventID);
|
|
6903
|
+
if (this.observedChildCompletionEventOrder.length > rememberedChildCompletionEvents) {
|
|
6904
|
+
const oldestEventID = this.observedChildCompletionEventOrder.shift();
|
|
6905
|
+
if (oldestEventID !== undefined) {
|
|
6906
|
+
this.observedChildCompletionEventIDs.delete(oldestEventID);
|
|
6907
|
+
}
|
|
6908
|
+
}
|
|
6909
|
+
this.childCompletionRevision += 1;
|
|
6910
|
+
return this.childCompletionRevision;
|
|
6863
6911
|
}
|
|
6864
6912
|
async register(enforceRefresh) {
|
|
6865
6913
|
let before;
|
|
@@ -6892,7 +6940,7 @@ class TodoTrackerEnforcement {
|
|
|
6892
6940
|
});
|
|
6893
6941
|
after = await this.context.tool.hook("execute.after", async (event) => {
|
|
6894
6942
|
if (event.status === "completed" && event.tool === todoTrackerName) {
|
|
6895
|
-
this.
|
|
6943
|
+
this.recordTrackerResult(event.sessionID, event.result.metadata, event.result.content ?? []);
|
|
6896
6944
|
}
|
|
6897
6945
|
});
|
|
6898
6946
|
observer = this.observeSubagentCompletion(controller.signal);
|
|
@@ -6925,9 +6973,13 @@ class TodoTrackerEnforcement {
|
|
|
6925
6973
|
if (event.type !== "session.idle") {
|
|
6926
6974
|
continue;
|
|
6927
6975
|
}
|
|
6976
|
+
const childCompletionRevision = this.nextChildCompletionRevision(event.id);
|
|
6977
|
+
if (childCompletionRevision === undefined) {
|
|
6978
|
+
continue;
|
|
6979
|
+
}
|
|
6928
6980
|
const session = await this.context.session.get({ sessionID: event.data.sessionID });
|
|
6929
6981
|
if (session.parentID !== undefined) {
|
|
6930
|
-
await this.requireTrackerRefresh(session.parentID,
|
|
6982
|
+
await this.requireTrackerRefresh(session.parentID, childCompletionRevision);
|
|
6931
6983
|
}
|
|
6932
6984
|
}
|
|
6933
6985
|
} catch (error) {
|
|
@@ -6972,7 +7024,13 @@ class TodoTracker {
|
|
|
6972
7024
|
throw new Error("Invalid todotracker input.");
|
|
6973
7025
|
}
|
|
6974
7026
|
enforcement.recordTrackerUpdate(executionContext.sessionID, input.todos);
|
|
6975
|
-
return {
|
|
7027
|
+
return {
|
|
7028
|
+
content: [
|
|
7029
|
+
{ type: "text", text: JSON.stringify(input.todos) },
|
|
7030
|
+
{ type: "text", text: trackerRefreshConfirmation }
|
|
7031
|
+
],
|
|
7032
|
+
metadata: { todos: input.todos }
|
|
7033
|
+
};
|
|
6976
7034
|
}
|
|
6977
7035
|
});
|
|
6978
7036
|
});
|
|
@@ -7010,6 +7068,7 @@ async function loadPickerConfig(context) {
|
|
|
7010
7068
|
});
|
|
7011
7069
|
return {
|
|
7012
7070
|
...fallback,
|
|
7071
|
+
goals: config.goals,
|
|
7013
7072
|
planDirectory: config.planDirectory,
|
|
7014
7073
|
skillMappings: config.skillMappings
|
|
7015
7074
|
};
|