@esso0428/pi-subagents 0.15.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 (98) hide show
  1. package/CHANGELOG.md +638 -0
  2. package/CONTRIBUTING.md +68 -0
  3. package/LICENSE +21 -0
  4. package/README.md +745 -0
  5. package/SECURITY.md +95 -0
  6. package/dist/agent-manager.d.ts +144 -0
  7. package/dist/agent-manager.js +542 -0
  8. package/dist/agent-runner.d.ts +212 -0
  9. package/dist/agent-runner.js +850 -0
  10. package/dist/agent-types.d.ts +67 -0
  11. package/dist/agent-types.js +168 -0
  12. package/dist/context.d.ts +12 -0
  13. package/dist/context.js +56 -0
  14. package/dist/cross-extension-rpc.d.ts +46 -0
  15. package/dist/cross-extension-rpc.js +76 -0
  16. package/dist/custom-agents.d.ts +17 -0
  17. package/dist/custom-agents.js +156 -0
  18. package/dist/default-agents.d.ts +7 -0
  19. package/dist/default-agents.js +122 -0
  20. package/dist/enabled-models.d.ts +49 -0
  21. package/dist/enabled-models.js +145 -0
  22. package/dist/env.d.ts +6 -0
  23. package/dist/env.js +28 -0
  24. package/dist/group-join.d.ts +32 -0
  25. package/dist/group-join.js +116 -0
  26. package/dist/index.d.ts +16 -0
  27. package/dist/index.js +2209 -0
  28. package/dist/invocation-config.d.ts +22 -0
  29. package/dist/invocation-config.js +15 -0
  30. package/dist/memory.d.ts +53 -0
  31. package/dist/memory.js +165 -0
  32. package/dist/model-resolver.d.ts +19 -0
  33. package/dist/model-resolver.js +80 -0
  34. package/dist/nico-overrides.d.ts +53 -0
  35. package/dist/nico-overrides.js +169 -0
  36. package/dist/output-file.d.ts +24 -0
  37. package/dist/output-file.js +101 -0
  38. package/dist/prompts.d.ts +32 -0
  39. package/dist/prompts.js +73 -0
  40. package/dist/schedule-store.d.ts +38 -0
  41. package/dist/schedule-store.js +155 -0
  42. package/dist/schedule.d.ts +109 -0
  43. package/dist/schedule.js +338 -0
  44. package/dist/settings.d.ts +141 -0
  45. package/dist/settings.js +162 -0
  46. package/dist/skill-loader.d.ts +24 -0
  47. package/dist/skill-loader.js +93 -0
  48. package/dist/status-note.d.ts +13 -0
  49. package/dist/status-note.js +24 -0
  50. package/dist/types.d.ts +197 -0
  51. package/dist/types.js +5 -0
  52. package/dist/ui/agent-widget.d.ts +160 -0
  53. package/dist/ui/agent-widget.js +484 -0
  54. package/dist/ui/conversation-viewer.d.ts +57 -0
  55. package/dist/ui/conversation-viewer.js +354 -0
  56. package/dist/ui/fleet-list.d.ts +106 -0
  57. package/dist/ui/fleet-list.js +345 -0
  58. package/dist/ui/schedule-menu.d.ts +16 -0
  59. package/dist/ui/schedule-menu.js +95 -0
  60. package/dist/ui/viewer-keys.d.ts +20 -0
  61. package/dist/ui/viewer-keys.js +17 -0
  62. package/dist/usage.d.ts +50 -0
  63. package/dist/usage.js +49 -0
  64. package/dist/worktree.d.ts +45 -0
  65. package/dist/worktree.js +160 -0
  66. package/examples/agent-tool-description.md +42 -0
  67. package/package.json +56 -0
  68. package/src/agent-manager.ts +631 -0
  69. package/src/agent-runner.ts +1014 -0
  70. package/src/agent-types.ts +202 -0
  71. package/src/context.ts +58 -0
  72. package/src/cross-extension-rpc.ts +122 -0
  73. package/src/custom-agents.ts +167 -0
  74. package/src/default-agents.ts +126 -0
  75. package/src/enabled-models.ts +180 -0
  76. package/src/env.ts +33 -0
  77. package/src/group-join.ts +141 -0
  78. package/src/index.ts +2400 -0
  79. package/src/invocation-config.ts +40 -0
  80. package/src/memory.ts +179 -0
  81. package/src/model-resolver.ts +100 -0
  82. package/src/nico-overrides.ts +235 -0
  83. package/src/output-file.ts +110 -0
  84. package/src/prompts.ts +99 -0
  85. package/src/schedule-store.ts +153 -0
  86. package/src/schedule.ts +365 -0
  87. package/src/settings.ts +288 -0
  88. package/src/skill-loader.ts +102 -0
  89. package/src/status-note.ts +25 -0
  90. package/src/types.ts +208 -0
  91. package/src/ui/agent-widget.ts +566 -0
  92. package/src/ui/conversation-viewer.ts +362 -0
  93. package/src/ui/fleet-list.ts +380 -0
  94. package/src/ui/schedule-menu.ts +104 -0
  95. package/src/ui/viewer-keys.ts +39 -0
  96. package/src/usage.ts +60 -0
  97. package/src/worktree.ts +191 -0
  98. package/vitest.config.ts +18 -0
package/SECURITY.md ADDED
@@ -0,0 +1,95 @@
1
+ # Security Policy
2
+
3
+ This document explains the security model behind `@tintinweb/pi-subagents` and
4
+ where the boundaries are.
5
+
6
+ `pi-subagents` is a [pi](https://pi.dev) extension. It spawns and orchestrates
7
+ autonomous sub-agents that run locally within the same security boundary as the
8
+ user running pi, and inherit pi's trust model. It is the responsibility of the
9
+ user to monitor those agents' operations or to contain them within a container,
10
+ virtual machine, or other sandbox solution.
11
+
12
+ Sub-agents run with the local user account's privileges and can use the tools
13
+ they are granted (reading and writing files, running commands, network access,
14
+ etc.). They treat the local user account and files writable by that account as
15
+ inside the same trust boundary as the pi process itself. If an attacker can
16
+ modify files under the user's home directory, workspace, shell startup files,
17
+ environment, pi configuration, or this extension's configuration, they can
18
+ generally influence pi, its sub-agents, or other local developer tools. Reports
19
+ that depend on such prior local write access are not security vulnerabilities
20
+ unless they demonstrate how `pi-subagents` grants that write access or crosses an
21
+ operating-system privilege boundary.
22
+
23
+ `pi-subagents` relies on the user only loading trustworthy agent definitions
24
+ (`.pi/agents/*.md`, `.agents/agents/*.md`, and global agents), skills, and
25
+ tools, and only using pi within trusted repositories. Files like `AGENTS.md`,
26
+ custom agent frontmatter/system prompts, preloaded skills, or instructions
27
+ embedded in repository content and comments can be used to prompt-inject the
28
+ coding agent and its sub-agents trivially, and this cannot be protected against.
29
+
30
+ ## Reporting a Vulnerability
31
+
32
+ If you believe you found a security vulnerability in `pi-subagents`, please
33
+ report it privately by opening a draft advisory through
34
+ [GitHub Security Advisories](https://github.com/tintinweb/pi-subagents/security/advisories/new)
35
+ for this repository.
36
+
37
+ Please include:
38
+
39
+ - A description of the issue and its impact
40
+ - Steps to reproduce, proof of concept, or relevant logs
41
+ - Affected version, commit, or configuration
42
+ - Any known mitigations
43
+
44
+ Do not open a public issue for security-sensitive reports. Reports will be
45
+ reviewed and disclosure coordinated as appropriate.
46
+
47
+ ## Scope
48
+
49
+ Security issues in the published npm package and the code in this repository are
50
+ in scope — for example, a flaw in `pi-subagents` that crosses an
51
+ operating-system privilege boundary, or that causes the extension to bypass a
52
+ tool restriction, denylist, or agent boundary it claims to enforce.
53
+
54
+ ## Out Of Scope
55
+
56
+ - Local code execution or sandboxing behavior (sub-agents intentionally do not
57
+ have a sandbox and run with the user's privileges)
58
+ - Behavior of pi itself, or of other pi extensions, skills, or tools installed by
59
+ the user (report those to their respective projects)
60
+ - Risks from working in untrusted repositories
61
+ - Risks from installing or loading untrusted agent definitions, skills,
62
+ extensions, packages, or tools
63
+ - Issues caused by non-trustworthy MITM proxies
64
+ - Public internet exposure of a pi installation
65
+ - Prompt injection attacks (including via `AGENTS.md`, agent frontmatter, custom
66
+ system prompts, preloaded skills, repository content, or context inheritance)
67
+ - Exposed secrets that are third-party/user-controlled credentials
68
+ - Reports requiring the ability to create, modify, delete, or replace files,
69
+ directories, symlinks, environment variables, shell configuration, or other
70
+ user-controlled local state on the target machine. This includes `.pi/agents/`,
71
+ `.agents/agents/`, agent and extension configuration, persistent agent memory,
72
+ workspace files, `AGENTS.md`, skills, dotfiles, and files synchronized through NFS, roaming
73
+ profiles, or dotfile managers, unless the report shows how `pi-subagents`
74
+ itself grants that access.
75
+ - Issues caused by intentionally weakened user configuration
76
+ - Resource/DOS claims that require trusted local input/config
77
+ - Reports about malicious model output
78
+ - User-approved or user-initiated local actions presented as vulnerabilities
79
+
80
+ ## Notes for Reporters
81
+
82
+ The most useful reports show a current, reproducible security boundary bypass
83
+ with demonstrated impact. Reports that only show expected local-agent behavior,
84
+ prompt injection, or a malicious trusted agent definition/skill are not security
85
+ vulnerabilities under this model.
86
+
87
+ For example, a report showing that malicious contents written to a trusted agent
88
+ definition or extension configuration cause a sub-agent to execute commands, load
89
+ attacker-controlled tools, or send credentials to an attacker-controlled endpoint
90
+ is out of scope.
91
+
92
+ When possible, include the exact affected path, package version or commit SHA,
93
+ configuration, and a proof of concept against the latest release or latest
94
+ `master`. For dependency reports, include evidence that the shipped dependency is
95
+ affected and that the issue is reachable through `pi-subagents`.
@@ -0,0 +1,144 @@
1
+ /**
2
+ * agent-manager.ts — Tracks agents, background execution, resume support.
3
+ *
4
+ * Background agents are subject to a configurable concurrency limit (default: 4).
5
+ * Excess agents are queued and auto-started as running agents complete.
6
+ * Foreground agents bypass the queue (they block the parent anyway).
7
+ */
8
+ import type { Model } from "@earendil-works/pi-ai";
9
+ import type { AgentSession, ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
10
+ import { type ToolActivity } from "./agent-runner.js";
11
+ import type { AgentInvocation, AgentRecord, IsolationMode, SubagentType, ThinkingLevel } from "./types.js";
12
+ export type OnAgentComplete = (record: AgentRecord) => void;
13
+ export type OnAgentStart = (record: AgentRecord) => void;
14
+ export type OnAgentCompact = (record: AgentRecord, info: CompactionInfo) => void;
15
+ export type CompactionInfo = {
16
+ reason: "manual" | "threshold" | "overflow";
17
+ tokensBefore: number;
18
+ };
19
+ interface SpawnOptions {
20
+ description: string;
21
+ model?: Model<any>;
22
+ maxTurns?: number;
23
+ isolated?: boolean;
24
+ inheritContext?: boolean;
25
+ thinkingLevel?: ThinkingLevel;
26
+ isBackground?: boolean;
27
+ /**
28
+ * Skip the maxConcurrent queue check for this spawn — start immediately even
29
+ * if the configured concurrency limit would otherwise queue it. Used by the
30
+ * scheduler so a fired job can't be deferred past its trigger window.
31
+ */
32
+ bypassQueue?: boolean;
33
+ /** Isolation mode — "worktree" creates a temp git worktree for the agent. */
34
+ isolation?: IsolationMode;
35
+ /**
36
+ * Working directory for the agent (absolute path). Default: parent session
37
+ * cwd. The agent's tools operate here, but .pi config (extensions, skills,
38
+ * settings, memory) still loads from the parent session's project — the
39
+ * target directory's `.pi` extensions never execute. With isolation:
40
+ * "worktree", the worktree is created FROM this directory and the result
41
+ * branch lands in that repo.
42
+ */
43
+ cwd?: string;
44
+ /** Resolved invocation snapshot captured for UI display. */
45
+ invocation?: AgentInvocation;
46
+ /** Parent abort signal — when aborted, the subagent is also stopped. */
47
+ signal?: AbortSignal;
48
+ /** Called on tool start/end with activity info (for streaming progress to UI). */
49
+ onToolActivity?: (activity: ToolActivity) => void;
50
+ /** Called on streaming text deltas from the assistant response. */
51
+ onTextDelta?: (delta: string, fullText: string) => void;
52
+ /** Called when the agent session is created (for accessing session stats). */
53
+ onSessionCreated?: (session: AgentSession) => void;
54
+ /** Called at the end of each agentic turn with the cumulative count. */
55
+ onTurnEnd?: (turnCount: number) => void;
56
+ /** Called once per assistant message_end with that message's usage delta. */
57
+ onAssistantUsage?: (usage: {
58
+ input: number;
59
+ output: number;
60
+ cacheWrite: number;
61
+ }) => void;
62
+ /** Called when the session successfully compacts. */
63
+ onCompaction?: (info: CompactionInfo) => void;
64
+ }
65
+ export declare class AgentManager {
66
+ private agents;
67
+ private cleanupInterval;
68
+ private onComplete?;
69
+ private onStart?;
70
+ private onCompact?;
71
+ private maxConcurrent;
72
+ /** Base repos worktrees were created from — so dispose() can prune them all,
73
+ * not just the parent repo (caller-supplied cwd can target other repos). */
74
+ private worktreeRepos;
75
+ /** Queue of background agents waiting to start. */
76
+ private queue;
77
+ /** Number of currently running background agents. */
78
+ private runningBackground;
79
+ constructor(onComplete?: OnAgentComplete, maxConcurrent?: number, onStart?: OnAgentStart, onCompact?: OnAgentCompact);
80
+ /** Update the max concurrent background agents limit. */
81
+ setMaxConcurrent(n: number): void;
82
+ getMaxConcurrent(): number;
83
+ /**
84
+ * Spawn an agent and return its ID immediately (for background use).
85
+ * If the concurrency limit is reached, the agent is queued.
86
+ */
87
+ spawn(pi: ExtensionAPI, ctx: ExtensionContext, type: SubagentType, prompt: string, options: SpawnOptions): string;
88
+ /** Actually start an agent (called immediately or from queue drain). */
89
+ private startAgent;
90
+ /** Start queued agents up to the concurrency limit. */
91
+ private drainQueue;
92
+ /**
93
+ * Called synchronously right after spawn, before onSessionCreated fires.
94
+ * Lets the caller set up the output file path on the record.
95
+ * The record is guaranteed to be in this.agents at this point.
96
+ */
97
+ private onSpawned?;
98
+ /**
99
+ * Spawn an agent and wait for completion (foreground use).
100
+ * Foreground agents bypass the concurrency queue.
101
+ * Returns { id, record } so callers can access the agent ID.
102
+ *
103
+ * @param onSpawned - Called synchronously after spawn(), before onSessionCreated fires.
104
+ * Use this to set record.outputFile so streamToOutputFile can pick it up.
105
+ */
106
+ spawnAndWait(pi: ExtensionAPI, ctx: ExtensionContext, type: SubagentType, prompt: string, options: Omit<SpawnOptions, "isBackground">, onSpawned?: (id: string) => void): Promise<{
107
+ id: string;
108
+ record: AgentRecord;
109
+ }>;
110
+ /**
111
+ * Resume an existing agent session with a new prompt.
112
+ */
113
+ resume(id: string, prompt: string, signal?: AbortSignal): Promise<AgentRecord | undefined>;
114
+ /**
115
+ * Send a steering message to an agent from the UI (mirrors the steer_subagent
116
+ * tool). A live session delivers it now — it interrupts the agent after its
117
+ * current tool execution and appears as a user message. If the session isn't
118
+ * ready yet, the message is queued on `pendingSteers` and flushed when the
119
+ * session is created. Returns false if the agent can't accept steering
120
+ * (unknown id, or no longer running/queued).
121
+ */
122
+ steer(id: string, message: string): boolean;
123
+ getRecord(id: string): AgentRecord | undefined;
124
+ listAgents(): AgentRecord[];
125
+ abort(id: string): boolean;
126
+ /** Dispose a record's session and remove it from the map. */
127
+ private removeRecord;
128
+ private cleanup;
129
+ /**
130
+ * Remove all completed/stopped/errored records immediately.
131
+ * Called on session start/switch so tasks from a prior session don't persist.
132
+ * Pass skipUnconsumed=true to preserve records the LLM hasn't read yet
133
+ * (resultConsumed=false) — they will be evicted by the 10-minute cleanup timer instead.
134
+ */
135
+ clearCompleted(skipUnconsumed?: boolean): void;
136
+ /** Whether any agents are still running or queued. */
137
+ hasRunning(): boolean;
138
+ /** Abort all running and queued agents immediately. */
139
+ abortAll(): number;
140
+ /** Wait for all running and queued agents to complete (including queued ones). */
141
+ waitForAll(): Promise<void>;
142
+ dispose(): void;
143
+ }
144
+ export {};