@timmyjl12/pi-subagents 0.20.0 → 0.21.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +862 -827
  2. package/README.md +1125 -1080
  3. package/dist/active-agents-prompt.d.ts +31 -9
  4. package/dist/active-agents-prompt.js +73 -9
  5. package/dist/agent-color.js +9 -1
  6. package/dist/agent-file-toggle.d.ts +1 -1
  7. package/dist/agent-manager.d.ts +405 -18
  8. package/dist/agent-manager.js +1661 -131
  9. package/dist/agent-runner.d.ts +45 -6
  10. package/dist/agent-runner.js +109 -18
  11. package/dist/agent-types.d.ts +30 -7
  12. package/dist/agent-types.js +38 -9
  13. package/dist/awaited-result.d.ts +37 -0
  14. package/dist/awaited-result.js +150 -0
  15. package/dist/child-session-shutdown.d.ts +19 -1
  16. package/dist/child-session-shutdown.js +60 -11
  17. package/dist/cleanup-plans.d.ts +10 -0
  18. package/dist/cleanup-plans.js +112 -0
  19. package/dist/cross-extension-rpc.d.ts +8 -1
  20. package/dist/cross-extension-rpc.js +59 -5
  21. package/dist/custom-agents.d.ts +34 -9
  22. package/dist/custom-agents.js +308 -111
  23. package/dist/default-agents.d.ts +1 -1
  24. package/dist/env.d.ts +1 -1
  25. package/dist/error-log.d.ts +6 -0
  26. package/dist/error-log.js +8 -0
  27. package/dist/force-main-model.d.ts +21 -0
  28. package/dist/force-main-model.js +28 -0
  29. package/dist/goal-bridge.d.ts +155 -0
  30. package/dist/goal-bridge.js +305 -0
  31. package/dist/group-join.d.ts +5 -1
  32. package/dist/group-join.js +52 -7
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.js +2827 -333
  35. package/dist/invocation-config.d.ts +30 -3
  36. package/dist/invocation-config.js +30 -1
  37. package/dist/memory.d.ts +1 -1
  38. package/dist/mention-clone.d.ts +1 -1
  39. package/dist/model-scope.d.ts +1 -1
  40. package/dist/nested-tools.d.ts +22 -1
  41. package/dist/nested-tools.js +120 -26
  42. package/dist/output-file.d.ts +15 -4
  43. package/dist/output-file.js +146 -43
  44. package/dist/prompts.d.ts +1 -1
  45. package/dist/recovery.d.ts +1 -1
  46. package/dist/report-cleanup.d.ts +204 -0
  47. package/dist/report-cleanup.js +1632 -0
  48. package/dist/report-store.d.ts +738 -0
  49. package/dist/report-store.js +3612 -0
  50. package/dist/schedule-store.d.ts +14 -6
  51. package/dist/schedule-store.js +88 -58
  52. package/dist/schedule.d.ts +20 -8
  53. package/dist/schedule.js +135 -74
  54. package/dist/settings.d.ts +39 -11
  55. package/dist/settings.js +22 -5
  56. package/dist/status-note.d.ts +1 -1
  57. package/dist/structured-output.d.ts +1 -1
  58. package/dist/types.d.ts +32 -3
  59. package/dist/ui/agent-mention.d.ts +2 -2
  60. package/dist/ui/agent-widget.d.ts +82 -13
  61. package/dist/ui/agent-widget.js +155 -37
  62. package/dist/ui/cleanup-preview.d.ts +59 -0
  63. package/dist/ui/cleanup-preview.js +466 -0
  64. package/dist/ui/conversation-viewer.d.ts +4 -4
  65. package/dist/ui/conversation-viewer.js +10 -6
  66. package/dist/ui/fleet-list.d.ts +3 -3
  67. package/dist/ui/fleet-list.js +3 -3
  68. package/dist/ui/fleet-overlay.d.ts +37 -6
  69. package/dist/ui/fleet-overlay.js +214 -18
  70. package/dist/ui/hub-feed.d.ts +52 -0
  71. package/dist/ui/hub-feed.js +148 -0
  72. package/dist/ui/native-transcript.js +5 -1
  73. package/dist/ui/schedule-menu.d.ts +1 -1
  74. package/dist/ui/schedule-menu.js +1 -1
  75. package/dist/ui/workflow-card.d.ts +4 -4
  76. package/dist/ui/workflow-dialog.d.ts +4 -4
  77. package/dist/ui/workflow-dialog.js +8 -3
  78. package/dist/ui/workflow-menu.d.ts +2 -2
  79. package/dist/usage.d.ts +12 -0
  80. package/dist/usage.js +28 -1
  81. package/dist/workflow/entry.d.ts +3 -3
  82. package/dist/workflow/host.d.ts +7 -4
  83. package/dist/workflow/host.js +162 -48
  84. package/dist/workflow/journal.d.ts +23 -7
  85. package/dist/workflow/journal.js +80 -23
  86. package/dist/workflow/progress.d.ts +1 -1
  87. package/dist/workflow/runtime.d.ts +45 -6
  88. package/dist/workflow/runtime.js +105 -16
  89. package/dist/workflow/task.d.ts +13 -4
  90. package/dist/workflow/task.js +7 -1
  91. package/dist/workflow/tool-description.d.ts +7 -2
  92. package/dist/workflow/tool-description.js +10 -5
  93. package/docs/{FORK.md → DEVELOPMENT.md} +4 -4
  94. package/docs/artifacts.md +93 -0
  95. package/docs/rpc.md +252 -189
  96. package/docs/runtime-performance.md +53 -0
  97. package/docs/workflows.md +48 -18
  98. package/examples/agent-tool-description.md +2 -2
  99. package/examples/workflows/review-panel.js +6 -3
  100. package/package.json +5 -5
  101. package/src/active-agents-prompt.ts +115 -39
  102. package/src/agent-color.ts +10 -2
  103. package/src/agent-file-toggle.ts +2 -2
  104. package/src/agent-manager.ts +3312 -1601
  105. package/src/agent-runner.ts +164 -36
  106. package/src/agent-types.ts +56 -11
  107. package/src/awaited-result.ts +187 -0
  108. package/src/child-session-shutdown.ts +114 -46
  109. package/src/cleanup-plans.ts +112 -0
  110. package/src/cross-extension-rpc.ts +68 -9
  111. package/src/custom-agents.ts +384 -112
  112. package/src/default-agents.ts +1 -1
  113. package/src/enabled-models.ts +1 -1
  114. package/src/env.ts +1 -1
  115. package/src/error-log.ts +10 -1
  116. package/src/force-main-model.ts +29 -0
  117. package/src/goal-bridge.ts +468 -0
  118. package/src/group-join.ts +56 -9
  119. package/src/index.ts +2987 -349
  120. package/src/invocation-config.ts +50 -4
  121. package/src/memory.ts +1 -1
  122. package/src/mention-clone.ts +3 -3
  123. package/src/model-scope.ts +1 -1
  124. package/src/nested-tools.ts +164 -33
  125. package/src/output-file.ts +168 -46
  126. package/src/prompts.ts +1 -1
  127. package/src/recovery.ts +2 -2
  128. package/src/report-cleanup.ts +2044 -0
  129. package/src/report-store.ts +4130 -0
  130. package/src/schedule-store.ts +244 -201
  131. package/src/schedule.ts +144 -80
  132. package/src/settings.ts +61 -16
  133. package/src/skill-loader.ts +1 -1
  134. package/src/standalone-fallback.ts +2 -2
  135. package/src/status-note.ts +1 -1
  136. package/src/structured-output.ts +1 -1
  137. package/src/types.ts +33 -3
  138. package/src/ui/agent-mention.ts +3 -3
  139. package/src/ui/agent-widget.ts +179 -45
  140. package/src/ui/cleanup-preview.ts +518 -0
  141. package/src/ui/conversation-viewer.ts +19 -15
  142. package/src/ui/fleet-list.ts +7 -7
  143. package/src/ui/fleet-overlay.ts +1048 -847
  144. package/src/ui/hub-feed.ts +179 -0
  145. package/src/ui/native-transcript.ts +7 -3
  146. package/src/ui/schedule-menu.ts +4 -4
  147. package/src/ui/workflow-card.ts +4 -4
  148. package/src/ui/workflow-dialog.ts +10 -6
  149. package/src/ui/workflow-menu.ts +4 -4
  150. package/src/usage.ts +53 -3
  151. package/src/workflow/collisions.ts +1 -1
  152. package/src/workflow/entry.ts +3 -3
  153. package/src/workflow/host.ts +174 -54
  154. package/src/workflow/journal.ts +80 -23
  155. package/src/workflow/progress.ts +1 -1
  156. package/src/workflow/runtime.ts +146 -23
  157. package/src/workflow/saved.ts +3 -3
  158. package/src/workflow/task.ts +18 -7
  159. package/src/workflow/tool-description.ts +10 -5
@@ -1,18 +1,40 @@
1
1
  /**
2
2
  * Main-session awareness of live subagents.
3
3
  *
4
- * A compact `<pi-subagents>` system-prompt section lists running/queued agents
5
- * only while any exist, so the main model can interpret "cancel that task"
6
- * and choose the appropriate stop or steer tool.
4
+ * A compact `<pi-subagents>` status message lists running/queued agents, so the
5
+ * main model can interpret "cancel that task" and choose the appropriate stop
6
+ * or steer tool.
7
+ *
8
+ * Delivered as a hidden custom message appended at the next prompt — and only
9
+ * when the list differs from the last one on the branch — rather than as a
10
+ * system-prompt section. A section edit rewrites the prompt head: providers
11
+ * without mid-conversation system messages (pi collapses them into the head)
12
+ * lose the whole cached prefix on every start and finish, and append-mode
13
+ * children inherit the volatile list through `ctx.getSystemPrompt()`. An
14
+ * appended message leaves everything already sent untouched.
7
15
  */
8
- import type { AgentRecord } from "./types.js";
9
- /** Key under `systemPromptOptions.sections`; pi renders it as `<pi-subagents>`. */
10
- export declare const ACTIVE_AGENTS_SECTION = "pi-subagents";
16
+ import type { SessionEntry } from "@earendil-works/pi-coding-agent";
17
+ import type { AgentRecord } from "./types.ts";
18
+ /** `customType` of the status message; `display: false` keeps it out of the TUI. */
19
+ export declare const ACTIVE_AGENTS_MESSAGE_TYPE = "subagents-active";
11
20
  type ListedRecord = Pick<AgentRecord, "id" | "handle" | "alias" | "description" | "status" | "isBackground">;
21
+ /** The subset of a branch entry this module reads. */
22
+ type BranchEntry = Pick<SessionEntry, "type"> & {
23
+ id?: string;
24
+ customType?: string;
25
+ content?: unknown;
26
+ firstKeptEntryId?: string | null;
27
+ };
12
28
  /**
13
- * Section text for the running/queued agents, or undefined when there are none
14
- * (idle sessions get no section at all). Contains only stable fields — no
15
- * durations or token counts — so the prompt does not churn every turn.
29
+ * List text for the running/queued agents, or undefined when there are none.
30
+ * Contains only stable fields — no durations or token counts — so the text
31
+ * changes only when the set of agents or their status does.
16
32
  */
17
33
  export declare function buildActiveAgentsSection(records: readonly ListedRecord[]): string | undefined;
34
+ /**
35
+ * Status message content to append at this prompt, or undefined when the
36
+ * branch already carries the current list. Once agents drain, the model is
37
+ * told so exactly once; a branch that never listed any gets nothing.
38
+ */
39
+ export declare function nextActiveAgentsMessage(records: readonly ListedRecord[], branch: readonly BranchEntry[]): string | undefined;
18
40
  export {};
@@ -1,18 +1,27 @@
1
1
  /**
2
2
  * Main-session awareness of live subagents.
3
3
  *
4
- * A compact `<pi-subagents>` system-prompt section lists running/queued agents
5
- * only while any exist, so the main model can interpret "cancel that task"
6
- * and choose the appropriate stop or steer tool.
4
+ * A compact `<pi-subagents>` status message lists running/queued agents, so the
5
+ * main model can interpret "cancel that task" and choose the appropriate stop
6
+ * or steer tool.
7
+ *
8
+ * Delivered as a hidden custom message appended at the next prompt — and only
9
+ * when the list differs from the last one on the branch — rather than as a
10
+ * system-prompt section. A section edit rewrites the prompt head: providers
11
+ * without mid-conversation system messages (pi collapses them into the head)
12
+ * lose the whole cached prefix on every start and finish, and append-mode
13
+ * children inherit the volatile list through `ctx.getSystemPrompt()`. An
14
+ * appended message leaves everything already sent untouched.
7
15
  */
8
- /** Key under `systemPromptOptions.sections`; pi renders it as `<pi-subagents>`. */
9
- export const ACTIVE_AGENTS_SECTION = "pi-subagents";
10
- /** Rows listed in the section; the rest are summarized as a count. */
16
+ /** `customType` of the status message; `display: false` keeps it out of the TUI. */
17
+ export const ACTIVE_AGENTS_MESSAGE_TYPE = "subagents-active";
18
+ /** Rows listed in the message; the rest are summarized as a count. */
11
19
  const MAX_ROWS = 10;
20
+ const NONE_ACTIVE = "No subagents are running or queued now.";
12
21
  /**
13
- * Section text for the running/queued agents, or undefined when there are none
14
- * (idle sessions get no section at all). Contains only stable fields — no
15
- * durations or token counts — so the prompt does not churn every turn.
22
+ * List text for the running/queued agents, or undefined when there are none.
23
+ * Contains only stable fields — no durations or token counts — so the text
24
+ * changes only when the set of agents or their status does.
16
25
  */
17
26
  export function buildActiveAgentsSection(records) {
18
27
  const active = records.filter(r => r.status === "running" || r.status === "queued");
@@ -32,3 +41,58 @@ export function buildActiveAgentsSection(records) {
32
41
  "If the user asks to cancel/stop one of these, call stop_subagent with its id or handle; to redirect it, call steer_subagent.",
33
42
  ].join("\n");
34
43
  }
44
+ /**
45
+ * The branch as the model still sees it after compaction. Mirrors pi's
46
+ * `buildContextEntries`: the latest compaction entry stands in for everything
47
+ * before it, except the entries it retained (`firstKeptEntryId` onwards) and
48
+ * everything after it. A branch that is already projected — the compaction
49
+ * first — passes through unchanged.
50
+ */
51
+ function projectedBranch(branch) {
52
+ let compactionAt = -1;
53
+ for (let i = branch.length - 1; i >= 0; i--) {
54
+ if (branch[i].type === "compaction") {
55
+ compactionAt = i;
56
+ break;
57
+ }
58
+ }
59
+ if (compactionAt < 0)
60
+ return branch;
61
+ const firstKept = branch[compactionAt].firstKeptEntryId;
62
+ const keptFrom = firstKept ? branch.findIndex(entry => entry.id === firstKept) : -1;
63
+ const retained = keptFrom >= 0 && keptFrom < compactionAt ? branch.slice(keptFrom, compactionAt) : [];
64
+ return [...retained, ...branch.slice(compactionAt + 1)];
65
+ }
66
+ /** Text of the latest status message the model still has on this branch. */
67
+ function lastAnnouncement(branch) {
68
+ const visible = projectedBranch(branch);
69
+ for (let i = visible.length - 1; i >= 0; i--) {
70
+ const entry = visible[i];
71
+ if (entry.type !== "custom_message" || entry.customType !== ACTIVE_AGENTS_MESSAGE_TYPE)
72
+ continue;
73
+ if (typeof entry.content === "string")
74
+ return entry.content;
75
+ if (!Array.isArray(entry.content))
76
+ return undefined;
77
+ return entry.content
78
+ .map((part) => (part.type === "text" && typeof part.text === "string" ? part.text : ""))
79
+ .join("");
80
+ }
81
+ return undefined;
82
+ }
83
+ /**
84
+ * Status message content to append at this prompt, or undefined when the
85
+ * branch already carries the current list. Once agents drain, the model is
86
+ * told so exactly once; a branch that never listed any gets nothing.
87
+ */
88
+ export function nextActiveAgentsMessage(records, branch) {
89
+ const list = buildActiveAgentsSection(records);
90
+ const last = lastAnnouncement(branch);
91
+ const wrap = (body) => `<pi-subagents>\n${body}\n</pi-subagents>`;
92
+ if (list) {
93
+ const text = wrap(list);
94
+ return text === last ? undefined : text;
95
+ }
96
+ const idle = wrap(NONE_ACTIVE);
97
+ return last === undefined || last === idle ? undefined : idle;
98
+ }
@@ -119,5 +119,13 @@ export function renderAgentName(type, theme, style = {}) {
119
119
  if (!type)
120
120
  return renderAgentNameLabel("Agent", undefined, theme, style);
121
121
  const config = getConfig(type);
122
- return renderAgentNameLabel(config.displayName, config.color, theme, style);
122
+ // displayName is user-authored config free text. Every caller feeds the
123
+ // result to a terminal ROW; a control byte here must not break the row.
124
+ // ANSI styling is added by renderAgentNameLabel after this flattening.
125
+ const displayName = config.displayName.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, " ")
126
+ .replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, " ")
127
+ .replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]+/g, " ")
128
+ .replace(/\s+/g, " ")
129
+ .trim();
130
+ return renderAgentNameLabel(displayName || type, config.color, theme, style);
123
131
  }
@@ -24,7 +24,7 @@
24
24
  * reports `changed: false` for the spellings it cannot rewrite, so the caller
25
25
  * refuses honestly rather than announcing a change it did not make.
26
26
  */
27
- import type { AgentConfig } from "./types.js";
27
+ import type { AgentConfig } from "./types.ts";
28
28
  export type AgentFileLocation = "project" | "workspace" | "personal";
29
29
  export declare const projectAgentsDir: (cwd?: string) => string;
30
30
  export declare const workspaceAgentsDir: (cwd?: string) => string;