ultimate-pi 0.3.1 → 0.4.1
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/.agents/skills/harness-decisions/SKILL.md +37 -0
- package/.agents/skills/harness-governor/SKILL.md +1 -1
- package/.agents/skills/harness-orchestration/SKILL.md +54 -0
- package/.agents/skills/harness-plan/SKILL.md +4 -3
- package/.agents/skills/harness-sentrux-setup/SKILL.md +57 -0
- package/.agents/skills/scrapling-web/SKILL.md +93 -0
- package/.pi/PACKAGING.md +1 -0
- package/.pi/SYSTEM.md +13 -15
- package/.pi/agents/harness/adversary.md +3 -0
- package/.pi/agents/harness/evaluator.md +3 -0
- package/.pi/agents/harness/executor.md +4 -1
- package/.pi/agents/harness/meta-optimizer.md +2 -1
- package/.pi/agents/harness/planner.md +22 -1
- package/.pi/agents/harness/sentrux-bootstrap.md +42 -0
- package/.pi/agents/harness/tie-breaker.md +2 -0
- package/.pi/extensions/harness-ask-user.ts +74 -0
- package/.pi/extensions/harness-subagents.ts +9 -0
- package/.pi/extensions/lib/ask-user/dialog.ts +260 -0
- package/.pi/extensions/lib/ask-user/fallback.ts +78 -0
- package/.pi/extensions/lib/ask-user/render.ts +66 -0
- package/.pi/extensions/lib/ask-user/schema.ts +69 -0
- package/.pi/extensions/lib/ask-user/types.ts +41 -0
- package/.pi/extensions/lib/ask-user/validate-core.mjs +79 -0
- package/.pi/extensions/lib/ask-user/validate.ts +92 -0
- package/.pi/extensions/lib/harness-subagents/agent-loader.ts +126 -0
- package/.pi/extensions/lib/harness-subagents/agent-manifest.ts +119 -0
- package/.pi/extensions/lib/harness-subagents/agent-parser.ts +87 -0
- package/.pi/extensions/lib/harness-subagents/blackboard-tool.ts +118 -0
- package/.pi/extensions/lib/harness-subagents/blackboard.ts +175 -0
- package/.pi/extensions/lib/harness-subagents/spawn-policy.ts +27 -0
- package/.pi/extensions/lib/harness-subagents/types-blackboard.ts +27 -0
- package/.pi/extensions/lib/harness-subagents/vendored/agent-manager.ts +553 -0
- package/.pi/extensions/lib/harness-subagents/vendored/agent-runner.ts +637 -0
- package/.pi/extensions/lib/harness-subagents/vendored/agent-types.ts +175 -0
- package/.pi/extensions/lib/harness-subagents/vendored/context.ts +59 -0
- package/.pi/extensions/lib/harness-subagents/vendored/cross-extension-rpc.ts +134 -0
- package/.pi/extensions/lib/harness-subagents/vendored/custom-agents.ts +5 -0
- package/.pi/extensions/lib/harness-subagents/vendored/default-agents.ts +123 -0
- package/.pi/extensions/lib/harness-subagents/vendored/env.ts +43 -0
- package/.pi/extensions/lib/harness-subagents/vendored/group-join.ts +144 -0
- package/.pi/extensions/lib/harness-subagents/vendored/index.ts +2447 -0
- package/.pi/extensions/lib/harness-subagents/vendored/invocation-config.ts +52 -0
- package/.pi/extensions/lib/harness-subagents/vendored/memory.ts +182 -0
- package/.pi/extensions/lib/harness-subagents/vendored/model-resolver.ts +92 -0
- package/.pi/extensions/lib/harness-subagents/vendored/output-file.ts +115 -0
- package/.pi/extensions/lib/harness-subagents/vendored/prompts.ts +103 -0
- package/.pi/extensions/lib/harness-subagents/vendored/schedule-store.ts +177 -0
- package/.pi/extensions/lib/harness-subagents/vendored/schedule.ts +416 -0
- package/.pi/extensions/lib/harness-subagents/vendored/settings.ts +210 -0
- package/.pi/extensions/lib/harness-subagents/vendored/skill-loader.ts +108 -0
- package/.pi/extensions/lib/harness-subagents/vendored/types.ts +187 -0
- package/.pi/extensions/lib/harness-subagents/vendored/ui/agent-widget.ts +637 -0
- package/.pi/extensions/lib/harness-subagents/vendored/ui/conversation-viewer.ts +324 -0
- package/.pi/extensions/lib/harness-subagents/vendored/ui/schedule-menu.ts +110 -0
- package/.pi/extensions/lib/harness-subagents/vendored/usage.ts +71 -0
- package/.pi/extensions/lib/harness-subagents/vendored/worktree.ts +195 -0
- package/.pi/extensions/lib/harness-vcc-settings.ts +50 -0
- package/.pi/extensions/ultimate-pi-vcc.ts +17 -0
- package/.pi/harness/README.md +2 -1
- package/.pi/harness/agents.manifest.json +80 -0
- package/.pi/harness/docs/adrs/0009-sentrux-rules-lifecycle.md +9 -5
- package/.pi/harness/docs/adrs/0030-inhouse-vcc-compaction.md +40 -0
- package/.pi/harness/docs/adrs/README.md +1 -0
- package/.pi/harness/env.harness.template +28 -0
- package/.pi/harness/sentrux/architecture.manifest.json +6 -1
- package/.pi/prompts/harness-auto.md +2 -2
- package/.pi/prompts/harness-plan.md +2 -2
- package/.pi/prompts/harness-router-tune.md +2 -2
- package/.pi/prompts/harness-run.md +1 -0
- package/.pi/prompts/harness-setup.md +179 -340
- package/.pi/scripts/README.md +6 -1
- package/.pi/scripts/harness-agents-manifest.mjs +123 -0
- package/.pi/scripts/harness-cli-verify.sh +60 -11
- package/.pi/scripts/harness-generate-model-router.mjs +242 -0
- package/.pi/scripts/harness-graphify-bootstrap.sh +1 -6
- package/.pi/scripts/harness-resolve-up-pkg.mjs +71 -0
- package/.pi/scripts/harness-seed-project-contracts.mjs +33 -1
- package/.pi/scripts/harness-sentrux-bootstrap.mjs +146 -0
- package/.pi/scripts/harness-sync-env.mjs +148 -0
- package/.pi/scripts/harness-verify.mjs +19 -0
- package/.pi/scripts/harness-web-search.md +33 -0
- package/.pi/scripts/harness-web.py +177 -0
- package/.pi/scripts/harness_web/__init__.py +1 -0
- package/.pi/scripts/harness_web/config.py +80 -0
- package/.pi/scripts/harness_web/output.py +55 -0
- package/.pi/scripts/harness_web/scrape.py +120 -0
- package/.pi/scripts/harness_web/search_ddg.py +106 -0
- package/.pi/scripts/release.sh +338 -0
- package/.pi/scripts/sentrux-rules-sync.mjs +29 -7
- package/.pi/scripts/vendor-pi-vcc-settings.stub.ts +8 -0
- package/.pi/scripts/vendor-sync-pi-vcc.sh +40 -0
- package/.pi/settings.example.json +1 -7
- package/.sentrux/rules.toml +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +14 -0
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/package.json +16 -12
- package/vendor/pi-vcc/README.md +215 -0
- package/vendor/pi-vcc/UPSTREAM_PIN.md +12 -0
- package/vendor/pi-vcc/demo.gif +0 -0
- package/vendor/pi-vcc/index.ts +12 -0
- package/vendor/pi-vcc/package.json +26 -0
- package/vendor/pi-vcc/scripts/audit-sessions.ts +88 -0
- package/vendor/pi-vcc/scripts/benchmark-real-sessions.ts +25 -0
- package/vendor/pi-vcc/scripts/compare-before-after.ts +36 -0
- package/vendor/pi-vcc/scripts/dump-branch-output.ts +20 -0
- package/vendor/pi-vcc/src/commands/pi-vcc.ts +36 -0
- package/vendor/pi-vcc/src/commands/vcc-recall.ts +65 -0
- package/vendor/pi-vcc/src/core/brief.ts +381 -0
- package/vendor/pi-vcc/src/core/build-sections.ts +79 -0
- package/vendor/pi-vcc/src/core/content.ts +60 -0
- package/vendor/pi-vcc/src/core/filter-noise.ts +42 -0
- package/vendor/pi-vcc/src/core/format-recall.ts +27 -0
- package/vendor/pi-vcc/src/core/format.ts +49 -0
- package/vendor/pi-vcc/src/core/lineage.ts +26 -0
- package/vendor/pi-vcc/src/core/load-messages.ts +41 -0
- package/vendor/pi-vcc/src/core/normalize.ts +66 -0
- package/vendor/pi-vcc/src/core/recall-scope.ts +14 -0
- package/vendor/pi-vcc/src/core/render-entries.ts +55 -0
- package/vendor/pi-vcc/src/core/report.ts +237 -0
- package/vendor/pi-vcc/src/core/sanitize.ts +5 -0
- package/vendor/pi-vcc/src/core/search-entries.ts +221 -0
- package/vendor/pi-vcc/src/core/settings.ts +8 -0
- package/vendor/pi-vcc/src/core/skill-collapse.ts +35 -0
- package/vendor/pi-vcc/src/core/summarize.ts +157 -0
- package/vendor/pi-vcc/src/core/tool-args.ts +14 -0
- package/vendor/pi-vcc/src/details.ts +7 -0
- package/vendor/pi-vcc/src/extract/commits.ts +69 -0
- package/vendor/pi-vcc/src/extract/files.ts +80 -0
- package/vendor/pi-vcc/src/extract/goals.ts +79 -0
- package/vendor/pi-vcc/src/extract/preferences.ts +55 -0
- package/vendor/pi-vcc/src/hooks/before-compact.ts +314 -0
- package/vendor/pi-vcc/src/sections.ts +12 -0
- package/vendor/pi-vcc/src/tools/recall.ts +109 -0
- package/vendor/pi-vcc/src/types.ts +14 -0
- package/vendor/pi-vcc/tests/before-compact-hook.test.ts +204 -0
- package/vendor/pi-vcc/tests/before-compact.test.ts +145 -0
- package/vendor/pi-vcc/tests/brief.test.ts +206 -0
- package/vendor/pi-vcc/tests/build-sections.test.ts +59 -0
- package/vendor/pi-vcc/tests/compile.test.ts +80 -0
- package/vendor/pi-vcc/tests/content.test.ts +31 -0
- package/vendor/pi-vcc/tests/extract-goals.test.ts +86 -0
- package/vendor/pi-vcc/tests/extract-preferences.test.ts +30 -0
- package/vendor/pi-vcc/tests/filter-noise.test.ts +61 -0
- package/vendor/pi-vcc/tests/fixtures.ts +61 -0
- package/vendor/pi-vcc/tests/format-recall.test.ts +30 -0
- package/vendor/pi-vcc/tests/format.test.ts +62 -0
- package/vendor/pi-vcc/tests/lineage.test.ts +33 -0
- package/vendor/pi-vcc/tests/load-messages.test.ts +51 -0
- package/vendor/pi-vcc/tests/normalize.test.ts +97 -0
- package/vendor/pi-vcc/tests/real-sessions.test.ts +38 -0
- package/vendor/pi-vcc/tests/recall-expand.test.ts +15 -0
- package/vendor/pi-vcc/tests/recall-scope.test.ts +32 -0
- package/vendor/pi-vcc/tests/recall-tool-scope.test.ts +67 -0
- package/vendor/pi-vcc/tests/render-entries.test.ts +62 -0
- package/vendor/pi-vcc/tests/report.test.ts +44 -0
- package/vendor/pi-vcc/tests/sanitize.test.ts +24 -0
- package/vendor/pi-vcc/tests/search-entries.test.ts +144 -0
- package/vendor/pi-vcc/tests/support/load-session.ts +23 -0
- package/vendor/pi-vcc/tests/support/real-sessions.ts +51 -0
- package/.agents/skills/firecrawl/SKILL.md +0 -150
- package/.agents/skills/firecrawl/rules/install.md +0 -82
- package/.agents/skills/firecrawl/rules/security.md +0 -26
- package/.agents/skills/firecrawl-agent/SKILL.md +0 -57
- package/.agents/skills/firecrawl-build-interact/SKILL.md +0 -67
- package/.agents/skills/firecrawl-build-onboarding/SKILL.md +0 -102
- package/.agents/skills/firecrawl-build-onboarding/references/auth-flow.md +0 -39
- package/.agents/skills/firecrawl-build-onboarding/references/project-setup.md +0 -20
- package/.agents/skills/firecrawl-build-onboarding/references/sdk-installation.md +0 -17
- package/.agents/skills/firecrawl-build-scrape/SKILL.md +0 -68
- package/.agents/skills/firecrawl-build-search/SKILL.md +0 -68
- package/.agents/skills/firecrawl-crawl/SKILL.md +0 -58
- package/.agents/skills/firecrawl-download/SKILL.md +0 -69
- package/.agents/skills/firecrawl-interact/SKILL.md +0 -83
- package/.agents/skills/firecrawl-map/SKILL.md +0 -50
- package/.agents/skills/firecrawl-parse/SKILL.md +0 -61
- package/.agents/skills/firecrawl-scrape/SKILL.md +0 -68
- package/.agents/skills/firecrawl-search/SKILL.md +0 -59
- package/.pi/pi-vcc-config.json +0 -4
- package/firecrawl/.env.template +0 -62
- package/firecrawl/README.md +0 -49
- package/firecrawl/docker-compose.yaml +0 -201
- package/firecrawl/searxng/searxng.env +0 -3
- package/firecrawl/searxng/settings.yml +0 -85
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Persistence for pi-subagents operational settings.
|
|
2
|
+
// - Global: ~/.pi/agent/subagents.json (via getAgentDir()) — manual defaults, never written here
|
|
3
|
+
// - Project: <cwd>/.pi/subagents.json — written by /agents → Settings; overrides global on load
|
|
4
|
+
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { getAgentDir } from "@mariozechner/pi-coding-agent";
|
|
8
|
+
import type { JoinMode } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export interface SubagentsSettings {
|
|
11
|
+
maxConcurrent?: number;
|
|
12
|
+
/**
|
|
13
|
+
* 0 = unlimited — the extension's single source of truth for that convention:
|
|
14
|
+
* `normalizeMaxTurns()` in agent-runner.ts treats 0 → `undefined`, and the
|
|
15
|
+
* `/agents` → Settings input prompt explicitly says "0 = unlimited".
|
|
16
|
+
*/
|
|
17
|
+
defaultMaxTurns?: number;
|
|
18
|
+
graceTurns?: number;
|
|
19
|
+
defaultJoinMode?: JoinMode;
|
|
20
|
+
/**
|
|
21
|
+
* Master switch for the schedule subagent feature. Defaults to `true`.
|
|
22
|
+
* When `false`: the `Agent` tool's `schedule` param + its guideline are
|
|
23
|
+
* stripped from the tool spec at registration (zero LLM-context cost), the
|
|
24
|
+
* scheduler doesn't bind to the session, and the `/agents → Scheduled jobs`
|
|
25
|
+
* menu entry is hidden. Schema-level removal applies at extension load
|
|
26
|
+
* (next pi session); runtime menu/runtime-fire short-circuit is immediate.
|
|
27
|
+
*/
|
|
28
|
+
schedulingEnabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Setter hooks used by applySettings to wire persisted values into in-memory state. */
|
|
32
|
+
export interface SettingsAppliers {
|
|
33
|
+
setMaxConcurrent: (n: number) => void;
|
|
34
|
+
setDefaultMaxTurns: (n: number) => void;
|
|
35
|
+
setGraceTurns: (n: number) => void;
|
|
36
|
+
setDefaultJoinMode: (mode: JoinMode) => void;
|
|
37
|
+
setSchedulingEnabled: (b: boolean) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Emit callback — a subset of `pi.events.emit` to keep helpers testable. */
|
|
41
|
+
export type SettingsEmit = (event: string, payload: unknown) => void;
|
|
42
|
+
|
|
43
|
+
const VALID_JOIN_MODES: ReadonlySet<string> = new Set<JoinMode>([
|
|
44
|
+
"async",
|
|
45
|
+
"group",
|
|
46
|
+
"smart",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
// Sanity ceilings — prevent hand-edited configs from asking for values that
|
|
50
|
+
// make no operational sense (e.g. 1e6 concurrent subagents). Permissive enough
|
|
51
|
+
// that any realistic power-user setting passes through.
|
|
52
|
+
const MAX_CONCURRENT_CEILING = 1024;
|
|
53
|
+
const MAX_TURNS_CEILING = 10_000;
|
|
54
|
+
const GRACE_TURNS_CEILING = 1_000;
|
|
55
|
+
|
|
56
|
+
/** Drop fields that don't match the expected shape. Silent — garbage becomes absent. */
|
|
57
|
+
function sanitize(raw: unknown): SubagentsSettings {
|
|
58
|
+
if (!raw || typeof raw !== "object") return {};
|
|
59
|
+
const r = raw as Record<string, unknown>;
|
|
60
|
+
const out: SubagentsSettings = {};
|
|
61
|
+
if (
|
|
62
|
+
Number.isInteger(r.maxConcurrent) &&
|
|
63
|
+
(r.maxConcurrent as number) >= 1 &&
|
|
64
|
+
(r.maxConcurrent as number) <= MAX_CONCURRENT_CEILING
|
|
65
|
+
) {
|
|
66
|
+
out.maxConcurrent = r.maxConcurrent as number;
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
Number.isInteger(r.defaultMaxTurns) &&
|
|
70
|
+
(r.defaultMaxTurns as number) >= 0 &&
|
|
71
|
+
(r.defaultMaxTurns as number) <= MAX_TURNS_CEILING
|
|
72
|
+
) {
|
|
73
|
+
out.defaultMaxTurns = r.defaultMaxTurns as number;
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
Number.isInteger(r.graceTurns) &&
|
|
77
|
+
(r.graceTurns as number) >= 1 &&
|
|
78
|
+
(r.graceTurns as number) <= GRACE_TURNS_CEILING
|
|
79
|
+
) {
|
|
80
|
+
out.graceTurns = r.graceTurns as number;
|
|
81
|
+
}
|
|
82
|
+
if (
|
|
83
|
+
typeof r.defaultJoinMode === "string" &&
|
|
84
|
+
VALID_JOIN_MODES.has(r.defaultJoinMode)
|
|
85
|
+
) {
|
|
86
|
+
out.defaultJoinMode = r.defaultJoinMode as JoinMode;
|
|
87
|
+
}
|
|
88
|
+
if (typeof r.schedulingEnabled === "boolean") {
|
|
89
|
+
out.schedulingEnabled = r.schedulingEnabled;
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function globalPath(): string {
|
|
95
|
+
return join(getAgentDir(), "subagents.json");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function projectPath(cwd: string): string {
|
|
99
|
+
return join(cwd, ".pi", "subagents.json");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Read a settings file. Missing file is silent (returns `{}`). A file that
|
|
104
|
+
* exists but can't be parsed emits a warning to stderr so users aren't
|
|
105
|
+
* silently reverted to defaults — and still returns `{}` so startup proceeds.
|
|
106
|
+
*/
|
|
107
|
+
function readSettingsFile(path: string): SubagentsSettings {
|
|
108
|
+
if (!existsSync(path)) return {};
|
|
109
|
+
try {
|
|
110
|
+
return sanitize(JSON.parse(readFileSync(path, "utf-8")));
|
|
111
|
+
} catch (err) {
|
|
112
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
113
|
+
console.warn(
|
|
114
|
+
`[pi-subagents] Ignoring malformed settings at ${path}: ${reason}`,
|
|
115
|
+
);
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Load merged settings: global provides defaults, project overrides. */
|
|
121
|
+
export function loadSettings(cwd: string = process.cwd()): SubagentsSettings {
|
|
122
|
+
return {
|
|
123
|
+
...readSettingsFile(globalPath()),
|
|
124
|
+
...readSettingsFile(projectPath(cwd)),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Write project-local settings. Global is never touched from code.
|
|
130
|
+
* Returns `true` on success, `false` if the write (or mkdir) failed so the
|
|
131
|
+
* caller can surface a warning — persistence isn't fatal but isn't silent.
|
|
132
|
+
*/
|
|
133
|
+
export function saveSettings(
|
|
134
|
+
s: SubagentsSettings,
|
|
135
|
+
cwd: string = process.cwd(),
|
|
136
|
+
): boolean {
|
|
137
|
+
const path = projectPath(cwd);
|
|
138
|
+
try {
|
|
139
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
140
|
+
writeFileSync(path, JSON.stringify(s, null, 2), "utf-8");
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Apply persisted settings to the in-memory state via caller-supplied setters. */
|
|
148
|
+
export function applySettings(
|
|
149
|
+
s: SubagentsSettings,
|
|
150
|
+
appliers: SettingsAppliers,
|
|
151
|
+
): void {
|
|
152
|
+
if (typeof s.maxConcurrent === "number")
|
|
153
|
+
appliers.setMaxConcurrent(s.maxConcurrent);
|
|
154
|
+
if (typeof s.defaultMaxTurns === "number")
|
|
155
|
+
appliers.setDefaultMaxTurns(s.defaultMaxTurns);
|
|
156
|
+
if (typeof s.graceTurns === "number") appliers.setGraceTurns(s.graceTurns);
|
|
157
|
+
if (s.defaultJoinMode) appliers.setDefaultJoinMode(s.defaultJoinMode);
|
|
158
|
+
if (typeof s.schedulingEnabled === "boolean")
|
|
159
|
+
appliers.setSchedulingEnabled(s.schedulingEnabled);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Format the user-facing toast for a settings mutation. Pure function —
|
|
164
|
+
* routes the success/failure of `saveSettings` into the right message + level
|
|
165
|
+
* so the UI layer (index.ts) stays a thin wire between input and notification.
|
|
166
|
+
*/
|
|
167
|
+
export function persistToastFor(
|
|
168
|
+
successMsg: string,
|
|
169
|
+
persisted: boolean,
|
|
170
|
+
): { message: string; level: "info" | "warning" } {
|
|
171
|
+
return persisted
|
|
172
|
+
? { message: successMsg, level: "info" }
|
|
173
|
+
: {
|
|
174
|
+
message: `${successMsg} (session only; failed to persist)`,
|
|
175
|
+
level: "warning",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Load merged settings, apply them to in-memory state, and emit the
|
|
181
|
+
* `subagents:settings_loaded` lifecycle event. Returns the loaded settings so
|
|
182
|
+
* callers can log/inspect. Extension init wires this once.
|
|
183
|
+
*/
|
|
184
|
+
export function applyAndEmitLoaded(
|
|
185
|
+
appliers: SettingsAppliers,
|
|
186
|
+
emit: SettingsEmit,
|
|
187
|
+
cwd: string = process.cwd(),
|
|
188
|
+
): SubagentsSettings {
|
|
189
|
+
const settings = loadSettings(cwd);
|
|
190
|
+
applySettings(settings, appliers);
|
|
191
|
+
emit("subagents:settings_loaded", { settings });
|
|
192
|
+
return settings;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Persist a settings snapshot, emit the `subagents:settings_changed` event
|
|
197
|
+
* (regardless of persist outcome so listeners see the in-memory change), and
|
|
198
|
+
* return the toast the UI should display. Event payload carries the `persisted`
|
|
199
|
+
* flag so listeners can react to write failures.
|
|
200
|
+
*/
|
|
201
|
+
export function saveAndEmitChanged(
|
|
202
|
+
snapshot: SubagentsSettings,
|
|
203
|
+
successMsg: string,
|
|
204
|
+
emit: SettingsEmit,
|
|
205
|
+
cwd: string = process.cwd(),
|
|
206
|
+
): { message: string; level: "info" | "warning" } {
|
|
207
|
+
const persisted = saveSettings(snapshot, cwd);
|
|
208
|
+
emit("subagents:settings_changed", { settings: snapshot, persisted });
|
|
209
|
+
return persistToastFor(successMsg, persisted);
|
|
210
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-loader.ts — Preload named skills.
|
|
3
|
+
*
|
|
4
|
+
* Roots, in precedence order:
|
|
5
|
+
* - <cwd>/.pi/skills (project, Pi's standard)
|
|
6
|
+
* - <cwd>/.agents/skills (project, cross-tool Agent Skills spec — https://agentskills.io)
|
|
7
|
+
* - getAgentDir()/skills (user, default ~/.pi/agent/skills — Pi's standard)
|
|
8
|
+
* - ~/.agents/skills (user, cross-tool Agent Skills spec)
|
|
9
|
+
* - ~/.pi/skills (legacy global, pre-Pi)
|
|
10
|
+
*
|
|
11
|
+
* Layout per root:
|
|
12
|
+
* - <root>/<name>.md (flat file at the top level)
|
|
13
|
+
* - <root>/.../<name>/SKILL.md (directory skill, may be nested — Pi's standard)
|
|
14
|
+
*
|
|
15
|
+
* Recursion skips dotfile entries and node_modules. A directory that itself contains
|
|
16
|
+
* SKILL.md is a skill — we don't descend into it (Pi: skills don't nest).
|
|
17
|
+
*
|
|
18
|
+
* Symlinks are rejected for security (deviation from Pi, which follows them).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { Dirent } from "node:fs";
|
|
22
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import { getAgentDir } from "@mariozechner/pi-coding-agent";
|
|
26
|
+
import { isSymlink, isUnsafeName, safeReadFile } from "./memory.js";
|
|
27
|
+
|
|
28
|
+
export interface PreloadedSkill {
|
|
29
|
+
name: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function preloadSkills(
|
|
34
|
+
skillNames: string[],
|
|
35
|
+
cwd: string,
|
|
36
|
+
): PreloadedSkill[] {
|
|
37
|
+
return skillNames.map((name) => ({
|
|
38
|
+
name,
|
|
39
|
+
content: loadSkillContent(name, cwd),
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function loadSkillContent(name: string, cwd: string): string {
|
|
44
|
+
if (isUnsafeName(name)) {
|
|
45
|
+
return `(Skill "${name}" skipped: name contains path traversal characters)`;
|
|
46
|
+
}
|
|
47
|
+
const roots = [
|
|
48
|
+
join(cwd, ".pi", "skills"), // project — Pi standard
|
|
49
|
+
join(cwd, ".agents", "skills"), // project — Agent Skills spec
|
|
50
|
+
join(getAgentDir(), "skills"), // user — Pi standard
|
|
51
|
+
join(homedir(), ".agents", "skills"), // user — Agent Skills spec
|
|
52
|
+
join(homedir(), ".pi", "skills"), // legacy global, pre-Pi
|
|
53
|
+
];
|
|
54
|
+
for (const root of roots) {
|
|
55
|
+
const content = findInRoot(root, name);
|
|
56
|
+
if (content !== undefined) return content;
|
|
57
|
+
}
|
|
58
|
+
return `(Skill "${name}" not found in .pi/skills/, .agents/skills/, or global skill locations)`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function findInRoot(root: string, name: string): string | undefined {
|
|
62
|
+
if (isSymlink(root)) return undefined; // reject symlinked roots entirely
|
|
63
|
+
const flat = safeReadFile(join(root, `${name}.md`))?.trim();
|
|
64
|
+
if (flat !== undefined) return flat;
|
|
65
|
+
return findSkillDirectory(root, name);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** BFS under `root` for a directory named `name` containing `SKILL.md`. Pi-conforming filters. */
|
|
69
|
+
function findSkillDirectory(root: string, name: string): string | undefined {
|
|
70
|
+
if (!existsSync(root)) return undefined;
|
|
71
|
+
const queue: string[] = [root];
|
|
72
|
+
|
|
73
|
+
while (queue.length > 0) {
|
|
74
|
+
const current = queue.shift();
|
|
75
|
+
if (current === undefined) continue;
|
|
76
|
+
|
|
77
|
+
let entries: Dirent<string>[];
|
|
78
|
+
try {
|
|
79
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
80
|
+
} catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Deterministic byte-order traversal — locale-independent.
|
|
85
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
86
|
+
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (!entry.isDirectory()) continue;
|
|
89
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
90
|
+
|
|
91
|
+
// Symlinked dirs already filtered by entry.isDirectory() — Dirent uses lstat semantics.
|
|
92
|
+
const path = join(current, entry.name);
|
|
93
|
+
const skillMd = join(path, "SKILL.md");
|
|
94
|
+
const isSkillDir = existsSync(skillMd);
|
|
95
|
+
|
|
96
|
+
if (isSkillDir) {
|
|
97
|
+
if (entry.name === name) {
|
|
98
|
+
const content = safeReadFile(skillMd)?.trim();
|
|
99
|
+
if (content !== undefined) return content;
|
|
100
|
+
}
|
|
101
|
+
continue; // Pi rule: skills don't nest — don't descend into a skill dir
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
queue.push(path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — Type definitions for the subagent system.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ThinkingLevel } from "@mariozechner/pi-agent-core";
|
|
6
|
+
import type { AgentSession } from "@mariozechner/pi-coding-agent";
|
|
7
|
+
import type { LifetimeUsage } from "./usage.js";
|
|
8
|
+
|
|
9
|
+
export type { ThinkingLevel };
|
|
10
|
+
|
|
11
|
+
/** Agent type: any string name (built-in defaults or user-defined). */
|
|
12
|
+
export type SubagentType = string;
|
|
13
|
+
|
|
14
|
+
/** Names of the three embedded default agents. */
|
|
15
|
+
export const DEFAULT_AGENT_NAMES = [
|
|
16
|
+
"general-purpose",
|
|
17
|
+
"Explore",
|
|
18
|
+
"Plan",
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
/** Memory scope for persistent agent memory. */
|
|
22
|
+
export type MemoryScope = "user" | "project" | "local";
|
|
23
|
+
|
|
24
|
+
/** Isolation mode for agent execution. */
|
|
25
|
+
export type IsolationMode = "worktree";
|
|
26
|
+
|
|
27
|
+
/** Unified agent configuration — used for both default and user-defined agents. */
|
|
28
|
+
export interface AgentConfig {
|
|
29
|
+
name: string;
|
|
30
|
+
displayName?: string;
|
|
31
|
+
description: string;
|
|
32
|
+
builtinToolNames?: string[];
|
|
33
|
+
/** Tool denylist — these tools are removed even if `builtinToolNames` or extensions include them. */
|
|
34
|
+
disallowedTools?: string[];
|
|
35
|
+
/** true = inherit all, string[] = only listed, false = none */
|
|
36
|
+
extensions: true | string[] | false;
|
|
37
|
+
/** true = inherit all, string[] = only listed, false = none */
|
|
38
|
+
skills: true | string[] | false;
|
|
39
|
+
model?: string;
|
|
40
|
+
thinking?: ThinkingLevel;
|
|
41
|
+
maxTurns?: number;
|
|
42
|
+
systemPrompt: string;
|
|
43
|
+
promptMode: "replace" | "append";
|
|
44
|
+
/** Default for spawn: fork parent conversation. undefined = caller decides. */
|
|
45
|
+
inheritContext?: boolean;
|
|
46
|
+
/** Default for spawn: run in background. undefined = caller decides. */
|
|
47
|
+
runInBackground?: boolean;
|
|
48
|
+
/** Default for spawn: no extension tools. undefined = caller decides. */
|
|
49
|
+
isolated?: boolean;
|
|
50
|
+
/** Persistent memory scope — agents with memory get a persistent directory and MEMORY.md */
|
|
51
|
+
memory?: MemoryScope;
|
|
52
|
+
/** Isolation mode — "worktree" runs the agent in a temporary git worktree */
|
|
53
|
+
isolation?: IsolationMode;
|
|
54
|
+
/** true = this is an embedded default agent (informational) */
|
|
55
|
+
isDefault?: boolean;
|
|
56
|
+
/** false = agent is hidden from the registry */
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
/** Where this agent was loaded from */
|
|
59
|
+
source?: "default" | "project" | "global";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type JoinMode = "async" | "group" | "smart";
|
|
63
|
+
|
|
64
|
+
export interface AgentRecord {
|
|
65
|
+
id: string;
|
|
66
|
+
type: SubagentType;
|
|
67
|
+
description: string;
|
|
68
|
+
status:
|
|
69
|
+
| "queued"
|
|
70
|
+
| "running"
|
|
71
|
+
| "completed"
|
|
72
|
+
| "steered"
|
|
73
|
+
| "aborted"
|
|
74
|
+
| "stopped"
|
|
75
|
+
| "error";
|
|
76
|
+
result?: string;
|
|
77
|
+
error?: string;
|
|
78
|
+
toolUses: number;
|
|
79
|
+
startedAt: number;
|
|
80
|
+
completedAt?: number;
|
|
81
|
+
session?: AgentSession;
|
|
82
|
+
abortController?: AbortController;
|
|
83
|
+
promise?: Promise<string>;
|
|
84
|
+
groupId?: string;
|
|
85
|
+
joinMode?: JoinMode;
|
|
86
|
+
/** Set when result was already consumed via get_subagent_result — suppresses completion notification. */
|
|
87
|
+
resultConsumed?: boolean;
|
|
88
|
+
/** Steering messages queued before the session was ready. */
|
|
89
|
+
pendingSteers?: string[];
|
|
90
|
+
/** Worktree info if the agent is running in an isolated worktree. */
|
|
91
|
+
worktree?: { path: string; branch: string };
|
|
92
|
+
/** Worktree cleanup result after agent completion. */
|
|
93
|
+
worktreeResult?: { hasChanges: boolean; branch?: string };
|
|
94
|
+
/** The tool_use_id from the original Agent tool call. */
|
|
95
|
+
toolCallId?: string;
|
|
96
|
+
/** Path to the streaming output transcript file. */
|
|
97
|
+
outputFile?: string;
|
|
98
|
+
/** Cleanup function for the output file stream subscription. */
|
|
99
|
+
outputCleanup?: () => void;
|
|
100
|
+
/**
|
|
101
|
+
* Lifetime usage breakdown, accumulated via `message_end` events. Survives
|
|
102
|
+
* compaction. Total = input + output + cacheWrite (cacheRead deliberately
|
|
103
|
+
* excluded — see issue #38). Initialized to zeros at spawn.
|
|
104
|
+
*/
|
|
105
|
+
lifetimeUsage: LifetimeUsage;
|
|
106
|
+
/** Number of times this agent's session has compacted. Initialized to 0 at spawn. */
|
|
107
|
+
compactionCount: number;
|
|
108
|
+
/** Resolved spawn params, captured for UI display. Fixed at spawn time. */
|
|
109
|
+
invocation?: AgentInvocation;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface AgentInvocation {
|
|
113
|
+
/** Short display name, e.g. "haiku" — only set when different from parent. */
|
|
114
|
+
modelName?: string;
|
|
115
|
+
thinking?: ThinkingLevel;
|
|
116
|
+
maxTurns?: number;
|
|
117
|
+
isolated?: boolean;
|
|
118
|
+
inheritContext?: boolean;
|
|
119
|
+
runInBackground?: boolean;
|
|
120
|
+
isolation?: IsolationMode;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Details attached to custom notification messages for visual rendering. */
|
|
124
|
+
export interface NotificationDetails {
|
|
125
|
+
id: string;
|
|
126
|
+
description: string;
|
|
127
|
+
status: string;
|
|
128
|
+
toolUses: number;
|
|
129
|
+
turnCount: number;
|
|
130
|
+
maxTurns?: number;
|
|
131
|
+
totalTokens: number;
|
|
132
|
+
durationMs: number;
|
|
133
|
+
outputFile?: string;
|
|
134
|
+
error?: string;
|
|
135
|
+
resultPreview: string;
|
|
136
|
+
/** Additional agents in a group notification. */
|
|
137
|
+
others?: NotificationDetails[];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface EnvInfo {
|
|
141
|
+
isGitRepo: boolean;
|
|
142
|
+
branch: string;
|
|
143
|
+
platform: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A subagent spawn registered to fire on a schedule.
|
|
148
|
+
*
|
|
149
|
+
* Stored at `<cwd>/.pi/subagent-schedules/<sessionId>.json`. Session-scoped:
|
|
150
|
+
* survives `/resume` but resets on `/new`, mirroring pi-chonky-tasks.
|
|
151
|
+
*/
|
|
152
|
+
export interface ScheduledSubagent {
|
|
153
|
+
id: string;
|
|
154
|
+
/** Unique within store. Defaults to `description`. */
|
|
155
|
+
name: string;
|
|
156
|
+
description: string;
|
|
157
|
+
/** Raw user input — cron expr | "+10m" | ISO | "5m". */
|
|
158
|
+
schedule: string;
|
|
159
|
+
scheduleType: "cron" | "once" | "interval";
|
|
160
|
+
/** Computed at create time for interval/once. */
|
|
161
|
+
intervalMs?: number;
|
|
162
|
+
|
|
163
|
+
// spawn params (subset of Agent tool params; no inherit_context, no resume)
|
|
164
|
+
subagent_type: SubagentType;
|
|
165
|
+
prompt: string;
|
|
166
|
+
model?: string;
|
|
167
|
+
thinking?: ThinkingLevel;
|
|
168
|
+
max_turns?: number;
|
|
169
|
+
isolated?: boolean;
|
|
170
|
+
isolation?: IsolationMode;
|
|
171
|
+
|
|
172
|
+
// state
|
|
173
|
+
enabled: boolean;
|
|
174
|
+
/** ISO timestamp. */
|
|
175
|
+
createdAt: string;
|
|
176
|
+
lastRun?: string;
|
|
177
|
+
lastStatus?: "success" | "error" | "running";
|
|
178
|
+
/** Refreshed on every fire and on store load. */
|
|
179
|
+
nextRun?: string;
|
|
180
|
+
runCount: number;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface ScheduleStoreData {
|
|
184
|
+
/** For future migrations. */
|
|
185
|
+
version: 1;
|
|
186
|
+
jobs: ScheduledSubagent[];
|
|
187
|
+
}
|