@gotgenes/pi-subagents 6.0.1 → 6.2.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/CHANGELOG.md +27 -0
- package/docs/architecture/architecture.md +5 -3
- package/docs/plans/0098-extract-agent-record-state-machine.md +435 -0
- package/docs/plans/0099-replace-ctx-with-parent-snapshot.md +488 -0
- package/docs/retro/0098-extract-agent-record-state-machine.md +46 -0
- package/docs/retro/0102-consolidate-test-record-factory.md +30 -0
- package/package.json +1 -1
- package/src/agent-manager.ts +37 -61
- package/src/agent-record.ts +179 -0
- package/src/agent-runner.ts +16 -22
- package/src/env.ts +4 -5
- package/src/index.ts +4 -3
- package/src/parent-snapshot.ts +27 -0
- package/src/service-adapter.ts +2 -2
- package/src/types.ts +33 -39
- package/src/ui/agent-menu.ts +2 -3
package/src/types.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ThinkingLevel } from "@earendil-works/pi-ai";
|
|
6
|
-
import type { AgentSession } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import type { LifetimeUsage } from "./usage.js";
|
|
8
6
|
|
|
7
|
+
export type { AgentRecordInit, AgentRecordStatus } from "./agent-record.js";
|
|
8
|
+
|
|
9
|
+
export { AgentRecord } from "./agent-record.js";
|
|
9
10
|
export type { ThinkingLevel };
|
|
10
11
|
|
|
11
12
|
/** Agent type: any string name (built-in defaults or user-defined). */
|
|
@@ -55,43 +56,6 @@ export interface AgentConfig {
|
|
|
55
56
|
source?: "default" | "project" | "global";
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export interface AgentRecord {
|
|
59
|
-
id: string;
|
|
60
|
-
type: SubagentType;
|
|
61
|
-
description: string;
|
|
62
|
-
status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error";
|
|
63
|
-
result?: string;
|
|
64
|
-
error?: string;
|
|
65
|
-
toolUses: number;
|
|
66
|
-
startedAt: number;
|
|
67
|
-
completedAt?: number;
|
|
68
|
-
session?: AgentSession;
|
|
69
|
-
abortController?: AbortController;
|
|
70
|
-
promise?: Promise<string>;
|
|
71
|
-
/** Set when result was already consumed via get_subagent_result — suppresses completion notification. */
|
|
72
|
-
resultConsumed?: boolean;
|
|
73
|
-
/** Steering messages queued before the session was ready. */
|
|
74
|
-
pendingSteers?: string[];
|
|
75
|
-
/** Worktree info if the agent is running in an isolated worktree. */
|
|
76
|
-
worktree?: { path: string; branch: string };
|
|
77
|
-
/** Worktree cleanup result after agent completion. */
|
|
78
|
-
worktreeResult?: { hasChanges: boolean; branch?: string };
|
|
79
|
-
/** The tool_use_id from the original Agent tool call. */
|
|
80
|
-
toolCallId?: string;
|
|
81
|
-
/** Path to the persisted session transcript file. */
|
|
82
|
-
outputFile?: string;
|
|
83
|
-
/**
|
|
84
|
-
* Lifetime usage breakdown, accumulated via `message_end` events. Survives
|
|
85
|
-
* compaction. Total = input + output + cacheWrite (cacheRead deliberately
|
|
86
|
-
* excluded — see issue #38). Initialized to zeros at spawn.
|
|
87
|
-
*/
|
|
88
|
-
lifetimeUsage: LifetimeUsage;
|
|
89
|
-
/** Number of times this agent's session has compacted. Initialized to 0 at spawn. */
|
|
90
|
-
compactionCount: number;
|
|
91
|
-
/** Resolved spawn params, captured for UI display. Fixed at spawn time. */
|
|
92
|
-
invocation?: AgentInvocation;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
59
|
export interface AgentInvocation {
|
|
96
60
|
/** Short display name, e.g. "haiku" — only set when different from parent. */
|
|
97
61
|
modelName?: string;
|
|
@@ -119,8 +83,38 @@ export interface NotificationDetails {
|
|
|
119
83
|
|
|
120
84
|
}
|
|
121
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Plain data snapshot of the parent session state captured at spawn time.
|
|
88
|
+
* Replaces live `ExtensionContext` references so queued agents don't read stale state.
|
|
89
|
+
*/
|
|
90
|
+
export interface ParentSnapshot {
|
|
91
|
+
/** Parent working directory. */
|
|
92
|
+
cwd: string;
|
|
93
|
+
/** Parent's effective system prompt (for append-mode agents). */
|
|
94
|
+
systemPrompt: string;
|
|
95
|
+
/** Parent's current model instance (fallback when agent config has no model). */
|
|
96
|
+
model: unknown;
|
|
97
|
+
/** Model registry for resolving config.model strings and creating sessions. */
|
|
98
|
+
modelRegistry: {
|
|
99
|
+
find(provider: string, modelId: string): unknown;
|
|
100
|
+
getAvailable?(): Array<{ provider: string; id: string }>;
|
|
101
|
+
};
|
|
102
|
+
/** Pre-built parent conversation text (when inheritContext was requested). */
|
|
103
|
+
parentContext?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
122
106
|
export interface EnvInfo {
|
|
123
107
|
isGitRepo: boolean;
|
|
124
108
|
branch: string;
|
|
125
109
|
platform: string;
|
|
126
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Narrow shell-exec callback replacing `ExtensionAPI` in `detectEnv()`.
|
|
114
|
+
* Matches the shape of `pi.exec()` without carrying an SDK dependency.
|
|
115
|
+
*/
|
|
116
|
+
export type ShellExec = (
|
|
117
|
+
command: string,
|
|
118
|
+
args: string[],
|
|
119
|
+
options?: { cwd?: string; timeout?: number },
|
|
120
|
+
) => Promise<{ stdout: string; stderr: string; code: number }>;
|
package/src/ui/agent-menu.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import type { SpawnOptions } from "../agent-manager.js";
|
|
6
6
|
import {
|
|
7
7
|
BUILTIN_TOOL_NAMES,
|
|
@@ -21,7 +21,7 @@ export interface AgentMenuManager {
|
|
|
21
21
|
listAgents: () => AgentRecord[];
|
|
22
22
|
getRecord: (id: string) => AgentRecord | undefined;
|
|
23
23
|
/** Used by generate wizard to spawn an agent that writes the .md file. */
|
|
24
|
-
spawnAndWait: (
|
|
24
|
+
spawnAndWait: (ctx: ExtensionContext, type: string, prompt: string, opts: Omit<SpawnOptions, "isBackground">) => Promise<AgentRecord>;
|
|
25
25
|
getMaxConcurrent: () => number;
|
|
26
26
|
setMaxConcurrent: (n: number) => void;
|
|
27
27
|
}
|
|
@@ -487,7 +487,6 @@ Guidelines for choosing settings:
|
|
|
487
487
|
Write the file using the write tool. Only write the file, nothing else.`;
|
|
488
488
|
|
|
489
489
|
const record = await deps.manager.spawnAndWait(
|
|
490
|
-
null,
|
|
491
490
|
ctx,
|
|
492
491
|
"general-purpose",
|
|
493
492
|
generatePrompt,
|