@pi-unipi/subagents 2.6.0 → 2.6.2
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 +89 -78
- package/agents/delegate.md +14 -0
- package/agents/oracle.md +78 -0
- package/agents/researcher.md +52 -0
- package/agents/reviewer.md +79 -0
- package/agents/scout.md +50 -0
- package/agents/worker.md +59 -0
- package/package.json +19 -17
- package/prompts/council.md +48 -0
- package/prompts/gather-context-and-clarify.md +13 -0
- package/prompts/parallel-cleanup.md +59 -0
- package/prompts/parallel-research.md +50 -0
- package/prompts/parallel-review.md +54 -0
- package/prompts/review-loop.md +43 -0
- package/skills/council-mode/SKILL.md +230 -0
- package/skills/subagents/SKILL.md +49 -0
- package/skills/subagents/references/constraints-and-recipes.md +259 -0
- package/skills/subagents/references/execution-controls.md +454 -0
- package/skills/subagents/references/management-authoring-rpc.md +161 -0
- package/skills/subagents/references/multi-lane-orchestration.md +39 -0
- package/skills/subagents/references/prompting-and-roles.md +267 -0
- package/src/acceptance.ts +331 -0
- package/src/agent-manager.ts +405 -0
- package/src/agent-memory.ts +300 -0
- package/src/agent-overrides.ts +183 -0
- package/src/agent-runner.ts +265 -0
- package/src/async-runner.ts +417 -0
- package/src/authority-policy.ts +47 -0
- package/src/budgets.ts +285 -0
- package/src/child-safety.ts +140 -0
- package/src/config.ts +226 -0
- package/src/conversation-viewer.ts +281 -0
- package/src/core-compat.ts +94 -0
- package/src/custom-agents.ts +323 -0
- package/src/file-system-retry.ts +50 -0
- package/src/fleet-data.ts +61 -0
- package/src/fleet-view.ts +316 -0
- package/src/foreground-detach.ts +59 -0
- package/src/fork-context.ts +285 -0
- package/src/global.d.ts +7 -0
- package/src/guide.ts +129 -0
- package/src/index.ts +1149 -0
- package/src/mission-state.ts +133 -0
- package/src/mission-store.ts +434 -0
- package/src/model-resolver.ts +79 -0
- package/src/output-limits.ts +142 -0
- package/src/parity-types.ts +315 -0
- package/src/pi-args.ts +161 -0
- package/src/pi-spawn.ts +147 -0
- package/src/result-files.ts +232 -0
- package/src/result-watcher.ts +221 -0
- package/src/retained-children.ts +176 -0
- package/src/run-fanout-budget.ts +356 -0
- package/src/scheduled-runs.ts +351 -0
- package/src/schemas.ts +263 -0
- package/src/slash-commands.ts +77 -0
- package/src/supervisor-channel.ts +249 -0
- package/src/tool-handler.ts +1144 -0
- package/src/types.ts +238 -0
- package/src/widget.ts +447 -0
- package/src/workflow-script.ts +737 -0
- package/src/workflow-worker.ts +384 -0
- package/src/worktree.ts +614 -0
- package/dist/agent-manager.d.ts +0 -81
- package/dist/agent-manager.d.ts.map +0 -1
- package/dist/agent-manager.js +0 -295
- package/dist/agent-manager.js.map +0 -1
- package/dist/agent-runner.d.ts +0 -51
- package/dist/agent-runner.d.ts.map +0 -1
- package/dist/agent-runner.js +0 -262
- package/dist/agent-runner.js.map +0 -1
- package/dist/config.d.ts +0 -24
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -132
- package/dist/config.js.map +0 -1
- package/dist/conversation-viewer.d.ts +0 -40
- package/dist/conversation-viewer.d.ts.map +0 -1
- package/dist/conversation-viewer.js +0 -276
- package/dist/conversation-viewer.js.map +0 -1
- package/dist/core-compat.d.ts +0 -21
- package/dist/core-compat.d.ts.map +0 -1
- package/dist/core-compat.js +0 -86
- package/dist/core-compat.js.map +0 -1
- package/dist/custom-agents.d.ts +0 -14
- package/dist/custom-agents.d.ts.map +0 -1
- package/dist/custom-agents.js +0 -113
- package/dist/custom-agents.js.map +0 -1
- package/dist/file-lock.d.ts +0 -42
- package/dist/file-lock.d.ts.map +0 -1
- package/dist/file-lock.js +0 -91
- package/dist/file-lock.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -758
- package/dist/index.js.map +0 -1
- package/dist/model-resolver.d.ts +0 -19
- package/dist/model-resolver.d.ts.map +0 -1
- package/dist/model-resolver.js +0 -61
- package/dist/model-resolver.js.map +0 -1
- package/dist/types.d.ts +0 -98
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -47
- package/dist/types.js.map +0 -1
- package/dist/widget.d.ts +0 -56
- package/dist/widget.d.ts.map +0 -1
- package/dist/widget.js +0 -396
- package/dist/widget.js.map +0 -1
package/dist/custom-agents.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Custom agent loader
|
|
3
|
-
*
|
|
4
|
-
* Discovers agent types from:
|
|
5
|
-
* - <workspace>/.unipi/config/agents/*.md (project, highest priority)
|
|
6
|
-
* - ~/.unipi/config/agents/*.md (global)
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, readdirSync, readFileSync, renameSync } from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
import { homedir } from "node:os";
|
|
11
|
-
import { parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
function compareCodeUnits(a, b) {
|
|
13
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
14
|
-
}
|
|
15
|
-
/** Backup a corrupted file by renaming to .bak */
|
|
16
|
-
function backupCorrupted(filePath) {
|
|
17
|
-
const backupPath = filePath + ".bak";
|
|
18
|
-
try {
|
|
19
|
-
renameSync(filePath, backupPath);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
// If backup fails, just leave it
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/** Get project agents directory. */
|
|
26
|
-
function getProjectAgentsDir(cwd) {
|
|
27
|
-
return join(cwd, ".unipi", "config", "agents");
|
|
28
|
-
}
|
|
29
|
-
/** Get global agents directory. */
|
|
30
|
-
function getGlobalAgentsDir() {
|
|
31
|
-
return join(homedir(), ".unipi", "config", "agents");
|
|
32
|
-
}
|
|
33
|
-
/** All known built-in tool names. */
|
|
34
|
-
const BUILTIN_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
35
|
-
/**
|
|
36
|
-
* Load a single agent from a .md file.
|
|
37
|
-
*/
|
|
38
|
-
function loadAgentFromFile(filePath, source) {
|
|
39
|
-
try {
|
|
40
|
-
const content = readFileSync(filePath, "utf-8");
|
|
41
|
-
const { frontmatter, body } = parseFrontmatter(content);
|
|
42
|
-
if (!frontmatter || typeof frontmatter !== "object") {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const name = filePath.split("/").pop()?.replace(/\.md$/, "") ?? "unknown";
|
|
46
|
-
// Parse tools from comma-separated string
|
|
47
|
-
const toolsStr = frontmatter.tools;
|
|
48
|
-
const builtinToolNames = toolsStr
|
|
49
|
-
? toolsStr.split(",").map((t) => t.trim()).filter((t) => BUILTIN_TOOL_NAMES.includes(t))
|
|
50
|
-
: [...BUILTIN_TOOL_NAMES];
|
|
51
|
-
return {
|
|
52
|
-
name,
|
|
53
|
-
displayName: frontmatter.display_name,
|
|
54
|
-
description: frontmatter.description ?? `${name} agent`,
|
|
55
|
-
builtinToolNames,
|
|
56
|
-
disallowedTools: frontmatter.disallowed_tools
|
|
57
|
-
?.split(",")
|
|
58
|
-
.map((t) => t.trim()),
|
|
59
|
-
extensions: frontmatter.extensions !== false,
|
|
60
|
-
skills: frontmatter.skills !== false,
|
|
61
|
-
model: frontmatter.model,
|
|
62
|
-
thinking: frontmatter.thinking,
|
|
63
|
-
maxTurns: frontmatter.max_turns,
|
|
64
|
-
systemPrompt: body.trim(),
|
|
65
|
-
promptMode: frontmatter.prompt_mode ?? "replace",
|
|
66
|
-
inheritContext: frontmatter.inherit_context,
|
|
67
|
-
runInBackground: frontmatter.run_in_background,
|
|
68
|
-
isolated: frontmatter.isolated,
|
|
69
|
-
enabled: frontmatter.enabled !== false,
|
|
70
|
-
source,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
// Corrupted file — backup and skip
|
|
75
|
-
backupCorrupted(filePath);
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Load all custom agents from project and global directories.
|
|
81
|
-
* Project agents override global agents with the same name.
|
|
82
|
-
*/
|
|
83
|
-
export function loadCustomAgents(cwd) {
|
|
84
|
-
const agents = new Map();
|
|
85
|
-
// Load global agents first
|
|
86
|
-
const globalDir = getGlobalAgentsDir();
|
|
87
|
-
if (existsSync(globalDir)) {
|
|
88
|
-
const files = readdirSync(globalDir)
|
|
89
|
-
.filter((f) => f.endsWith(".md"))
|
|
90
|
-
.sort(compareCodeUnits);
|
|
91
|
-
for (const file of files) {
|
|
92
|
-
const agent = loadAgentFromFile(join(globalDir, file), "global");
|
|
93
|
-
if (agent) {
|
|
94
|
-
agents.set(agent.name, agent);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// Load project agents (overrides global)
|
|
99
|
-
const projectDir = getProjectAgentsDir(cwd);
|
|
100
|
-
if (existsSync(projectDir)) {
|
|
101
|
-
const files = readdirSync(projectDir)
|
|
102
|
-
.filter((f) => f.endsWith(".md"))
|
|
103
|
-
.sort(compareCodeUnits);
|
|
104
|
-
for (const file of files) {
|
|
105
|
-
const agent = loadAgentFromFile(join(projectDir, file), "project");
|
|
106
|
-
if (agent) {
|
|
107
|
-
agents.set(agent.name, agent);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return agents;
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=custom-agents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-agents.js","sourceRoot":"","sources":["../src/custom-agents.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAA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AAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;YACnE,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/file-lock.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Per-file transparent locking
|
|
3
|
-
*
|
|
4
|
-
* Agents never see lock errors. Write tool queues internally.
|
|
5
|
-
* Per-file granularity: locking src/auth.ts doesn't block src/login.ts.
|
|
6
|
-
*/
|
|
7
|
-
export declare class FileLock {
|
|
8
|
-
/** Active locks by file path. */
|
|
9
|
-
private locks;
|
|
10
|
-
/** Queue of waiting acquires per file path. */
|
|
11
|
-
private queues;
|
|
12
|
-
/**
|
|
13
|
-
* Acquire a lock on a file. Blocks until available.
|
|
14
|
-
* Returns a release function.
|
|
15
|
-
*
|
|
16
|
-
* @param filePath - Absolute path to the file
|
|
17
|
-
* @param agentId - ID of the agent requesting the lock
|
|
18
|
-
* @returns Release function — call when done writing
|
|
19
|
-
*/
|
|
20
|
-
acquire(filePath: string, agentId: string): Promise<() => void>;
|
|
21
|
-
/**
|
|
22
|
-
* Check if a file is currently locked.
|
|
23
|
-
*/
|
|
24
|
-
isLocked(filePath: string): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Get the agent that holds a lock on a file.
|
|
27
|
-
*/
|
|
28
|
-
getHolder(filePath: string): string | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Get count of locked files.
|
|
31
|
-
*/
|
|
32
|
-
get lockCount(): number;
|
|
33
|
-
/**
|
|
34
|
-
* Release all locks held by an agent (on abort).
|
|
35
|
-
*/
|
|
36
|
-
releaseAll(agentId: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Clear all locks (on shutdown).
|
|
39
|
-
*/
|
|
40
|
-
clear(): void;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=file-lock.d.ts.map
|
package/dist/file-lock.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,qBAAa,QAAQ;IACnB,iCAAiC;IACjC,OAAO,CAAC,KAAK,CAAoC;IACjD,+CAA+C;IAC/C,OAAO,CAAC,MAAM,CAAwC;IAEtD;;;;;;;OAOG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAoCrE;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAInC;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI/C;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQjC;;OAEG;IACH,KAAK,IAAI,IAAI;CAOd"}
|
package/dist/file-lock.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Per-file transparent locking
|
|
3
|
-
*
|
|
4
|
-
* Agents never see lock errors. Write tool queues internally.
|
|
5
|
-
* Per-file granularity: locking src/auth.ts doesn't block src/login.ts.
|
|
6
|
-
*/
|
|
7
|
-
export class FileLock {
|
|
8
|
-
/** Active locks by file path. */
|
|
9
|
-
locks = new Map();
|
|
10
|
-
/** Queue of waiting acquires per file path. */
|
|
11
|
-
queues = new Map();
|
|
12
|
-
/**
|
|
13
|
-
* Acquire a lock on a file. Blocks until available.
|
|
14
|
-
* Returns a release function.
|
|
15
|
-
*
|
|
16
|
-
* @param filePath - Absolute path to the file
|
|
17
|
-
* @param agentId - ID of the agent requesting the lock
|
|
18
|
-
* @returns Release function — call when done writing
|
|
19
|
-
*/
|
|
20
|
-
async acquire(filePath, agentId) {
|
|
21
|
-
// Wait for existing lock
|
|
22
|
-
while (this.locks.has(filePath)) {
|
|
23
|
-
await new Promise((resolve) => {
|
|
24
|
-
const queue = this.queues.get(filePath) ?? [];
|
|
25
|
-
queue.push(resolve);
|
|
26
|
-
this.queues.set(filePath, queue);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// Create lock entry
|
|
30
|
-
let releaseFn;
|
|
31
|
-
const promise = new Promise((resolve) => {
|
|
32
|
-
releaseFn = () => {
|
|
33
|
-
this.locks.delete(filePath);
|
|
34
|
-
resolve();
|
|
35
|
-
// Wake next waiter
|
|
36
|
-
const queue = this.queues.get(filePath);
|
|
37
|
-
if (queue && queue.length > 0) {
|
|
38
|
-
const next = queue.shift();
|
|
39
|
-
next();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
const entry = {
|
|
44
|
-
agentId,
|
|
45
|
-
filePath,
|
|
46
|
-
promise,
|
|
47
|
-
release: releaseFn,
|
|
48
|
-
};
|
|
49
|
-
this.locks.set(filePath, entry);
|
|
50
|
-
return releaseFn;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check if a file is currently locked.
|
|
54
|
-
*/
|
|
55
|
-
isLocked(filePath) {
|
|
56
|
-
return this.locks.has(filePath);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get the agent that holds a lock on a file.
|
|
60
|
-
*/
|
|
61
|
-
getHolder(filePath) {
|
|
62
|
-
return this.locks.get(filePath)?.agentId;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get count of locked files.
|
|
66
|
-
*/
|
|
67
|
-
get lockCount() {
|
|
68
|
-
return this.locks.size;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Release all locks held by an agent (on abort).
|
|
72
|
-
*/
|
|
73
|
-
releaseAll(agentId) {
|
|
74
|
-
for (const [filePath, entry] of this.locks) {
|
|
75
|
-
if (entry.agentId === agentId) {
|
|
76
|
-
entry.release();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Clear all locks (on shutdown).
|
|
82
|
-
*/
|
|
83
|
-
clear() {
|
|
84
|
-
for (const entry of this.locks.values()) {
|
|
85
|
-
entry.release();
|
|
86
|
-
}
|
|
87
|
-
this.locks.clear();
|
|
88
|
-
this.queues.clear();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=file-lock.js.map
|
package/dist/file-lock.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,OAAO,QAAQ;IACnB,iCAAiC;IACzB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACjD,+CAA+C;IACvC,MAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEtD;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,OAAe;QAC7C,yBAAyB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAClC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC9C,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,oBAAoB;QACpB,IAAI,SAAqB,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,OAAO,CAA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AED;;OAEG;IACH,KAAK;QACH,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Extension entry
|
|
3
|
-
*
|
|
4
|
-
* Tools: spawn_helper, get_helper_result
|
|
5
|
-
* Features: renderCall/renderResult, message renderer, conversation viewer
|
|
6
|
-
* ESC propagation: all children abort on parent ESC
|
|
7
|
-
*/
|
|
8
|
-
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
|
-
export default function (pi: ExtensionAPI): void;
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAqHhF,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QA8uBxC"}
|