@oisin-ee/pi-dogsled 0.27.0 → 0.28.1
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 +122 -28
- package/package.json +18 -7
- package/pi/index.ts +9 -4
- package/pi/plan-mode.ts +7 -7
- package/pi/todo/CHANGELOG.md +133 -0
- package/pi/todo/README.md +133 -0
- package/pi/todo/src/contract-fixture.ts +103 -0
- package/pi/todo/src/display.ts +78 -0
- package/pi/todo/src/embedded.ts +105 -0
- package/pi/todo/src/gate.ts +89 -0
- package/pi/todo/src/generated/todo_core.d.ts +573 -0
- package/pi/todo/src/generated/todo_core.js +970 -0
- package/pi/todo/src/generated/todo_core_bg.wasm +0 -0
- package/pi/todo/src/generated/todo_core_bg.wasm.d.ts +22 -0
- package/pi/todo/src/guidance.ts +16 -0
- package/pi/todo/src/handoff.ts +91 -0
- package/pi/todo/src/import-fixture.ts +63 -0
- package/pi/todo/src/index.ts +100 -0
- package/pi/todo/src/lease-fixture.ts +95 -0
- package/pi/todo/src/lifecycle.ts +105 -0
- package/pi/todo/src/plan-approved.ts +78 -0
- package/pi/todo/src/presentation.ts +70 -0
- package/pi/todo/src/provider-fixture.ts +50 -0
- package/pi/todo/src/provider.ts +289 -0
- package/pi/todo/src/registration-fixture.ts +126 -0
- package/pi/todo/src/reminder.ts +30 -0
- package/pi/todo/src/repository.ts +31 -0
- package/pi/todo/src/runtime-fixture.ts +255 -0
- package/pi/todo/src/schema.ts +99 -0
- package/pi/todo/src/source.ts +51 -0
- package/pi/todo/src/state.ts +105 -0
- package/pi/todo/src/tool.ts +60 -0
- package/pi/todo/src/wasm.ts +64 -0
- package/pi/todo/src/widget.ts +77 -0
- package/pi/todo/src/work.ts +180 -0
- package/pi/unit-bridge.ts +12 -10
- package/pi/unit-protocol.ts +2 -16
- package/pi/unit-worker.ts +7 -11
- package/pi/work-panel.ts +4 -4
- package/pi/work-todo.ts +30 -88
- package/plugins/dogsled/skills/dogsled/SKILL.md +1 -1
- package/plugins/dogsled/skills/dogsled/references/review.md +2 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @oisin-ee/pi-todo
|
|
2
|
+
|
|
3
|
+
A `todo` tool for [pi](https://pi.dev). The model keeps one ordered list of outcomes and bounded subtasks for the session. Multiple units can be active together.
|
|
4
|
+
The list rules run in Rust, compiled to WebAssembly.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pi install npm:@oisin-ee/pi-todo
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
To install it with the other packages, use [`@oisin-ee/oisinpi`](https://www.npmjs.com/package/@oisin-ee/oisinpi).
|
|
11
|
+
|
|
12
|
+
## The tool
|
|
13
|
+
|
|
14
|
+
The model calls `todo` with one `op`. Tasks are addressed by their exact content.
|
|
15
|
+
|
|
16
|
+
| `op` | Effect |
|
|
17
|
+
| -------- | --------------------------------------------------------------- |
|
|
18
|
+
| `init` | Replaces the list with `items`. |
|
|
19
|
+
| `append` | Adds `items` to the end. |
|
|
20
|
+
| `start` | Explicitly activates `task` without demoting other active work. |
|
|
21
|
+
| `done` | Completes `task`. Without `task`, completes every open task. |
|
|
22
|
+
| `drop` | Abandons `task`. Without `task`, abandons every open task. |
|
|
23
|
+
| `view` | Returns the list. It does not change it. |
|
|
24
|
+
|
|
25
|
+
Creation and append leave tasks pending. Nothing starts automatically. This replaces the previous single-active, automatic-start behavior.
|
|
26
|
+
Use `start` to activate or reopen work explicitly. Starting a child also opens its parent. Starting a parent does not start its children.
|
|
27
|
+
|
|
28
|
+
Keep `content` a short headline: aim under 60 characters, imperative, no trailing detail. Put context, approach, or acceptance detail in the optional `description` (one or two sentences). Outcomes and subtask drafts accept `description`; a plain string item has none. A blank description counts as none. `update` with `description` sets it on an open task or subtask, and a blank value clears it. It never changes `content` or how a task is selected. `view` prints a description on the line under its headline; the Pi widget shows headlines only.
|
|
29
|
+
|
|
30
|
+
`items` accepts strings or outcomes with string subtasks:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"op": "init",
|
|
35
|
+
"items": [
|
|
36
|
+
{
|
|
37
|
+
"content": "Password reset",
|
|
38
|
+
"subtasks": ["Implement tokens and behavior tests", "Implement form and interaction tests"]
|
|
39
|
+
},
|
|
40
|
+
"Update documentation"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To target a child, supply its exact `task` content and its exact root `parent` content:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{ "op": "start", "parent": "Password reset", "task": "Implement tokens and behavior tests" }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To add children, use `append` with `parent` and string `items`. Only two levels are permitted.
|
|
52
|
+
Root names are unique. Child names are unique within their parent. Different parents can use the same child name.
|
|
53
|
+
Blank names, duplicate siblings, unknown targets, grandchildren, and malformed requests fail without saving a change.
|
|
54
|
+
|
|
55
|
+
Each executable unit fits one agent session, with one deliverable, clear scope, and an acceptance condition.
|
|
56
|
+
Split independent outcomes or work that needs another session. Combine trivial steps with their deliverable and tests.
|
|
57
|
+
Delegate independent units separately. The lead can execute one unit. Keep dependent units ordered.
|
|
58
|
+
Do not delegate an oversized parent as one assignment.
|
|
59
|
+
|
|
60
|
+
A parent stays open after its children close and shows **Ready for review**.
|
|
61
|
+
Complete the parent explicitly after integration review. Completing a parent with open children fails, including bulk completion.
|
|
62
|
+
Dropping a parent abandons open children but preserves completed and abandoned children.
|
|
63
|
+
Untargeted `done` and `drop` affect open work only. A parent without `task` is not a bulk-child selector.
|
|
64
|
+
Appending children to a closed parent reopens it as pending. An active parent stays active.
|
|
65
|
+
Outcome and subtask progress remain separate. Abandoned work never counts as completed.
|
|
66
|
+
|
|
67
|
+
## Activation gate
|
|
68
|
+
|
|
69
|
+
Shell, code, and mutation tools need one active local unit. Structured reads, workflow control, and `todo` calls stay available without one.
|
|
70
|
+
The gate checks the selected model at each call. The planner selections `tier/plan-claude` and `tier/plan-gpt` skip the activation check, so a planning session can read and inspect without a unit.
|
|
71
|
+
Every other selection needs an active unit, including a tier with another name and a physical model that only looks like a planner.
|
|
72
|
+
The exemption is a workflow prerequisite, not a permission. It does not grant write access, and other policies such as guardrails still apply.
|
|
73
|
+
An active unit stays required for the sessions that implement code.
|
|
74
|
+
|
|
75
|
+
## State
|
|
76
|
+
|
|
77
|
+
Each task change is saved as a `todo-state` entry on the session branch. A resumed session, a `/tree` move,
|
|
78
|
+
and calls made from inside codemode all see the list of the current branch.
|
|
79
|
+
Old flat snapshots retain their recorded statuses and read with empty subtasks.
|
|
80
|
+
|
|
81
|
+
## Widget
|
|
82
|
+
|
|
83
|
+
The widget shows only in-progress tasks by default. Active tasks use the theme accent and bold text.
|
|
84
|
+
Long task names wrap to the terminal width. An empty list has no widget.
|
|
85
|
+
|
|
86
|
+
Press **Alt+T** to expand Upcoming, Done, and Dropped sections beneath the active task. Press **Alt+T** again to collapse them.
|
|
87
|
+
`/todos` also toggles these sections. `/todos list` prints the full list.
|
|
88
|
+
|
|
89
|
+
Expansion stays open through task updates. Session changes and `/tree` navigation collapse it. Expansion does not change saved tasks.
|
|
90
|
+
When no task is active, a short status and the shortcut hint remain visible.
|
|
91
|
+
Outside the terminal UI, `/todos` prints the list instead.
|
|
92
|
+
|
|
93
|
+
## Shared work display
|
|
94
|
+
|
|
95
|
+
The merged Dogsled extension attaches its work widget directly to pi-todo.
|
|
96
|
+
Tasks remain on the current Pi session branch. Dogsled receives a typed, read-only presentation capability.
|
|
97
|
+
Pi-todo owns the renderer in both standalone and shared views. Dogsled hosts it above the editor without opening a popup.
|
|
98
|
+
Alt+J/K scrolls the hosted rows. Alt+I toggles their expansion. Ordinary editor keys remain unchanged.
|
|
99
|
+
`/todos` and Alt+T request the shared Todos view. `/todos list` still prints the full list.
|
|
100
|
+
When shared presentation ends, the standalone widget returns without changing task state.
|
|
101
|
+
|
|
102
|
+
The [display contract](https://github.com/oisin-ee/dogsled/blob/main/docs/pi-work.md) defines direct attachment, snapshots, claims, and release.
|
|
103
|
+
`display.sections` contains four typed status groups in order: `in_progress`, `pending`, `completed`, `abandoned`. Each group contains a count and its items.
|
|
104
|
+
Each item carries its text, optional description, review flag, contract summary, and subtasks with their optional descriptions.
|
|
105
|
+
The core owns this grouping. A presenter only draws it. Rendering failures restore standalone todos without changing saved tasks.
|
|
106
|
+
|
|
107
|
+
## Dogsled plans
|
|
108
|
+
|
|
109
|
+
After the user approves a plan, Dogsled plan mode (`/plan` and `submit_plan`) calls the todo approval handle directly.
|
|
110
|
+
Pi-todo continues the approved plan in the same session. No setting is needed.
|
|
111
|
+
|
|
112
|
+
After approval, the agent reads the current todo list and adds the remaining approved work before implementation.
|
|
113
|
+
It preserves unrelated tasks and completed progress. Free-form plans do not need a special checklist format.
|
|
114
|
+
The todo tool owns progress, persistence, reminders, and the shared work display.
|
|
115
|
+
A different working directory or another owner of the `todo` tool stops the handoff with an error.
|
|
116
|
+
|
|
117
|
+
## Reminder
|
|
118
|
+
|
|
119
|
+
When the agent stops with open tasks, pi-todo adds a visible reminder to the conversation and continues the turn.
|
|
120
|
+
The reminder names open children and parents that await integration review.
|
|
121
|
+
It sends at most 3 reminders per user message. After a reminder, it waits for the list to change before it sends
|
|
122
|
+
another. A new user message resets the count.
|
|
123
|
+
|
|
124
|
+
## Other todo tools
|
|
125
|
+
|
|
126
|
+
If another package already registers `todo`, pi-todo stays inactive and shows a warning that names that package.
|
|
127
|
+
|
|
128
|
+
## Source
|
|
129
|
+
|
|
130
|
+
The original flat operations and the reminder derive from
|
|
131
|
+
[oh-my-pi](https://github.com/can1357/oh-my-pi/tree/e7fe318/packages/coding-agent/src) (`tools/todo`,
|
|
132
|
+
`todo-tracker.ts`), MIT. Saving a custom entry on every change follows
|
|
133
|
+
[rpiv-todo](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo).
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { TodoParams, TodoSession } from "./tool.ts";
|
|
2
|
+
import { STATE_ENTRY } from "./state.ts";
|
|
3
|
+
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { TodoList } from "./wasm.ts";
|
|
5
|
+
import { runTodo } from "./tool.ts";
|
|
6
|
+
|
|
7
|
+
interface Fixture {
|
|
8
|
+
readonly entries: SessionEntry[];
|
|
9
|
+
readonly session: TodoSession;
|
|
10
|
+
readonly call: (params: TodoParams) => TodoList;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a branch-backed caller using the real tool and WASM core.
|
|
15
|
+
* @param {readonly unknown[]} snapshots Existing stored snapshots.
|
|
16
|
+
* @returns {Fixture} The tool caller and Pi append seam.
|
|
17
|
+
*/
|
|
18
|
+
const first = 0,
|
|
19
|
+
second = 1,
|
|
20
|
+
third = 2,
|
|
21
|
+
last = -1,
|
|
22
|
+
fixture = (snapshots: readonly unknown[] = []): Fixture => {
|
|
23
|
+
const entries = snapshots.map((data): SessionEntry => ({
|
|
24
|
+
customType: STATE_ENTRY,
|
|
25
|
+
data,
|
|
26
|
+
id: crypto.randomUUID(),
|
|
27
|
+
parentId: null,
|
|
28
|
+
timestamp: "2026-10-20T00:00:00Z",
|
|
29
|
+
type: "custom",
|
|
30
|
+
})),
|
|
31
|
+
session: TodoSession = {
|
|
32
|
+
append: (customType, data): void => {
|
|
33
|
+
entries.push({
|
|
34
|
+
customType,
|
|
35
|
+
data,
|
|
36
|
+
id: crypto.randomUUID(),
|
|
37
|
+
parentId: entries.at(last)?.id ?? null,
|
|
38
|
+
timestamp: "2026-10-20T00:00:00Z",
|
|
39
|
+
type: "custom",
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
branch: () => entries,
|
|
43
|
+
sessionId: "test-session",
|
|
44
|
+
};
|
|
45
|
+
return { call: (params) => runTodo(params, session).details, entries, session };
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* A complete self-assigned contract for deterministic behavior tests.
|
|
49
|
+
* @returns {NonNullable<TodoParams["contract"]>} Authored contract fields.
|
|
50
|
+
*/
|
|
51
|
+
contract = (): NonNullable<TodoParams["contract"]> => ({
|
|
52
|
+
acceptance: {
|
|
53
|
+
argv: ["moon", "run", "todo-core:test"],
|
|
54
|
+
cwd: ".",
|
|
55
|
+
expected: "passes",
|
|
56
|
+
kind: "command",
|
|
57
|
+
},
|
|
58
|
+
assignment: { kind: "self" },
|
|
59
|
+
deliverable: "Executable task contracts",
|
|
60
|
+
dependsOn: [],
|
|
61
|
+
scope: { generates: [], owns: ["src/"], reads: ["README.md"], repositoryId: "oisinpi" },
|
|
62
|
+
}),
|
|
63
|
+
/**
|
|
64
|
+
* Returns the runtime ID from the first root in a tool result.
|
|
65
|
+
* @param {TodoList} list Real tool result.
|
|
66
|
+
* @returns {string} Runtime ID.
|
|
67
|
+
*/
|
|
68
|
+
firstId = (list: TodoList): string => {
|
|
69
|
+
const id = list.tasks.at(first)?.unit?.reference.unitId;
|
|
70
|
+
if (id === undefined) {
|
|
71
|
+
throw new Error("Expected a runtime unit ID");
|
|
72
|
+
}
|
|
73
|
+
return id;
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Requires a root identity at a known fixture position.
|
|
77
|
+
* @param {TodoList} list Tool result.
|
|
78
|
+
* @param {number} index Root position.
|
|
79
|
+
* @returns {string} Runtime ID.
|
|
80
|
+
*/
|
|
81
|
+
rootId = (list: TodoList, index: number): string => {
|
|
82
|
+
const id = list.tasks.at(index)?.unit?.reference.unitId;
|
|
83
|
+
if (id === undefined) {
|
|
84
|
+
throw new Error("Expected root identity");
|
|
85
|
+
}
|
|
86
|
+
return id;
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Requires a child identity from the first outcome.
|
|
90
|
+
* @param {TodoList} list Tool result.
|
|
91
|
+
* @param {number} index Child position.
|
|
92
|
+
* @returns {string} Runtime ID.
|
|
93
|
+
*/
|
|
94
|
+
childId = (list: TodoList, index: number): string => {
|
|
95
|
+
const id = list.tasks.at(first)?.subtasks?.at(index)?.unit?.reference.unitId;
|
|
96
|
+
if (id === undefined) {
|
|
97
|
+
throw new Error("Expected child identity");
|
|
98
|
+
}
|
|
99
|
+
return id;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { childId, contract, first, firstId, fixture, last, rootId, second, third };
|
|
103
|
+
export type { Fixture };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { SectionChild, SectionItem, Subtask, TodoList, TodoSection } from "./wasm.ts";
|
|
2
|
+
import { sections, view } from "./wasm.ts";
|
|
3
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { TodoView } from "./embedded.ts";
|
|
5
|
+
|
|
6
|
+
/** Host-owned layout and rendering services for an inline todo view. */
|
|
7
|
+
interface ViewHost {
|
|
8
|
+
readonly theme: Readonly<Pick<Theme, "fg" | "bold">>;
|
|
9
|
+
readonly height: () => number;
|
|
10
|
+
readonly requestRender: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A provider-owned view. The host forwards updates without interpreting state. */
|
|
14
|
+
interface HostedView {
|
|
15
|
+
readonly render: (width: number) => string[];
|
|
16
|
+
readonly handleInput: (input: string) => void;
|
|
17
|
+
readonly invalidate: () => void;
|
|
18
|
+
readonly update: (state: unknown) => void;
|
|
19
|
+
readonly dispose: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Read-only core projections exposed to a presenter. */
|
|
23
|
+
interface DisplaySection extends Readonly<Omit<TodoSection, "items">> {
|
|
24
|
+
readonly items: readonly (Readonly<Omit<SectionItem, "children">> & {
|
|
25
|
+
readonly children: readonly Readonly<SectionChild>[];
|
|
26
|
+
})[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Transient presentation data, never persisted in a session entry. */
|
|
30
|
+
interface TodoDisplay {
|
|
31
|
+
readonly empty: boolean;
|
|
32
|
+
readonly summary: string;
|
|
33
|
+
readonly current: string;
|
|
34
|
+
readonly text: string;
|
|
35
|
+
/** Status groups owned by the core: in_progress, pending, completed, abandoned. */
|
|
36
|
+
readonly sections: readonly DisplaySection[];
|
|
37
|
+
readonly state: unknown;
|
|
38
|
+
readonly createView: (host: ViewHost) => HostedView;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const emptyCount = 0,
|
|
42
|
+
headerIndex = 0,
|
|
43
|
+
/**
|
|
44
|
+
* Projects the core's summary and supplies its reusable renderer.
|
|
45
|
+
* @param {TodoList} list The validated current branch snapshot.
|
|
46
|
+
* @returns {TodoDisplay} An in-process presentation capability.
|
|
47
|
+
*/
|
|
48
|
+
display = (list: TodoList): TodoDisplay => {
|
|
49
|
+
const text = view(list),
|
|
50
|
+
active = list.tasks.flatMap((task) => [
|
|
51
|
+
...(task.status === "in_progress" ? [task.content] : []),
|
|
52
|
+
...(task.subtasks ?? [])
|
|
53
|
+
.filter(
|
|
54
|
+
(child: Readonly<Pick<Subtask, "content" | "status">>) =>
|
|
55
|
+
child.status === "in_progress",
|
|
56
|
+
)
|
|
57
|
+
.map(
|
|
58
|
+
(child: Readonly<Pick<Subtask, "content" | "status">>) =>
|
|
59
|
+
`${task.content} → ${child.content}`,
|
|
60
|
+
),
|
|
61
|
+
]),
|
|
62
|
+
current =
|
|
63
|
+
active.length > emptyCount
|
|
64
|
+
? active.join("; ")
|
|
65
|
+
: (list.tasks.find((task) => task.status === "pending")?.content ?? "");
|
|
66
|
+
return {
|
|
67
|
+
createView: (host) => new TodoView(list, host),
|
|
68
|
+
current,
|
|
69
|
+
empty: list.tasks.length === emptyCount,
|
|
70
|
+
sections: sections(list),
|
|
71
|
+
state: list,
|
|
72
|
+
summary: text.split("\n").at(headerIndex) ?? "",
|
|
73
|
+
text,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { display };
|
|
78
|
+
export type { HostedView, TodoDisplay, ViewHost };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Key, ScrollView, matchesKey } from "@earendil-works/pi-tui";
|
|
2
|
+
import { parse, widget } from "./wasm.ts";
|
|
3
|
+
import type { TodoList } from "./wasm.ts";
|
|
4
|
+
import { TodoWidget } from "./widget.ts";
|
|
5
|
+
import type { ViewHost } from "./display.ts";
|
|
6
|
+
|
|
7
|
+
const minimumHeight = 1,
|
|
8
|
+
previousLine = -1,
|
|
9
|
+
nextLine = 1;
|
|
10
|
+
|
|
11
|
+
/** Inline viewport over the same renderer used by the standalone widget. */
|
|
12
|
+
class TodoView {
|
|
13
|
+
readonly #host: ViewHost;
|
|
14
|
+
#list: TodoList;
|
|
15
|
+
#expanded = true;
|
|
16
|
+
#disposed = false;
|
|
17
|
+
readonly #body: TodoWidget;
|
|
18
|
+
readonly #scroll: ScrollView;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an expansion-local view without event subscriptions or task writes.
|
|
22
|
+
* @param {TodoList} list Validated branch tasks.
|
|
23
|
+
* @param {ViewHost} host Host layout and rendering services.
|
|
24
|
+
*/
|
|
25
|
+
public constructor(list: TodoList, host: ViewHost) {
|
|
26
|
+
this.#host = host;
|
|
27
|
+
this.#list = list;
|
|
28
|
+
this.#body = this.#content();
|
|
29
|
+
this.#scroll = new ScrollView(this.#body, { overscroll: "contain", scrollbar: "hidden" });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates the shared widget content.
|
|
34
|
+
* @returns {TodoWidget} Theme-aware rows.
|
|
35
|
+
*/
|
|
36
|
+
#content(): TodoWidget {
|
|
37
|
+
const body = new TodoWidget(
|
|
38
|
+
widget(this.#list, this.#expanded) ?? [],
|
|
39
|
+
this.#expanded,
|
|
40
|
+
this.#host.theme,
|
|
41
|
+
);
|
|
42
|
+
body.setShortcut("Alt+I");
|
|
43
|
+
return body;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Applies a provider snapshot while preserving the viewport.
|
|
48
|
+
* @param {unknown} state The opaque state from the display capability.
|
|
49
|
+
*/
|
|
50
|
+
public update(state: unknown): void {
|
|
51
|
+
if (!this.#disposed) {
|
|
52
|
+
this.#list = parse(state);
|
|
53
|
+
this.#body.setRows(widget(this.#list, this.#expanded) ?? [], this.#expanded);
|
|
54
|
+
this.invalidate();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Renders a bounded, scrollable view with the active host theme.
|
|
60
|
+
* @param {number} width Available terminal columns.
|
|
61
|
+
* @returns {string[]} Visible terminal lines.
|
|
62
|
+
*/
|
|
63
|
+
public render(width: number): string[] {
|
|
64
|
+
if (this.#disposed) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const height = Math.max(minimumHeight, this.#host.height());
|
|
68
|
+
this.#scroll.updateLayout(this.#body.render(width).length, height, this.#host.requestRender);
|
|
69
|
+
return this.#scroll
|
|
70
|
+
.render(width)
|
|
71
|
+
.slice(this.#scroll.scrollTop, this.#scroll.scrollTop + height);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Handles only navigation forwarded by the inline host.
|
|
76
|
+
* @param {string} input A translated host shortcut.
|
|
77
|
+
*/
|
|
78
|
+
public handleInput(input: string): void {
|
|
79
|
+
if (this.#disposed) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (matchesKey(input, Key.enter)) {
|
|
83
|
+
this.#expanded = !this.#expanded;
|
|
84
|
+
this.#body.setRows(widget(this.#list, this.#expanded) ?? [], this.#expanded);
|
|
85
|
+
} else if (matchesKey(input, Key.up)) {
|
|
86
|
+
this.#scroll.scrollBy(previousLine);
|
|
87
|
+
} else if (matchesKey(input, Key.down)) {
|
|
88
|
+
this.#scroll.scrollBy(nextLine);
|
|
89
|
+
}
|
|
90
|
+
this.#host.requestRender();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Invalidates both native components after a theme or data change. */
|
|
94
|
+
public invalidate(): void {
|
|
95
|
+
this.#body.invalidate();
|
|
96
|
+
this.#scroll.invalidate();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Ends this view's lifetime without modifying task state. */
|
|
100
|
+
public dispose(): void {
|
|
101
|
+
this.#disposed = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { TodoView };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TaskProvider } from "./provider.ts";
|
|
3
|
+
import { ownsTodo } from "./lifecycle.ts";
|
|
4
|
+
|
|
5
|
+
/** Planning selections that skip the activation check, exact provider and model IDs. */
|
|
6
|
+
const planningSelections = new Set(["plan-claude", "plan-gpt"]),
|
|
7
|
+
/**
|
|
8
|
+
* Whether the selected model is a planning selection.
|
|
9
|
+
* @param {Readonly<object>} model Selected model, when the session has one.
|
|
10
|
+
* @returns {boolean} Whether the activation check does not apply.
|
|
11
|
+
*/
|
|
12
|
+
isPlanning = (model: { readonly provider?: string; readonly id?: string } | undefined): boolean =>
|
|
13
|
+
model?.provider === "tier" && planningSelections.has(model.id ?? ""),
|
|
14
|
+
/** Exact structured reads and workflow controls, never command-text inference. */
|
|
15
|
+
controls = new Set([
|
|
16
|
+
"ask",
|
|
17
|
+
"codemode",
|
|
18
|
+
"interview",
|
|
19
|
+
"todo",
|
|
20
|
+
"tool_search",
|
|
21
|
+
"read",
|
|
22
|
+
"ls",
|
|
23
|
+
"find",
|
|
24
|
+
"grep",
|
|
25
|
+
"hypa_read",
|
|
26
|
+
"hypa_ls",
|
|
27
|
+
"hypa_find",
|
|
28
|
+
"hypa_grep",
|
|
29
|
+
"web_search",
|
|
30
|
+
"web_fetch",
|
|
31
|
+
"lsp_diagnostics",
|
|
32
|
+
"ctx_search",
|
|
33
|
+
"ctx_stats",
|
|
34
|
+
"mcp__codebase_memory__search_graph",
|
|
35
|
+
"mcp__codebase_memory__get_code_snippet",
|
|
36
|
+
"mcp__codebase_memory__trace_path",
|
|
37
|
+
"mcp__codebase_memory__detect_changes",
|
|
38
|
+
"hindsight_search_knowledge_pages",
|
|
39
|
+
"hindsight_list_knowledge_pages",
|
|
40
|
+
"hindsight_read_knowledge_page",
|
|
41
|
+
"hindsight_reflect",
|
|
42
|
+
"hindsight_sync_status",
|
|
43
|
+
"hindsight_diagnose",
|
|
44
|
+
"hindsight_capture_initiative",
|
|
45
|
+
"mcp__dogsled__spawn",
|
|
46
|
+
"mcp__dogsled__send",
|
|
47
|
+
"mcp__dogsled__cancel",
|
|
48
|
+
"mcp__dogsled__close",
|
|
49
|
+
"mcp__dogsled__done",
|
|
50
|
+
"mcp__dogsled__stop",
|
|
51
|
+
"mcp__dogsled__read",
|
|
52
|
+
"mcp__dogsled__status",
|
|
53
|
+
"mcp__dogsled__inbox",
|
|
54
|
+
]),
|
|
55
|
+
/**
|
|
56
|
+
* Checks actual calls and leases execution-bearing calls.
|
|
57
|
+
* @param {Readonly<ExtensionAPI>} pi Runtime hooks and metadata.
|
|
58
|
+
* @param {Readonly<TaskProvider>} provider Task state and leases.
|
|
59
|
+
*/
|
|
60
|
+
registerGate = (
|
|
61
|
+
pi: Readonly<Pick<ExtensionAPI, "on" | "getAllTools">>,
|
|
62
|
+
provider: Readonly<TaskProvider>,
|
|
63
|
+
): void => {
|
|
64
|
+
pi.on("tool_call", (event: Readonly<{ toolName: string; toolCallId: string }>, ctx) => {
|
|
65
|
+
if (!ownsTodo(pi)) {
|
|
66
|
+
return { block: false };
|
|
67
|
+
}
|
|
68
|
+
provider.context(ctx);
|
|
69
|
+
if (controls.has(event.toolName) || isPlanning(ctx.model)) {
|
|
70
|
+
return { block: false };
|
|
71
|
+
}
|
|
72
|
+
const active = provider.capability().active();
|
|
73
|
+
if (!active.ok || active.value === null) {
|
|
74
|
+
return {
|
|
75
|
+
block: true,
|
|
76
|
+
reason: active.ok
|
|
77
|
+
? "Start a complete self-assigned leaf with todo before shell, code, mutation, or unknown tools."
|
|
78
|
+
: active.error.message,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
provider.lease(event.toolCallId, active.value.ref);
|
|
82
|
+
return { block: false };
|
|
83
|
+
});
|
|
84
|
+
pi.on("tool_execution_end", (event: Readonly<{ toolCallId: string }>) => {
|
|
85
|
+
provider.release(event.toolCallId);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { registerGate };
|