opencode-courier 0.11.1 → 0.13.0
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 +19 -14
- package/dist/index.js +19 -6
- package/dist/kernel/protocol.d.ts +2 -0
- package/dist/kernel/protocol.js +4 -0
- package/dist/memory/events.js +3 -1
- package/dist/memory/index.d.ts +2 -1
- package/dist/memory/index.js +2 -1
- package/dist/memory/lessons.d.ts +12 -0
- package/dist/memory/lessons.js +56 -0
- package/dist/memory/note.js +3 -0
- package/dist/memory/ports.d.ts +3 -1
- package/dist/memory/text.d.ts +11 -0
- package/dist/memory/text.js +22 -1
- package/dist/memory/tools.js +2 -1
- package/dist/person/events.js +4 -1
- package/dist/person/permission.d.ts +1 -1
- package/dist/person/permission.js +1 -1
- package/dist/person/question/answer.d.ts +1 -1
- package/dist/person/question/answer.js +1 -1
- package/dist/person/question/lifecycle.d.ts +1 -1
- package/dist/person/question/lifecycle.js +1 -1
- package/dist/person/question/relay.js +1 -1
- package/dist/platform/events.d.ts +10 -2
- package/dist/platform/events.js +38 -8
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +97 -45
- package/dist/tree/cleanup.js +2 -0
- package/dist/tree/context.d.ts +2 -2
- package/dist/tree/context.js +26 -10
- package/dist/tree/domain.d.ts +32 -2
- package/dist/tree/domain.js +28 -2
- package/dist/tree/events.js +21 -1
- package/dist/tree/group.js +3 -0
- package/dist/tree/index.d.ts +1 -1
- package/dist/tree/model.d.ts +18 -0
- package/dist/tree/model.js +65 -0
- package/dist/tree/panel.js +3 -2
- package/dist/tree/ports.d.ts +59 -13
- package/dist/tree/roster.d.ts +3 -11
- package/dist/tree/roster.js +4 -10
- package/dist/tree/rpc-handlers.d.ts +6 -0
- package/dist/tree/rpc.d.ts +16 -0
- package/dist/tree/rpc.js +4 -0
- package/dist/tree/send.js +46 -19
- package/dist/tree/spawn.d.ts +8 -0
- package/dist/tree/spawn.js +74 -21
- package/dist/tree/standing.d.ts +17 -0
- package/dist/tree/standing.js +90 -0
- package/dist/tree/status.d.ts +35 -19
- package/dist/tree/status.js +6 -6
- package/dist/tree/stop.js +3 -0
- package/dist/tree/store.js +4 -2
- package/dist/tree/subtree.d.ts +16 -8
- package/dist/tree/text.d.ts +48 -6
- package/dist/tree/text.js +113 -8
- package/dist/tree/tools.d.ts +3 -3
- package/dist/tree/tools.js +24 -20
- package/dist/tui.js +8 -0
- package/package.json +6 -6
package/dist/skill.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Plugin } from "@opencode/plugin";
|
|
|
3
3
|
export declare const SKILL_DESCRIPTION: string;
|
|
4
4
|
/**
|
|
5
5
|
* The skill's text; it names no limits, which the role part and the brief give for the session's own tree.
|
|
6
|
-
* Steps 3, 4 and 6 repeat the brief's split rule on purpose: the root has no brief, so only the skill gives it.
|
|
6
|
+
* Steps 1, 3, 4 and 6 repeat the brief's split rule on purpose: the root has no brief, so only the skill gives it.
|
|
7
7
|
*/
|
|
8
8
|
export declare const SKILL_CONTENT: string;
|
|
9
9
|
/** The editor OpenCode hands a skill transform. */
|
package/dist/skill.js
CHANGED
|
@@ -1,66 +1,118 @@
|
|
|
1
1
|
import { ONE_PART_LINE, SKILL_ID, SPLIT_LINE } from "./kernel/protocol.js";
|
|
2
2
|
// The courier-orchestrate skill: the playbook a session loads with its skill tool.
|
|
3
3
|
/** Why a model loads the skill, listed with every session's available skills. */
|
|
4
|
-
export const SKILL_DESCRIPTION = "Load at the start of any implementation task that may have independent parts, or when a session started you,
|
|
5
|
-
"decide whether to split it across OpenCode sessions
|
|
6
|
-
"
|
|
7
|
-
"when a part goes wrong.";
|
|
4
|
+
export const SKILL_DESCRIPTION = "Load at the start of any implementation task that may have independent parts, or when a session started you, if " +
|
|
5
|
+
"courier_spawn is among your tools: how to decide whether to split it across OpenCode sessions and state the decision, " +
|
|
6
|
+
"plan and start the parts, end your turn, verify and integrate the reports, report upward, and handle a part gone wrong.";
|
|
8
7
|
/**
|
|
9
8
|
* The skill's text; it names no limits, which the role part and the brief give for the session's own tree.
|
|
10
|
-
* Steps 3, 4 and 6 repeat the brief's split rule on purpose: the root has no brief, so only the skill gives it.
|
|
9
|
+
* Steps 1, 3, 4 and 6 repeat the brief's split rule on purpose: the root has no brief, so only the skill gives it.
|
|
11
10
|
*/
|
|
12
11
|
export const SKILL_CONTENT = [
|
|
13
12
|
"How to split a task across OpenCode sessions with opencode-courier, and bring the results back up. Your brief, or the " +
|
|
14
|
-
"opencode-courier role line in your system prompt, names your depth in the session tree and its limits."
|
|
13
|
+
"opencode-courier role line in your system prompt, names your depth in the session tree and its limits. If " +
|
|
14
|
+
"courier_spawn is not among your tools, you cannot split: do the task yourself, and report upward as your brief says " +
|
|
15
|
+
"if a session started you.",
|
|
15
16
|
"",
|
|
16
|
-
"1. Decide: split or do.
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
"1. Decide: split or do.",
|
|
18
|
+
" - At the root, first call courier_recall once, before you decide and never in a loop: it lists how earlier trees in " +
|
|
19
|
+
"this project were split and how each part went. Below the root, read none: the records describe whole trees, which " +
|
|
20
|
+
"the root weighed before it split.",
|
|
21
|
+
" - Split when the task has 2 or more independent, substantial parts touching separate files or areas; do it yourself " +
|
|
22
|
+
"when it is small, sequential or tightly coupled. Several whole jobs in one prompt, such as 4 tickets, are that many " +
|
|
23
|
+
"parts: each session runs " +
|
|
24
|
+
"this playbook for its job, stages, review and all, so the tree below you repeats its shape once per job.",
|
|
25
|
+
" - What you read and write yourself stays in your context for every later turn: keep the deciding, checking and " +
|
|
26
|
+
"integrating, and hand off the long reading and writing.",
|
|
27
|
+
" - Only the root, the session nobody started, may start exactly one session for the whole task, and only when the " +
|
|
28
|
+
"task is heavy (long reading, many edits, long runs) and its own context is worth keeping; it still verifies and " +
|
|
29
|
+
"integrates that session's report itself (steps 5 to 7). Every other session never starts exactly one session for " +
|
|
30
|
+
"the whole task: it only adds a hop, and a chain of single hops uses up the tree's depth.",
|
|
31
|
+
` - Say which in one line of your reply, before you start: ${SPLIT_LINE}; the root has a third form, ${ONE_PART_LINE}.`,
|
|
32
|
+
" Parts a task can have, besides its edits, each one session where it is worth a context of its own:",
|
|
33
|
+
" - a scout: a session with isolate: false reads the code, or a library's or a host's source, tries things and " +
|
|
34
|
+
"reports what it found, before you plan;",
|
|
35
|
+
" - the implementers, isolate: true where two edit at once, each with its checks and what to report;",
|
|
36
|
+
" - its e2e scenario, its documentation, sometimes a second test file;",
|
|
37
|
+
" - a review stage, after the merge, to see the whole: one review session with fresh context, which makes no fixes " +
|
|
38
|
+
"of its own. Put in its task the diff to read: your checkout's HEAD, with the " +
|
|
39
|
+
"merges committed, against the commit you started from, which you note before your first spawn; when you are " +
|
|
40
|
+
"isolated, your own courier/<session> branch, committed first, against the commit your worktree started from. It " +
|
|
41
|
+
"may hand the reading to 2 or more reviewers (one group, each reads the diff from one angle and reports its " +
|
|
42
|
+
"findings), then starts one verifier with their reports: a fresh session that checks each finding against the diff, " +
|
|
43
|
+
"drops what does not hold, and starts one implementor for what holds, or 2 or more with isolate: true when the fixes " +
|
|
44
|
+
"are independent, merging their branches after (step 7); an implementor fixes what it should and refuses, with the " +
|
|
45
|
+
"reason, what it should not. In the project's checkout, the review session, the verifier and a lone implementor go " +
|
|
46
|
+
"without isolate and commit in place; when you are isolated, start each of them with isolate: true, so that each " +
|
|
47
|
+
"worktree starts from the one above; reviewers only read and need no worktree. The review session reports to you " +
|
|
48
|
+
"what was found, what held, what was fixed (the commits) and what was refused and why. It does not replace step 6: " +
|
|
49
|
+
"running the checks on the fixed tree stays yours, and so does settling a refusal you disagree with. Go through " +
|
|
50
|
+
"steps 3 to 7 once more for the stage, and do its work yourself when the levels below you are too few for it. One " +
|
|
51
|
+
"session for one stage, after a stage of 2 or more parts or one you did yourself, is a part of the task, not the " +
|
|
52
|
+
"whole; a reviewer alone with nothing before it is not a stage.",
|
|
53
|
+
" When the core is coupled: a task with one tightly coupled core usually still has parts from that list; weigh each. " +
|
|
54
|
+
"When the rest depend on names and texts the core fixes, split in stages: the core first, yourself when it is small " +
|
|
55
|
+
"or by one session when it is big, merged and committed before the rest start; then, if 2 or more parts remain, one " +
|
|
56
|
+
"session per part, in one group. A staged core is one part of the task, not the whole task, when 2 or more parts " +
|
|
57
|
+
"follow it.",
|
|
37
58
|
"2. Plan the parts so that no two edit the same files. Write each task so the session can do it without you: what to " +
|
|
38
59
|
"produce and where, how to check it, what to report. Say if it may split its part further, and to run its checks " +
|
|
39
|
-
"through the project's scripts (step 6)
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"a
|
|
60
|
+
"through the project's scripts (step 6), since each permission request below you wakes you and waits on the person. " +
|
|
61
|
+
"Name the skills it should load for its part, from those listed to you: it sees the same list, not your choice; one " +
|
|
62
|
+
"permission rule for skill covers their loads, as one covers the checks. Say in the task when the part is a whole job " +
|
|
63
|
+
"that delivers itself (step 7), since an isolated session's brief otherwise says its branch is for you to merge.",
|
|
64
|
+
"3. Start them: one courier_spawn per part that runs at once, all with the same group name, so that you are woken once " +
|
|
65
|
+
"with every report, and isolate: true for each part that edits files in parallel with another. When each part runs " +
|
|
66
|
+
"a review stage of its own, count 6 live sessions per part against maxTotal (a part, its review session and its " +
|
|
67
|
+
"reviewers are live together at the peak): start the parts that fit in one group, and the rest in a group of their " +
|
|
68
|
+
"own once the first group has reported. A job that depends on another starts after that one is done, as a stage: " +
|
|
69
|
+
"merged into your checkout, or, when it was delivered instead (step 7), started with isolate: true and told the " +
|
|
70
|
+
"delivering session's courier/<session> branch, from its report, to merge first. " +
|
|
71
|
+
"Leave model and variant unset, so a part runs on your own model, unless the part plainly calls for another: a " +
|
|
72
|
+
"cheaper model or a lower variant for a small, well-specified part (a rename, a lookup), a stronger model or a higher " +
|
|
73
|
+
"variant for a design question or a hard bug. " +
|
|
74
|
+
"native: true for a part nobody needs to open on its own: it reads, checks or looks something up, reports once and is " +
|
|
75
|
+
"done; leave it off for a part the person may want to open, or that should outlive you. " +
|
|
76
|
+
"For long work, courier_later a check-in for yourself, and courier_cancel it when the reports arrive.",
|
|
77
|
+
"4. End your turn: reply without calling more tools, and do not poll with courier_children, courier_tree " +
|
|
78
|
+
"or sleep. The group's reports, a blocked report, a message without a status, a question, a permission request, a " +
|
|
79
|
+
"failed turn or a silent end each start a new turn for you; so does a message from the person or from the session " +
|
|
80
|
+
"that started you.",
|
|
81
|
+
" Answering from below: follow the notice. For a permission request, propose once with courier_answer, or reject with " +
|
|
82
|
+
"the reason when the person has told you to refuse it or it plainly goes against what they asked; the person decides, " +
|
|
83
|
+
"in OpenCode's prompt in your session. For a question, ask the person with your question tool, with the questions the " +
|
|
84
|
+
"notice gives; their answer goes on by itself. When the notice says OpenCode already shows it to the person, call " +
|
|
85
|
+
"nothing unless they give you their answer. Never answer for them.",
|
|
86
|
+
" Passing a message on: when it changes what other parts need (an assumption of the split that is wrong, a shared file " +
|
|
87
|
+
"or API that behaves otherwise, a decision of the person's), pass it on at once with courier_send, only to the sessions " +
|
|
88
|
+
"it affects, before they go further, then end your turn again; if it breaks the split, courier_stop the parts it breaks " +
|
|
89
|
+
"and plan them again, or send them a corrected task. Send it up too, without a status, when the other parts of the " +
|
|
90
|
+
"session that started you need it. Progress that changes nothing for the others goes to no one. A session's account " +
|
|
91
|
+
"of what the person told it is the person's word: pass it on to the parts it affects, do not judge it against the " +
|
|
92
|
+
"original task, and never tell a session to undo what the person asked.",
|
|
46
93
|
"5. Read each report by its status and its artifacts (branch, commits, files, checks). done: verify it. partial: what is " +
|
|
47
94
|
"left and why; have the session finish it with a courier_send, or do it yourself. blocked: make the decision it asks for " +
|
|
48
95
|
"and send it with courier_send; if only the person can make it, ask them with your question tool and pass the answer on. " +
|
|
49
|
-
"failed: read the error; message the session to try again, start a replacement, or carry on without it."
|
|
50
|
-
|
|
51
|
-
"
|
|
96
|
+
"failed: read the error; message the session to try again, start a replacement, or carry on without it. A review " +
|
|
97
|
+
"stage's report lists what was found, held, fixed and refused: read the refusals, fix or settle yourself any you " +
|
|
98
|
+
"disagree with, and run the checks on the fixed tree.",
|
|
99
|
+
"6. Verify first-hand: open the files, run the checks. Never hand the checking to another session: a review stage " +
|
|
100
|
+
"verifies and fixes below you, and running the checks on what it changed is still yours. Run checks through " +
|
|
52
101
|
"the project's scripts (bun run <script>, npm run <script>), not ./node_modules/.bin/<tool>, so that one permission " +
|
|
53
102
|
"rule covers them: your own permission prompts are relayed nowhere, and each one stalls the whole tree.",
|
|
54
103
|
"7. Integrate: merge each reported branch into your own checkout (git merge courier/<session>), resolve conflicts " +
|
|
55
|
-
"yourself, run the checks once more, then courier_cleanup the isolated sessions you are done with."
|
|
104
|
+
"yourself, run the checks once more, then courier_cleanup the isolated sessions you are done with. When the parts are " +
|
|
105
|
+
"whole jobs with a deliverable each (a ticket with its own branch or pull request), the session delivers it and " +
|
|
106
|
+
"reports the link, still naming its courier/<session> branch when it is isolated; you verify each delivery and merge " +
|
|
107
|
+
"nothing of it into your checkout.",
|
|
56
108
|
"8. Report upward if a session started you: one courier_send to it, with one status for the whole (done only when every " +
|
|
57
|
-
"part is verified and integrated; partial, blocked or failed otherwise) and the artifacts.
|
|
58
|
-
"to the person: if there is something the next tree in this project should know about
|
|
59
|
-
"it was split, what a part got wrong and what caught it, what a brief should have
|
|
60
|
-
"courier_note with that one line; none when there is nothing. Name the job it
|
|
61
|
-
"lesson for one kind of job is not taken for every job; the tool refuses a line
|
|
62
|
-
"it, so write it again shorter. A rule that holds every time goes to AGENTS.md or
|
|
63
|
-
"into a note. Then reply to the person.",
|
|
109
|
+
"part is verified and integrated, or verified and delivered; partial, blocked or failed otherwise) and the artifacts. " +
|
|
110
|
+
"At the top, before you reply to the person: if there is something the next tree in this project should know about " +
|
|
111
|
+
"running a tree like this one (how it was split, what a part got wrong and what caught it, what a brief should have " +
|
|
112
|
+
"said, what the person decided), one courier_note with that one line; none when there is nothing. Name the job it " +
|
|
113
|
+
"comes from and the reason, so that a lesson for one kind of job is not taken for every job; the tool refuses a line " +
|
|
114
|
+
"over its limit rather than clipping it, so write it again shorter. A rule that holds every time goes to AGENTS.md or " +
|
|
115
|
+
"the skill, through the person, not into a note. Then reply to the person.",
|
|
64
116
|
"",
|
|
65
117
|
"When a part goes wrong:",
|
|
66
118
|
"- A failed turn (failed=\"...\") or a silent end (ended=\"without-report\", quoting the session's last reply): message " +
|
package/dist/tree/cleanup.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { isAbsolute } from "node:path";
|
|
4
4
|
import { forgetDropped } from "./forget.js";
|
|
5
|
+
import { syncStanding } from "./standing.js";
|
|
5
6
|
import { childStore } from "./store.js";
|
|
6
7
|
import { keepReason } from "./text.js";
|
|
7
8
|
/** At most this many changes and commits are returned; the reason still counts them all. */
|
|
@@ -18,6 +19,7 @@ export async function cleanup(ports, parentID, input) {
|
|
|
18
19
|
// A member still out is dropped from its group, so the group is released without it; the result names that group.
|
|
19
20
|
const forget = async () => {
|
|
20
21
|
const group = await forgetDropped(ports, entry);
|
|
22
|
+
await syncStanding(ports, parentID);
|
|
21
23
|
return group ? { group } : {};
|
|
22
24
|
};
|
|
23
25
|
if (!entry.isolated)
|
package/dist/tree/context.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface Shaped {
|
|
|
9
9
|
}>;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* The `context` hook:
|
|
13
|
-
*
|
|
12
|
+
* The `context` hook: hides courier_spawn and the tools named `hiddenFromLeaf` from a session at `maxDepth`, and names a
|
|
13
|
+
* session's role in a system part unless its `role` entry does; a session nobody spawned that has started none is pointed to the skill.
|
|
14
14
|
*/
|
|
15
15
|
export declare function shapeContext(ports: ContextPorts, event: Shaped): Promise<void>;
|
package/dist/tree/context.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import { setBounded } from "../platform/bounded.js";
|
|
2
2
|
import { childStore } from "./store.js";
|
|
3
|
-
import { ROLE_PREFIX, rolePart } from "./text.js";
|
|
4
|
-
/** How many sessions'
|
|
3
|
+
import { ROLE_KEY, ROLE_PREFIX, rolePart } from "./text.js";
|
|
4
|
+
/** How many sessions' roles an instance remembers. */
|
|
5
5
|
const ROLES_MAX = 1000;
|
|
6
|
+
/** A role part, or the role entry's block, already in the system prompt, wherever its part begins. */
|
|
7
|
+
const ROLE_LINE = new RegExp(`^${ROLE_PREFIX}`, "m");
|
|
6
8
|
/**
|
|
7
|
-
* The `context` hook:
|
|
8
|
-
*
|
|
9
|
+
* The `context` hook: hides courier_spawn and the tools named `hiddenFromLeaf` from a session at `maxDepth`, and names a
|
|
10
|
+
* session's role in a system part unless its `role` entry does; a session nobody spawned that has started none is pointed to the skill.
|
|
9
11
|
*/
|
|
10
12
|
export async function shapeContext(ports, event) {
|
|
11
13
|
try {
|
|
12
|
-
const depth = await
|
|
14
|
+
const { depth, entry } = await roleOf(ports, event.sessionID);
|
|
13
15
|
if (depth === null && !event.tools.courier_spawn)
|
|
14
16
|
return;
|
|
15
17
|
if (depth !== null && depth >= ports.limits.maxDepth)
|
|
16
18
|
for (const tool of ["courier_spawn", ...(ports.hiddenFromLeaf ?? [])])
|
|
17
19
|
delete event.tools[tool];
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
+
if (entry || event.system.some((part) => ROLE_LINE.test(part.text)))
|
|
21
|
+
return;
|
|
22
|
+
event.system.push({ type: "text", text: rolePart(depth, ports.limits) });
|
|
20
23
|
}
|
|
21
24
|
catch (error) {
|
|
22
25
|
ports.log(`courier: cannot tell the role of session ${event.sessionID}: ${String(error)}`);
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
|
-
async function
|
|
28
|
+
async function roleOf(ports, sessionID) {
|
|
26
29
|
const known = ports.roles.get(sessionID);
|
|
27
30
|
if (known !== undefined)
|
|
28
31
|
return known;
|
|
@@ -30,6 +33,19 @@ async function depthOf(ports, sessionID) {
|
|
|
30
33
|
const children = childStore(ports.storage);
|
|
31
34
|
const chain = await children.indexedLineage(sessionID);
|
|
32
35
|
const depth = chain.length || ((await children.children(sessionID)).length ? 0 : null);
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
const role = { depth, entry: depth !== null && (await hasEntry(ports, sessionID)) };
|
|
37
|
+
setBounded(ports.roles, sessionID, role, ROLES_MAX);
|
|
38
|
+
return role;
|
|
39
|
+
}
|
|
40
|
+
/** Whether the session carries the role entry, listed when its role is looked up; one that cannot be read gets the part. */
|
|
41
|
+
async function hasEntry(ports, sessionID) {
|
|
42
|
+
if (!ports.instructions)
|
|
43
|
+
return false;
|
|
44
|
+
try {
|
|
45
|
+
return (await ports.instructions.entry.list({ sessionID })).some((entry) => entry.key === ROLE_KEY);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
ports.log(`courier: cannot read the instruction entries of session ${sessionID}, so its role goes in a system part: ${String(error)}`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
35
51
|
}
|
package/dist/tree/domain.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function readLimits(options: unknown): {
|
|
|
17
17
|
limits: Limits;
|
|
18
18
|
problems: string[];
|
|
19
19
|
};
|
|
20
|
-
/** The `nativeChildren` option: whether a child started without isolate gets OpenCode's own `parentID`; off unless `true`. */
|
|
20
|
+
/** The `nativeChildren` option: whether a child started without isolate or `native` gets OpenCode's own `parentID`; off unless `true`. */
|
|
21
21
|
export declare function readNativeChildren(options: unknown): {
|
|
22
22
|
nativeChildren: boolean;
|
|
23
23
|
problems: string[];
|
|
@@ -73,6 +73,18 @@ export declare function cut<T extends Cuttable>(nodes: ReadonlyArray<T>, max: nu
|
|
|
73
73
|
kept: T[];
|
|
74
74
|
leftOut: number;
|
|
75
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Entries older than this are dropped when their parent's roster is read, and on plugin setup,
|
|
78
|
+
* except isolated children whose worktree is still there: those stay until courier_cleanup.
|
|
79
|
+
*/
|
|
80
|
+
export declare const RETENTION_MS: number;
|
|
81
|
+
/** Whether a directory still exists; tests pass a fake. */
|
|
82
|
+
export type Exists = (directory: string) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Whether an entry is past retention at `now`: recorded more than `RETENTION_MS` before, unless it is an isolated
|
|
85
|
+
* child whose worktree exists, which is kept so it can still be cleaned up.
|
|
86
|
+
*/
|
|
87
|
+
export declare const isExpired: (entry: RosterEntry, now: number, exists: Exists) => boolean;
|
|
76
88
|
/** A session started with courier_spawn, recorded under the session that started it. */
|
|
77
89
|
export interface RosterEntry {
|
|
78
90
|
readonly sessionID: string;
|
|
@@ -91,9 +103,27 @@ export interface RosterEntry {
|
|
|
91
103
|
readonly reports?: "status";
|
|
92
104
|
/** The join group courier_spawn put it in, whose release holds its report; absent for a child in none. */
|
|
93
105
|
readonly group?: string;
|
|
94
|
-
/** Created with OpenCode's own `parentID` (the `nativeChildren` option), so OpenCode shows its asks in its parent's view. */
|
|
106
|
+
/** Created with OpenCode's own `parentID` (courier_spawn's `native`, else the `nativeChildren` option), so OpenCode shows its asks in its parent's view. */
|
|
95
107
|
readonly native?: true;
|
|
108
|
+
/** The model it was started on, as `modelName` writes it, when that is not the model its parent was on. */
|
|
109
|
+
readonly model?: string;
|
|
110
|
+
}
|
|
111
|
+
/** How a child was started, as courier_children and the panel show it: isolated, native when it is, and its model when not its parent's. */
|
|
112
|
+
export declare function startedAs(entry: RosterEntry): {
|
|
113
|
+
model?: string | undefined;
|
|
114
|
+
native?: true | undefined;
|
|
115
|
+
isolated: boolean;
|
|
116
|
+
};
|
|
117
|
+
/** A model as a session names it: its provider, its id, and its variant, which `"default"` and none both leave to the provider. */
|
|
118
|
+
export interface ModelRef {
|
|
119
|
+
readonly providerID: string;
|
|
120
|
+
readonly id: string;
|
|
121
|
+
readonly variant?: string;
|
|
96
122
|
}
|
|
123
|
+
/** `provider/model` as `courier_spawn` takes it: one slash, nothing empty on either side. */
|
|
124
|
+
export declare function parseModelName(text: string): Pick<ModelRef, "providerID" | "id"> | undefined;
|
|
125
|
+
/** A model as the roster, the panel and the results name it: `provider/model`, with `#variant` for a variant that is not the default. */
|
|
126
|
+
export declare function modelName(model: ModelRef): string;
|
|
97
127
|
/** `lineage` over roster entries already read. */
|
|
98
128
|
export declare function lineageIn(entries: ReadonlyArray<RosterEntry>, sessionID: string): RosterEntry[];
|
|
99
129
|
/** Roster entries by their session, for `lineageBy`. */
|
package/dist/tree/domain.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { millis, obj } from "../platform/json.js";
|
|
2
|
-
export const DEFAULT_LIMITS = { maxDepth:
|
|
2
|
+
export const DEFAULT_LIMITS = { maxDepth: 5, maxChildren: 5, maxTotal: 30 };
|
|
3
3
|
/** The limits in the plugin's options; one that is not a positive integer keeps its default and is named in `problems`. */
|
|
4
4
|
export function readLimits(options) {
|
|
5
5
|
const given = obj(options);
|
|
@@ -16,7 +16,7 @@ export function readLimits(options) {
|
|
|
16
16
|
const limits = { maxDepth: read("maxDepth"), maxChildren: read("maxChildren"), maxTotal: read("maxTotal") };
|
|
17
17
|
return { limits, problems };
|
|
18
18
|
}
|
|
19
|
-
/** The `nativeChildren` option: whether a child started without isolate gets OpenCode's own `parentID`; off unless `true`. */
|
|
19
|
+
/** The `nativeChildren` option: whether a child started without isolate or `native` gets OpenCode's own `parentID`; off unless `true`. */
|
|
20
20
|
export function readNativeChildren(options) {
|
|
21
21
|
const value = obj(options).nativeChildren;
|
|
22
22
|
if (value === undefined || typeof value === "boolean")
|
|
@@ -70,6 +70,32 @@ export function cut(nodes, max) {
|
|
|
70
70
|
}
|
|
71
71
|
return { kept: nodes.filter((node) => kept.has(node.sessionID)), leftOut: nodes.length - kept.size };
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Entries older than this are dropped when their parent's roster is read, and on plugin setup,
|
|
75
|
+
* except isolated children whose worktree is still there: those stay until courier_cleanup.
|
|
76
|
+
*/
|
|
77
|
+
export const RETENTION_MS = 14 * 24 * 60 * 60_000;
|
|
78
|
+
/**
|
|
79
|
+
* Whether an entry is past retention at `now`: recorded more than `RETENTION_MS` before, unless it is an isolated
|
|
80
|
+
* child whose worktree exists, which is kept so it can still be cleaned up.
|
|
81
|
+
*/
|
|
82
|
+
export const isExpired = (entry, now, exists) => now - entry.createdAt > RETENTION_MS && !(entry.isolated && exists(entry.directory));
|
|
83
|
+
/** How a child was started, as courier_children and the panel show it: isolated, native when it is, and its model when not its parent's. */
|
|
84
|
+
export function startedAs(entry) {
|
|
85
|
+
return { isolated: entry.isolated, ...(entry.native ? { native: true } : {}), ...(entry.model ? { model: entry.model } : {}) };
|
|
86
|
+
}
|
|
87
|
+
/** `provider/model` as `courier_spawn` takes it: one slash, nothing empty on either side. */
|
|
88
|
+
export function parseModelName(text) {
|
|
89
|
+
const slash = text.indexOf("/");
|
|
90
|
+
if (slash <= 0 || slash === text.length - 1)
|
|
91
|
+
return undefined;
|
|
92
|
+
return { providerID: text.slice(0, slash), id: text.slice(slash + 1) };
|
|
93
|
+
}
|
|
94
|
+
/** A model as the roster, the panel and the results name it: `provider/model`, with `#variant` for a variant that is not the default. */
|
|
95
|
+
export function modelName(model) {
|
|
96
|
+
const variant = model.variant && model.variant !== "default" ? `#${model.variant}` : "";
|
|
97
|
+
return `${model.providerID}/${model.id}${variant}`;
|
|
98
|
+
}
|
|
73
99
|
/** `lineage` over roster entries already read. */
|
|
74
100
|
export function lineageIn(entries, sessionID) {
|
|
75
101
|
return lineageBy(bySession(entries), sessionID);
|
package/dist/tree/events.js
CHANGED
|
@@ -4,6 +4,7 @@ import { endsIdle, retryDelay } from "./domain.js";
|
|
|
4
4
|
import { forgetChild, forgetDeleted } from "./forget.js";
|
|
5
5
|
import { hasCompleteGroup, leave, outIn } from "./group.js";
|
|
6
6
|
import { awaited, reportOf, stoppedSincePrompt } from "./report.js";
|
|
7
|
+
import { syncStanding } from "./standing.js";
|
|
7
8
|
import { childStore, groupStore } from "./store.js";
|
|
8
9
|
import { lastReply } from "./status.js";
|
|
9
10
|
import { failureNotice, silentNotice } from "./text.js";
|
|
@@ -43,6 +44,7 @@ export async function reportFailure(ports, seen, event) {
|
|
|
43
44
|
finally {
|
|
44
45
|
if (completed.includes(true))
|
|
45
46
|
ports.nudge();
|
|
47
|
+
await Promise.all(entries.map((entry) => syncStanding(ports, entry.parentID)));
|
|
46
48
|
}
|
|
47
49
|
return entries.map((entry) => entry.parentID);
|
|
48
50
|
}
|
|
@@ -66,9 +68,11 @@ export async function notePrompt(ports, event, inbox) {
|
|
|
66
68
|
if (inboxID !== undefined && UNOWED.has(inbox?.get(inboxID) ?? ""))
|
|
67
69
|
return false;
|
|
68
70
|
const children = childStore(ports.storage);
|
|
69
|
-
|
|
71
|
+
const parentID = await children.indexedParent(sessionID);
|
|
72
|
+
if (parentID === undefined)
|
|
70
73
|
return false;
|
|
71
74
|
await children.prompted(sessionID, event.created ?? ports.now());
|
|
75
|
+
await syncStanding(ports, parentID);
|
|
72
76
|
return true;
|
|
73
77
|
}
|
|
74
78
|
/**
|
|
@@ -88,6 +92,7 @@ export async function noteInterrupted(ports, event) {
|
|
|
88
92
|
const member = await outIn(ports, entry);
|
|
89
93
|
if (member && (await leave(ports, member, "interrupted", at)))
|
|
90
94
|
ports.nudge();
|
|
95
|
+
await syncStanding(ports, entry.parentID);
|
|
91
96
|
return true;
|
|
92
97
|
}
|
|
93
98
|
/**
|
|
@@ -104,6 +109,8 @@ export async function noteDeleted(ports, event) {
|
|
|
104
109
|
await forgetDeleted(ports, sessionID, forgotten, member, event.created);
|
|
105
110
|
if (parentID !== undefined && entry && !entry.isolated && started.length === 0)
|
|
106
111
|
await forgetChild(ports.storage, parentID, sessionID);
|
|
112
|
+
if (parentID !== undefined)
|
|
113
|
+
await syncStanding(ports, parentID);
|
|
107
114
|
return forgotten;
|
|
108
115
|
}
|
|
109
116
|
/** A `Waits` asking `suppliers` one after another, cheapest first: the first that waits answers. */
|
|
@@ -165,6 +172,7 @@ export async function reportSilent(ports, seen, event, outside) {
|
|
|
165
172
|
await children.untold(sessionID, toldAt).catch(() => undefined);
|
|
166
173
|
throw error;
|
|
167
174
|
}
|
|
175
|
+
await syncStanding(ports, entry.parentID);
|
|
168
176
|
return [entry.parentID];
|
|
169
177
|
}
|
|
170
178
|
/**
|
|
@@ -179,6 +187,17 @@ export async function reportDeclined(ports, seen, event, outside) {
|
|
|
179
187
|
return reportSilent(ports, seen, event, outside);
|
|
180
188
|
}
|
|
181
189
|
const TURN_ENDS = new Set(["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted"]);
|
|
190
|
+
/** What `route` and `after` dispatch on; the wake watch needs `inbox.enqueued` and `execution.started` both. */
|
|
191
|
+
const TREE_TYPES = [
|
|
192
|
+
"session.execution.started",
|
|
193
|
+
"session.execution.succeeded",
|
|
194
|
+
"session.execution.failed",
|
|
195
|
+
"session.execution.interrupted",
|
|
196
|
+
"session.inbox.enqueued",
|
|
197
|
+
"session.inbox.delivered",
|
|
198
|
+
"session.inbox.cancelled",
|
|
199
|
+
"session.deleted",
|
|
200
|
+
];
|
|
182
201
|
/** A session's turn ended, sealing its groups: one that is complete has the scheduler deliver it now; not a shutdown's, which stamps no idle time. */
|
|
183
202
|
async function sealGroups(ports, event) {
|
|
184
203
|
if (event.data.reason === "shutdown")
|
|
@@ -239,6 +258,7 @@ async function route(ports, state, outside, event) {
|
|
|
239
258
|
*/
|
|
240
259
|
export function treeEvents(state, outside) {
|
|
241
260
|
return {
|
|
261
|
+
types: TREE_TYPES,
|
|
242
262
|
handle: (ports, event) => route(ports, state, outside, event),
|
|
243
263
|
// After: a silent end is judged while the group the nudge may deliver is still there to wait on.
|
|
244
264
|
after: (ports, event) => (TURN_ENDS.has(event.type) ? sealGroups(ports, event) : undefined),
|
package/dist/tree/group.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNotFound, millis } from "../platform/json.js";
|
|
2
2
|
import { envelope } from "../kernel/protocol.js";
|
|
3
3
|
import { complete, standingOf } from "./domain.js";
|
|
4
|
+
import { syncStanding } from "./standing.js";
|
|
4
5
|
import { groupStore } from "./store.js";
|
|
5
6
|
import { groupNotice } from "./text.js";
|
|
6
7
|
/** Makes a spawned session a member of its parent's group, opening the group if it was not. */
|
|
@@ -182,6 +183,8 @@ async function release(ports, parentID, group) {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
await drop(ports, parentID, group, members);
|
|
186
|
+
// Delivered: the members read as released in the parent's standing, which its next step shows.
|
|
187
|
+
await syncStanding(ports, parentID);
|
|
185
188
|
}
|
|
186
189
|
/** Drops a group's members once delivered, or unsent, saying why. */
|
|
187
190
|
async function drop(ports, parentID, group, members, unsent) {
|
package/dist/tree/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { endsIdle, lineageIn, nativeRootOf, readLimits, readNativeChildren } fro
|
|
|
4
4
|
export { together, treeEvents, waitsOn } from "./events.js";
|
|
5
5
|
export { deliverReleased } from "./group.js";
|
|
6
6
|
export { contextOf } from "./panel.js";
|
|
7
|
-
export type { CleanupPorts, CourierPorts, ModelWindow, Pending, PendingPrompt, RosterEntry, RosterStorage, ShownForm, SpawnGate, Waits, WatchPorts, WatchState, } from "./ports.js";
|
|
7
|
+
export type { CleanupPorts, CourierPorts, Entries, Entry, Instructions, ModelWindow, Pending, PendingPrompt, Role, RosterEntry, RosterStorage, ShownForm, SpawnGate, Waits, WatchPorts, WatchState, } from "./ports.js";
|
|
8
8
|
export { allEntries, answeringTop, childrenOf, indexedLineage, lineage, pruneExpired, reportState, RETENTION_MS, type ReportState } from "./roster.js";
|
|
9
9
|
export { runs, turnIn, turnOf, type Turn } from "./running.js";
|
|
10
10
|
export { subtree, type Below } from "./subtree.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ModelRef } from "./domain.js";
|
|
2
|
+
import type { CourierPorts } from "./ports.js";
|
|
3
|
+
/** What courier_spawn says of the model: `provider/model`, and the variant of whichever model is chosen. */
|
|
4
|
+
export interface ModelChoice {
|
|
5
|
+
readonly model?: string;
|
|
6
|
+
readonly variant?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The model a child runs on: the `model` named, else the agent's, else the one its parent runs on, with the `variant`
|
|
10
|
+
* named; `parent` is the parent's own, for the roster to tell a child on another one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function chooseModel(ports: CourierPorts, parentID: string, choice: ModelChoice, agent: string | undefined): Promise<{
|
|
13
|
+
model: undefined;
|
|
14
|
+
parent: ModelRef | undefined;
|
|
15
|
+
} | {
|
|
16
|
+
model: ModelRef;
|
|
17
|
+
parent: ModelRef | undefined;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { modelName, parseModelName } from "./domain.js";
|
|
2
|
+
import { modelFormatRefusal, unknownModelRefusal, unknownVariantRefusal, variantWithoutModelRefusal } from "./text.js";
|
|
3
|
+
/**
|
|
4
|
+
* The model a child runs on: the `model` named, else the agent's, else the one its parent runs on, with the `variant`
|
|
5
|
+
* named; `parent` is the parent's own, for the roster to tell a child on another one.
|
|
6
|
+
*/
|
|
7
|
+
export async function chooseModel(ports, parentID, choice, agent) {
|
|
8
|
+
// Some models send null, or an empty string, for an optional field they leave out.
|
|
9
|
+
const named = trimmed(choice.model);
|
|
10
|
+
const variant = trimmed(choice.variant);
|
|
11
|
+
const own = named === undefined ? undefined : parseModelName(named);
|
|
12
|
+
if (named !== undefined && !own)
|
|
13
|
+
throw new Error(modelFormatRefusal(named));
|
|
14
|
+
const parent = await parentModel(ports, parentID);
|
|
15
|
+
// An agent that cannot be looked up may name a model of its own, which OpenCode applies when none is passed.
|
|
16
|
+
const inherited = own ? undefined : await inheritedModel(ports, parent, agent).catch(() => undefined);
|
|
17
|
+
const base = own ?? inherited;
|
|
18
|
+
if (!base) {
|
|
19
|
+
if (variant !== undefined)
|
|
20
|
+
throw new Error(variantWithoutModelRefusal(variant, agent));
|
|
21
|
+
return { model: undefined, parent };
|
|
22
|
+
}
|
|
23
|
+
const chosen = variant ?? base.variant;
|
|
24
|
+
const model = { providerID: base.providerID, id: base.id, ...(chosen !== undefined ? { variant: chosen } : {}) };
|
|
25
|
+
if (own || variant !== undefined)
|
|
26
|
+
await check(ports, model, own !== undefined);
|
|
27
|
+
return { model, parent };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The model the parent runs on: its session's, else OpenCode's default. A failed lookup must not keep a child on no
|
|
31
|
+
* particular model from starting, so it reads as none, and the child then runs on OpenCode's default.
|
|
32
|
+
*/
|
|
33
|
+
async function parentModel(ports, parentID) {
|
|
34
|
+
const session = await ports.session.get({ sessionID: parentID }).catch(() => undefined);
|
|
35
|
+
if (!session)
|
|
36
|
+
return undefined;
|
|
37
|
+
return session.model ?? (await ports.defaultModel().catch(() => undefined));
|
|
38
|
+
}
|
|
39
|
+
/** The named agent's model, if it names one; else the parent's. */
|
|
40
|
+
async function inheritedModel(ports, parent, agent) {
|
|
41
|
+
if (!agent)
|
|
42
|
+
return parent;
|
|
43
|
+
const named = await ports.agent.get({ agentID: agent, location: { directory: ports.directory } });
|
|
44
|
+
return named.data.model ?? parent;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Refuses a model OpenCode does not list, or a variant its model has not; `"default"` is every model's. A listing that
|
|
48
|
+
* cannot be read checks nothing: OpenCode refuses what it does not know at the child's first turn, which is reported.
|
|
49
|
+
*/
|
|
50
|
+
async function check(ports, model, named) {
|
|
51
|
+
let known;
|
|
52
|
+
try {
|
|
53
|
+
known = await ports.models();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
ports.log(`courier_spawn: cannot list the models to check ${modelName(model)} against: ${String(error)}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const found = known.find((item) => item.providerID === model.providerID && item.id === model.id);
|
|
60
|
+
if (!found)
|
|
61
|
+
throw new Error(unknownModelRefusal(model, known, named));
|
|
62
|
+
if (model.variant !== undefined && model.variant !== "default" && !found.variants.includes(model.variant))
|
|
63
|
+
throw new Error(unknownVariantRefusal(model, found.variants));
|
|
64
|
+
}
|
|
65
|
+
const trimmed = (value) => (typeof value === "string" ? value.trim() || undefined : (value ?? undefined));
|
package/dist/tree/panel.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { startedAs } from "./domain.js";
|
|
1
2
|
import { lastStatus, stoppedSincePrompt } from "./report.js";
|
|
2
3
|
import { standingIn } from "./status.js";
|
|
3
4
|
import { childStore } from "./store.js";
|
|
@@ -80,7 +81,7 @@ async function row(ports, windows, { entry, depth, info, running, endedAt, pendi
|
|
|
80
81
|
...(stopped ? { stopped } : {}),
|
|
81
82
|
...reportRow(report, status),
|
|
82
83
|
...(entry.group && standing ? { group: { name: entry.group, standing } } : {}),
|
|
83
|
-
|
|
84
|
+
...startedAs(entry),
|
|
84
85
|
created: info?.time.created ?? entry.createdAt,
|
|
85
86
|
...(info && !running && endedAt !== undefined ? { idle: endedAt } : {}),
|
|
86
87
|
...(info ? { cost: info.cost } : {}),
|
|
@@ -96,7 +97,7 @@ async function row(ports, windows, { entry, depth, info, running, endedAt, pendi
|
|
|
96
97
|
export async function panel(ports, rootID) {
|
|
97
98
|
const { kept, leftOut } = await readTree(ports, rootID);
|
|
98
99
|
const stalled = await stalledAmong(ports, [rootID, ...kept.map((node) => node.entry.sessionID)]);
|
|
99
|
-
const windows = await ports.
|
|
100
|
+
const windows = await ports.models().catch(() => []);
|
|
100
101
|
const rows = await Promise.all(kept.map((node) => row(ports, windows, node, stalled.get(node.entry.sessionID))));
|
|
101
102
|
const own = stalled.get(rootID);
|
|
102
103
|
return { rows, ...(leftOut ? { truncated: leftOut } : {}), ...(own !== undefined ? { stalled: own } : {}) };
|