@astrofoundry/astrogate 0.1.3 → 0.1.5
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/cli/astrogate.sh +34 -9
- package/cli/astrogate.test.ts +4 -1
- package/dist/bridge.js +8 -2
- package/dist/claude.js +66 -12
- package/dist/extensions/bridge/index.js +8 -2
- package/extensions/bridge/index.ts +8 -2
- package/harness/claude/agents.ts +39 -0
- package/harness/claude/claude.test.ts +27 -1
- package/harness/claude/main.ts +17 -4
- package/package.json +1 -1
- package/release.sha256 +10 -10
- package/release.sha256.sig +2 -2
package/cli/astrogate.sh
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
# the running core's verify-release.sh checks the core first, and
|
|
7
7
|
# each tool download must match the sha256 in the core's tools.lock
|
|
8
8
|
# sudo astrogate core rollback swaps the current core and the previous one, with their tools
|
|
9
|
+
# (sudo astrogate core activate <x.y.z> the second half of update: the new version's own code installs
|
|
10
|
+
# its tools and switches to it; update runs it, nobody else needs to)
|
|
9
11
|
# astrogate tools each tool's installed version and the version the core pins
|
|
10
12
|
# astrogate doctor read-only checks; exits 1 when one fails
|
|
11
13
|
#
|
|
@@ -70,7 +72,7 @@ case "${1:-}" in
|
|
|
70
72
|
action=${2:-status}
|
|
71
73
|
case "$action" in
|
|
72
74
|
status) [ $# -le 2 ] || usage ;;
|
|
73
|
-
update)
|
|
75
|
+
update | activate)
|
|
74
76
|
shift 2
|
|
75
77
|
while [ $# -gt 0 ]; do
|
|
76
78
|
case "$1" in
|
|
@@ -86,6 +88,7 @@ case "${1:-}" in
|
|
|
86
88
|
;;
|
|
87
89
|
esac
|
|
88
90
|
done
|
|
91
|
+
[ "$action" = update ] || [ -n "$version" ] || usage
|
|
89
92
|
;;
|
|
90
93
|
rollback) [ $# -eq 2 ] || usage ;;
|
|
91
94
|
*) usage ;;
|
|
@@ -354,6 +357,17 @@ core_status() {
|
|
|
354
357
|
echo "core ${current:-not installed}${previous:+, previous $previous}, newest on npm ${latest:-unknown}"
|
|
355
358
|
}
|
|
356
359
|
|
|
360
|
+
# Picks the signers file: root's copy, or on the first install the one named with --signers.
|
|
361
|
+
pick_signers() {
|
|
362
|
+
if [ -f "$SIGNERS" ]; then
|
|
363
|
+
[ -z "$signers_arg" ] || /usr/bin/cmp -s "$signers_arg" "$SIGNERS" || fail "$SIGNERS exists and differs from $signers_arg; replace it by hand when the signing key changes"
|
|
364
|
+
signers=$SIGNERS
|
|
365
|
+
else
|
|
366
|
+
[ -n "$signers_arg" ] && [ -f "$signers_arg" ] || fail "no $SIGNERS yet: the first install needs --signers <the repo's allowed_signers>"
|
|
367
|
+
signers=$signers_arg
|
|
368
|
+
fi
|
|
369
|
+
}
|
|
370
|
+
|
|
357
371
|
core_update() {
|
|
358
372
|
require_root
|
|
359
373
|
check_root_dir /
|
|
@@ -362,13 +376,7 @@ core_update() {
|
|
|
362
376
|
ensure_root_dir /usr/local/libexec
|
|
363
377
|
ensure_root_dir "$BASE"
|
|
364
378
|
ensure_root_dir "$BASE/versions"
|
|
365
|
-
|
|
366
|
-
[ -z "$signers_arg" ] || /usr/bin/cmp -s "$signers_arg" "$SIGNERS" || fail "$SIGNERS exists and differs from $signers_arg; replace it by hand when the signing key changes"
|
|
367
|
-
signers=$SIGNERS
|
|
368
|
-
else
|
|
369
|
-
[ -n "$signers_arg" ] && [ -f "$signers_arg" ] || fail "no $SIGNERS yet: the first install needs --signers <the repo's allowed_signers>"
|
|
370
|
-
signers=$signers_arg
|
|
371
|
-
fi
|
|
379
|
+
pick_signers
|
|
372
380
|
current=$(link_version current)
|
|
373
381
|
if [ -z "$version" ]; then
|
|
374
382
|
version=$(latest_version)
|
|
@@ -400,7 +408,23 @@ core_update() {
|
|
|
400
408
|
/bin/chmod 0755 "$target.new/cli/astrogate.sh" "$target.new/cli/verify-release.sh"
|
|
401
409
|
/bin/rm -rf "$target"
|
|
402
410
|
/bin/mv "$target.new" "$target"
|
|
403
|
-
#
|
|
411
|
+
# The checked version's own code finishes, so a release's new install steps apply to itself.
|
|
412
|
+
/bin/rm -rf "$work"
|
|
413
|
+
trap - EXIT HUP INT TERM
|
|
414
|
+
exec /bin/sh "$target/cli/astrogate.sh" core activate "$version" ${signers_arg:+--signers "$signers_arg"}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
# The second half of core update, run from the checked version it activates: every tool that
|
|
418
|
+
# version pins is in place before anything switches.
|
|
419
|
+
core_activate() {
|
|
420
|
+
require_root
|
|
421
|
+
pick_signers
|
|
422
|
+
target=$BASE/versions/$version
|
|
423
|
+
[ "$HERE" = "$target/cli" ] || fail "core activate runs only from the version it activates"
|
|
424
|
+
check_root_dir "$target"
|
|
425
|
+
current=$(link_version current)
|
|
426
|
+
[ "$version" != "$current" ] || fail "core $version is current already"
|
|
427
|
+
make_work
|
|
404
428
|
stage_tools "$target"
|
|
405
429
|
switch_to "$version"
|
|
406
430
|
link_tools "$BASE/current"
|
|
@@ -515,6 +539,7 @@ doctor() {
|
|
|
515
539
|
case "$action" in
|
|
516
540
|
status) core_status ;;
|
|
517
541
|
update) core_update ;;
|
|
542
|
+
activate) core_activate ;;
|
|
518
543
|
rollback) core_rollback ;;
|
|
519
544
|
tools) tools_status ;;
|
|
520
545
|
doctor) doctor ;;
|
package/cli/astrogate.test.ts
CHANGED
|
@@ -44,6 +44,9 @@ describe("astrogate", () => {
|
|
|
44
44
|
[["core", "update", "--signers", ""]],
|
|
45
45
|
[["core", "update", "--signers", "a", "--signers", "b"]],
|
|
46
46
|
[["core", "rollback", "1.2.3"]],
|
|
47
|
+
[["core", "activate"]],
|
|
48
|
+
[["core", "activate", "--signers", "x"]],
|
|
49
|
+
[["core", "activate", "1.2"]],
|
|
47
50
|
[["doctor", "now"]],
|
|
48
51
|
[["tools", "now"]],
|
|
49
52
|
[["update"]],
|
|
@@ -53,7 +56,7 @@ describe("astrogate", () => {
|
|
|
53
56
|
expect(result.stderr).toMatch(/^usage: astrogate/);
|
|
54
57
|
});
|
|
55
58
|
|
|
56
|
-
it.runIf(isMac && !isRoot).each([["update"], ["update", "1.2.3", "--signers", "x"], ["rollback"]])("refuses core %s without root", (...args) => {
|
|
59
|
+
it.runIf(isMac && !isRoot).each([["update"], ["update", "1.2.3", "--signers", "x"], ["rollback"], ["activate", "1.2.3"]])("refuses core %s without root", (...args) => {
|
|
57
60
|
const result = astrogate("core", ...args);
|
|
58
61
|
expect(result.status).toBe(1);
|
|
59
62
|
expect(result.stderr).toContain("run it as root: sudo astrogate core");
|
package/dist/bridge.js
CHANGED
|
@@ -9719,8 +9719,14 @@ ${request}`;
|
|
|
9719
9719
|
conversationId: task.conversation.id,
|
|
9720
9720
|
resume: task.conversation.resumed,
|
|
9721
9721
|
appendSystemPrompt: CHANNEL_RULES,
|
|
9722
|
-
// The child must not become a second Discord bridge.
|
|
9723
|
-
|
|
9722
|
+
// The child must not become a second Discord bridge. The foreman's specialist subagents run in the
|
|
9723
|
+
// background, and `claude -p` waits for them only 10 minutes unless told otherwise; an approval can take longer.
|
|
9724
|
+
env: {
|
|
9725
|
+
[ACTIVATION_ENV]: "0",
|
|
9726
|
+
...approvalEnv,
|
|
9727
|
+
CLAUDE_CODE_OAUTH_TOKEN: loadClaudeToken(),
|
|
9728
|
+
CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS: String((agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 6e4)
|
|
9729
|
+
},
|
|
9724
9730
|
timeoutMs: (agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 6e4,
|
|
9725
9731
|
clock: task.clock,
|
|
9726
9732
|
signal: task.abort.signal,
|
package/dist/claude.js
CHANGED
|
@@ -7364,16 +7364,34 @@ var require_dist = __commonJS({
|
|
|
7364
7364
|
});
|
|
7365
7365
|
|
|
7366
7366
|
// harness/claude/main.ts
|
|
7367
|
-
import { existsSync as existsSync2, readdirSync, readFileSync as
|
|
7367
|
+
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7368
7368
|
import { join as join3 } from "node:path";
|
|
7369
7369
|
import { createInterface } from "node:readline";
|
|
7370
|
-
import { fileURLToPath } from "node:url";
|
|
7370
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7371
7371
|
|
|
7372
7372
|
// extensions/subagents/pi-paths.ts
|
|
7373
|
+
var import_yaml = __toESM(require_dist(), 1);
|
|
7374
|
+
import { readFileSync } from "node:fs";
|
|
7373
7375
|
import { homedir } from "node:os";
|
|
7374
7376
|
import { dirname, join } from "node:path";
|
|
7375
|
-
|
|
7377
|
+
import { fileURLToPath } from "node:url";
|
|
7376
7378
|
var CONFIG_DIR_NAME = ".pi";
|
|
7379
|
+
var PACKAGE_NAME = "@astrofoundry/astrogate";
|
|
7380
|
+
function packageRoot(from = fileURLToPath(import.meta.url)) {
|
|
7381
|
+
let dir = dirname(from);
|
|
7382
|
+
for (; ; ) {
|
|
7383
|
+
let name;
|
|
7384
|
+
try {
|
|
7385
|
+
name = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8")).name;
|
|
7386
|
+
} catch {
|
|
7387
|
+
name = void 0;
|
|
7388
|
+
}
|
|
7389
|
+
if (name === PACKAGE_NAME) return dir;
|
|
7390
|
+
const parent = dirname(dir);
|
|
7391
|
+
if (parent === dir) throw new Error(`no ${PACKAGE_NAME} package above ${from}`);
|
|
7392
|
+
dir = parent;
|
|
7393
|
+
}
|
|
7394
|
+
}
|
|
7377
7395
|
var AGENT_DIR_ENV = "PI_CODING_AGENT_DIR";
|
|
7378
7396
|
function getAgentDir() {
|
|
7379
7397
|
const dir = process.env[AGENT_DIR_ENV];
|
|
@@ -7382,7 +7400,7 @@ function getAgentDir() {
|
|
|
7382
7400
|
}
|
|
7383
7401
|
|
|
7384
7402
|
// extensions/gate/config.ts
|
|
7385
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
7403
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
7386
7404
|
import { homedir as homedir2 } from "node:os";
|
|
7387
7405
|
import { join as join2 } from "node:path";
|
|
7388
7406
|
function configPath() {
|
|
@@ -7471,7 +7489,7 @@ function loadConfig() {
|
|
|
7471
7489
|
const errors = [];
|
|
7472
7490
|
if (!existsSync(path)) return { config: null, configPath: path, errors };
|
|
7473
7491
|
try {
|
|
7474
|
-
const parsed = JSON.parse(
|
|
7492
|
+
const parsed = JSON.parse(readFileSync2(path, "utf-8"));
|
|
7475
7493
|
return { config: validateConfig(parsed, errors), configPath: path, errors };
|
|
7476
7494
|
} catch (err) {
|
|
7477
7495
|
errors.push(`invalid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -7647,6 +7665,30 @@ function renderAgent(source) {
|
|
|
7647
7665
|
];
|
|
7648
7666
|
return lines.join("\n");
|
|
7649
7667
|
}
|
|
7668
|
+
var FOREMAN = "foreman";
|
|
7669
|
+
function renderForeman(source) {
|
|
7670
|
+
const agent = parseMarkdown(source.agent);
|
|
7671
|
+
const description = agent.fields.description;
|
|
7672
|
+
if (!description) throw new Error("foreman: the agent has no description");
|
|
7673
|
+
const skill = source.skill === null ? "" : parseMarkdown(source.skill).body.trim();
|
|
7674
|
+
const subagents = source.services.map(agentName);
|
|
7675
|
+
const lines = [
|
|
7676
|
+
"---",
|
|
7677
|
+
`name: ${agentName(FOREMAN)}`,
|
|
7678
|
+
`description: ${JSON.stringify(description)}`,
|
|
7679
|
+
`tools: ${subagents.length > 0 ? `Read, Agent(${subagents.join(", ")})` : "Read"}`,
|
|
7680
|
+
`model: ${source.settings.model}`,
|
|
7681
|
+
...source.settings.effort ? [`effort: ${source.settings.effort}`] : [],
|
|
7682
|
+
GENERATED_FIELD,
|
|
7683
|
+
"---",
|
|
7684
|
+
`In this harness your \`subagent\` tool is the Agent tool: set \`subagent_type\` to the specialist's agent (${subagents.map((a) => `\`${a}\``).join(", ") || "none is installed"}) and give the task as \`prompt\`. Wait for every report a step needs before you answer; your answer ends the run.`,
|
|
7685
|
+
"",
|
|
7686
|
+
agent.body.trim(),
|
|
7687
|
+
...skill ? ["", skill] : [],
|
|
7688
|
+
""
|
|
7689
|
+
];
|
|
7690
|
+
return lines.join("\n");
|
|
7691
|
+
}
|
|
7650
7692
|
|
|
7651
7693
|
// harness/claude/mcp.ts
|
|
7652
7694
|
import { spawn } from "node:child_process";
|
|
@@ -7802,7 +7844,7 @@ function mergeSettings(current, services, hookCommand, longestCallMs) {
|
|
|
7802
7844
|
}
|
|
7803
7845
|
|
|
7804
7846
|
// harness/claude/main.ts
|
|
7805
|
-
var BUNDLE =
|
|
7847
|
+
var BUNDLE = fileURLToPath2(import.meta.url);
|
|
7806
7848
|
var PACK = join3(getAgentDir(), "pack");
|
|
7807
7849
|
var SERVICE = /^[a-z][a-z0-9-]{0,30}$/;
|
|
7808
7850
|
function usage() {
|
|
@@ -7810,7 +7852,7 @@ function usage() {
|
|
|
7810
7852
|
process.exit(2);
|
|
7811
7853
|
}
|
|
7812
7854
|
function readJson(path) {
|
|
7813
|
-
return JSON.parse(
|
|
7855
|
+
return JSON.parse(readFileSync3(path, "utf-8"));
|
|
7814
7856
|
}
|
|
7815
7857
|
function writeAtomic(path, text) {
|
|
7816
7858
|
const tmp = `${path}.tmp`;
|
|
@@ -7853,7 +7895,7 @@ async function hook() {
|
|
|
7853
7895
|
function agents(dir, node2) {
|
|
7854
7896
|
const pack = packFile();
|
|
7855
7897
|
for (const name of readdirSync(dir).filter((n) => n.startsWith("astro-") && n.endsWith(".md"))) {
|
|
7856
|
-
if (
|
|
7898
|
+
if (readFileSync3(join3(dir, name), "utf-8").includes(`
|
|
7857
7899
|
${GENERATED_FIELD}
|
|
7858
7900
|
`)) rmSync(join3(dir, name));
|
|
7859
7901
|
}
|
|
@@ -7862,22 +7904,34 @@ ${GENERATED_FIELD}
|
|
|
7862
7904
|
const skillPath = join3(PACK, "skills", service, "SKILL.md");
|
|
7863
7905
|
const text = renderAgent({
|
|
7864
7906
|
service,
|
|
7865
|
-
agent:
|
|
7866
|
-
skill: existsSync2(skillPath) ?
|
|
7907
|
+
agent: readFileSync3(agentPath, "utf-8"),
|
|
7908
|
+
skill: existsSync2(skillPath) ? readFileSync3(skillPath, "utf-8") : null,
|
|
7867
7909
|
settings: claudeSettings(pack, service),
|
|
7868
7910
|
node: node2,
|
|
7869
7911
|
bundle: BUNDLE
|
|
7870
7912
|
});
|
|
7871
7913
|
writeAtomic(join3(dir, `${agentName(service)}.md`), text);
|
|
7872
7914
|
}
|
|
7873
|
-
|
|
7915
|
+
const root = packageRoot();
|
|
7916
|
+
const foremanAgent = [join3(PACK, "agents", `${FOREMAN}.md`), join3(root, "agents", `${FOREMAN}.md`)].find((p) => existsSync2(p));
|
|
7917
|
+
const foremanSkill = [join3(PACK, "skills", FOREMAN, "SKILL.md"), join3(root, "skills", FOREMAN, "SKILL.md")].find((p) => existsSync2(p));
|
|
7918
|
+
if (foremanAgent) {
|
|
7919
|
+
const text = renderForeman({
|
|
7920
|
+
agent: readFileSync3(foremanAgent, "utf-8"),
|
|
7921
|
+
skill: foremanSkill ? readFileSync3(foremanSkill, "utf-8") : null,
|
|
7922
|
+
services: pack.specialists.map((s) => s.service),
|
|
7923
|
+
settings: claudeSettings(pack, FOREMAN)
|
|
7924
|
+
});
|
|
7925
|
+
writeAtomic(join3(dir, `${agentName(FOREMAN)}.md`), text);
|
|
7926
|
+
}
|
|
7927
|
+
process.stdout.write(`${pack.specialists.length} Claude Code specialist agents${foremanAgent ? " and the foreman" : ""} from pack ${pack.version} in ${dir}
|
|
7874
7928
|
`);
|
|
7875
7929
|
}
|
|
7876
7930
|
function settings(path, node2) {
|
|
7877
7931
|
const config = loadConfig().config;
|
|
7878
7932
|
if (!config) throw new Error("~/.pi/agent/specialists.json is missing or invalid");
|
|
7879
7933
|
const current = existsSync2(path) ? readJson(path) : {};
|
|
7880
|
-
if (existsSync2(path) && !existsSync2(`${path}.before-astro`)) writeFileSync(`${path}.before-astro`,
|
|
7934
|
+
if (existsSync2(path) && !existsSync2(`${path}.before-astro`)) writeFileSync(`${path}.before-astro`, readFileSync3(path));
|
|
7881
7935
|
const services = config.specialists.map((s) => s.service);
|
|
7882
7936
|
const longest = Math.max(...config.specialists.map((s) => s.timeoutMs));
|
|
7883
7937
|
writeAtomic(path, `${JSON.stringify(mergeSettings(current, services, `${node2} ${BUNDLE} hook`, longest), null, 2)}
|
|
@@ -9713,8 +9713,14 @@ ${request}`;
|
|
|
9713
9713
|
conversationId: task.conversation.id,
|
|
9714
9714
|
resume: task.conversation.resumed,
|
|
9715
9715
|
appendSystemPrompt: CHANNEL_RULES,
|
|
9716
|
-
// The child must not become a second Discord bridge.
|
|
9717
|
-
|
|
9716
|
+
// The child must not become a second Discord bridge. The foreman's specialist subagents run in the
|
|
9717
|
+
// background, and `claude -p` waits for them only 10 minutes unless told otherwise; an approval can take longer.
|
|
9718
|
+
env: {
|
|
9719
|
+
[ACTIVATION_ENV]: "0",
|
|
9720
|
+
...approvalEnv,
|
|
9721
|
+
CLAUDE_CODE_OAUTH_TOKEN: loadClaudeToken(),
|
|
9722
|
+
CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS: String((agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 6e4)
|
|
9723
|
+
},
|
|
9718
9724
|
timeoutMs: (agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 6e4,
|
|
9719
9725
|
clock: task.clock,
|
|
9720
9726
|
signal: task.abort.signal,
|
|
@@ -715,8 +715,14 @@ export class Bridge {
|
|
|
715
715
|
conversationId: task.conversation.id,
|
|
716
716
|
resume: task.conversation.resumed,
|
|
717
717
|
appendSystemPrompt: CHANNEL_RULES,
|
|
718
|
-
// The child must not become a second Discord bridge.
|
|
719
|
-
|
|
718
|
+
// The child must not become a second Discord bridge. The foreman's specialist subagents run in the
|
|
719
|
+
// background, and `claude -p` waits for them only 10 minutes unless told otherwise; an approval can take longer.
|
|
720
|
+
env: {
|
|
721
|
+
[ACTIVATION_ENV]: "0",
|
|
722
|
+
...approvalEnv,
|
|
723
|
+
CLAUDE_CODE_OAUTH_TOKEN: loadClaudeToken(),
|
|
724
|
+
CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS: String((agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 60_000),
|
|
725
|
+
},
|
|
720
726
|
timeoutMs: (agent.timeoutMinutes ?? TASK_TIMEOUT_MINUTES) * 60_000,
|
|
721
727
|
clock: task.clock,
|
|
722
728
|
signal: task.abort.signal,
|
package/harness/claude/agents.ts
CHANGED
|
@@ -91,3 +91,42 @@ export function renderAgent(source: AgentSource): string {
|
|
|
91
91
|
];
|
|
92
92
|
return lines.join("\n");
|
|
93
93
|
}
|
|
94
|
+
|
|
95
|
+
/** The core agent that takes the owner's requests and hands each step to a specialist. */
|
|
96
|
+
export const FOREMAN = "foreman";
|
|
97
|
+
|
|
98
|
+
export interface ForemanSource {
|
|
99
|
+
agent: string;
|
|
100
|
+
skill: string | null;
|
|
101
|
+
services: readonly string[];
|
|
102
|
+
settings: ClaudeSettings;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The text of `astro-foreman.md`. The bridge runs it as the main agent (`claude -p --agent astro-foreman`),
|
|
107
|
+
* the only way an agent can spawn subagents; its Agent tool reaches only the specialist subagents, so it
|
|
108
|
+
* never gets a specialist tool itself.
|
|
109
|
+
*/
|
|
110
|
+
export function renderForeman(source: ForemanSource): string {
|
|
111
|
+
const agent = parseMarkdown(source.agent);
|
|
112
|
+
const description = agent.fields.description;
|
|
113
|
+
if (!description) throw new Error("foreman: the agent has no description");
|
|
114
|
+
const skill = source.skill === null ? "" : parseMarkdown(source.skill).body.trim();
|
|
115
|
+
const subagents = source.services.map(agentName);
|
|
116
|
+
const lines = [
|
|
117
|
+
"---",
|
|
118
|
+
`name: ${agentName(FOREMAN)}`,
|
|
119
|
+
`description: ${JSON.stringify(description)}`,
|
|
120
|
+
`tools: ${subagents.length > 0 ? `Read, Agent(${subagents.join(", ")})` : "Read"}`,
|
|
121
|
+
`model: ${source.settings.model}`,
|
|
122
|
+
...(source.settings.effort ? [`effort: ${source.settings.effort}`] : []),
|
|
123
|
+
GENERATED_FIELD,
|
|
124
|
+
"---",
|
|
125
|
+
`In this harness your \`subagent\` tool is the Agent tool: set \`subagent_type\` to the specialist's agent (${subagents.map((a) => `\`${a}\``).join(", ") || "none is installed"}) and give the task as \`prompt\`. Wait for every report a step needs before you answer; your answer ends the run.`,
|
|
126
|
+
"",
|
|
127
|
+
agent.body.trim(),
|
|
128
|
+
...(skill ? ["", skill] : []),
|
|
129
|
+
"",
|
|
130
|
+
];
|
|
131
|
+
return lines.join("\n");
|
|
132
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import type { SpecialistsConfig } from "../../extensions/gate/types.ts";
|
|
3
|
-
import { claudeSettings, GENERATED_FIELD, parseMarkdown, renderAgent } from "./agents.ts";
|
|
3
|
+
import { claudeSettings, GENERATED_FIELD, parseMarkdown, renderAgent, renderForeman } from "./agents.ts";
|
|
4
4
|
import { type BridgeApproval, decide, type HookOutput } from "./hook.ts";
|
|
5
5
|
import { type Message, type Runner, SpecialistServer } from "./mcp.ts";
|
|
6
6
|
import { hasGate, HOOK_MATCHER, mergeSettings } from "./settings.ts";
|
|
@@ -116,6 +116,32 @@ describe("agents", () => {
|
|
|
116
116
|
expect(() => claudeSettings({ specialists: [{ service: "media", claude: { model: "opus", effort: "huge" as "max" } }] }, "media")).toThrow(/effort/);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
it("renders the foreman as a main agent that reaches only the specialist subagents", () => {
|
|
120
|
+
const foreman = "---\nname: foreman\ndescription: Gets the owner's requests done.\ntools: read, subagent\nskills: foreman\n---\nYou are the foreman.\n";
|
|
121
|
+
const facts = "---\nname: foreman\ndescription: Facts\n---\n# Specialists\n\nmedia: the library.\n";
|
|
122
|
+
const text = renderForeman({ agent: foreman, skill: facts, services: ["media", "arcane"], settings: { model: "claude-opus-5-5", effort: "high" } });
|
|
123
|
+
expect(text).toBe(
|
|
124
|
+
[
|
|
125
|
+
"---",
|
|
126
|
+
"name: astro-foreman",
|
|
127
|
+
'description: "Gets the owner\'s requests done."',
|
|
128
|
+
"tools: Read, Agent(astro-media, astro-arcane)",
|
|
129
|
+
"model: claude-opus-5-5",
|
|
130
|
+
"effort: high",
|
|
131
|
+
GENERATED_FIELD,
|
|
132
|
+
"---",
|
|
133
|
+
"In this harness your `subagent` tool is the Agent tool: set `subagent_type` to the specialist's agent (`astro-media`, `astro-arcane`) and give the task as `prompt`. Wait for every report a step needs before you answer; your answer ends the run.",
|
|
134
|
+
"",
|
|
135
|
+
"You are the foreman.",
|
|
136
|
+
"",
|
|
137
|
+
"# Specialists\n\nmedia: the library.",
|
|
138
|
+
"",
|
|
139
|
+
].join("\n"),
|
|
140
|
+
);
|
|
141
|
+
expect(renderForeman({ agent: foreman, skill: null, services: [], settings: { model: "claude-opus-5-5" } })).toContain("\ntools: Read\n");
|
|
142
|
+
expect(() => renderForeman({ agent: "You are the foreman.", skill: null, services: [], settings: { model: "claude-opus-5-5" } })).toThrow("no description");
|
|
143
|
+
});
|
|
144
|
+
|
|
119
145
|
it("renders a subagent with its own MCP server and the skill in its prompt", () => {
|
|
120
146
|
const text = renderAgent({ service: "media", agent, skill, settings: { model: "claude-opus-5-5", effort: "xhigh" }, node: "/opt/homebrew/bin/node", bundle: "/p/harness/claude.js" });
|
|
121
147
|
expect(text).toBe(
|
package/harness/claude/main.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* claude.js serve <service> the specialist's MCP server on stdio
|
|
6
6
|
* claude.js hook the PreToolUse hook: JSON on stdin, a decision on stdout
|
|
7
|
-
* claude.js agents <agents dir> <node> writes astro-<service>.md for every pack specialist
|
|
7
|
+
* claude.js agents <agents dir> <node> writes astro-<service>.md for every pack specialist, and astro-foreman.md
|
|
8
8
|
* claude.js settings <settings.json> <node> adds the hook, allow rules, and time limits
|
|
9
9
|
*
|
|
10
10
|
* `<node>` is the Node the files name, such as /opt/homebrew/bin/node: a stable link, because
|
|
@@ -14,10 +14,10 @@ import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSyn
|
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { createInterface } from "node:readline";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { getAgentDir } from "../../extensions/subagents/pi-paths.ts";
|
|
17
|
+
import { getAgentDir, packageRoot } from "../../extensions/subagents/pi-paths.ts";
|
|
18
18
|
import { loadConfig } from "../../extensions/gate/config.ts";
|
|
19
19
|
import { deniedText, requestApproval } from "../../extensions/gate/core.ts";
|
|
20
|
-
import { claudeSettings, GENERATED_FIELD, type PackFile, renderAgent } from "./agents.ts";
|
|
20
|
+
import { claudeSettings, FOREMAN, GENERATED_FIELD, type PackFile, renderAgent, renderForeman } from "./agents.ts";
|
|
21
21
|
import { agentName, decide, type HookInput, verdict } from "./hook.ts";
|
|
22
22
|
import { SpecialistServer } from "./mcp.ts";
|
|
23
23
|
import { mergeSettings, type Settings } from "./settings.ts";
|
|
@@ -93,7 +93,20 @@ function agents(dir: string, node: string): void {
|
|
|
93
93
|
});
|
|
94
94
|
writeAtomic(join(dir, `${agentName(service)}.md`), text);
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
// The pack's foreman overrides the core's, as in Pi; its facts come from the pack's foreman skill.
|
|
97
|
+
const root = packageRoot();
|
|
98
|
+
const foremanAgent = [join(PACK, "agents", `${FOREMAN}.md`), join(root, "agents", `${FOREMAN}.md`)].find((p) => existsSync(p));
|
|
99
|
+
const foremanSkill = [join(PACK, "skills", FOREMAN, "SKILL.md"), join(root, "skills", FOREMAN, "SKILL.md")].find((p) => existsSync(p));
|
|
100
|
+
if (foremanAgent) {
|
|
101
|
+
const text = renderForeman({
|
|
102
|
+
agent: readFileSync(foremanAgent, "utf-8"),
|
|
103
|
+
skill: foremanSkill ? readFileSync(foremanSkill, "utf-8") : null,
|
|
104
|
+
services: pack.specialists.map((s) => s.service),
|
|
105
|
+
settings: claudeSettings(pack, FOREMAN),
|
|
106
|
+
});
|
|
107
|
+
writeAtomic(join(dir, `${agentName(FOREMAN)}.md`), text);
|
|
108
|
+
}
|
|
109
|
+
process.stdout.write(`${pack.specialists.length} Claude Code specialist agents${foremanAgent ? " and the foreman" : ""} from pack ${pack.version} in ${dir}\n`);
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
function settings(path: string, node: string): void {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrofoundry/astrogate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Astrogate core: isolated agent workspaces with specialists, a foreman, and chat bridges, for the pi coding agent and Claude Code.",
|
|
5
5
|
"packageManager": "pnpm@12.23.0",
|
|
6
6
|
"scripts": {
|
package/release.sha256
CHANGED
|
@@ -3,13 +3,13 @@ b9b0f9fa90b9a230157de1fefef1aa5a624bfd7b50527b67ad86ecc62414aadb agents/foreman
|
|
|
3
3
|
4091f50a5a9ff72e2f1571c6de054d9c891dbe294aa58e6a55ad9a1bff2f766a cli/astro-install.sh
|
|
4
4
|
9f371247fdaea09e1551f940fd91eacb7d242baea343fce66f12fc8e22ba064b cli/astro.sh
|
|
5
5
|
8e054f8286876b77e0887d0b0e2a62d4a048fd41bfa0048d126e0c9171869cf6 cli/astro.test.ts
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
01882995b53a4f528f39668c50256533c8b6aef1f882dbf7d4cd1ec82ff9969f cli/astrogate.sh
|
|
7
|
+
1f8a0d0914b30582793399cf16cebcf6266d3c716f5925919073d2c7e85c4c6e cli/astrogate.test.ts
|
|
8
8
|
07b9aef7e5d0ee43959e0c16e00ec3a202769c94faea4167257513bf15b9383c cli/verify-release.sh
|
|
9
9
|
29614fd0eb1ad08215baf827b00ee2b98ccb73ca0ccf770bc5a0084c71da5926 cli/verify-release.test.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
87077122362031c7496ad6c191c00bd3ab90e39d8901286f78462ddbb7c76bae dist/bridge.js
|
|
11
|
+
06d6ce0f4763fe1552573336ad32e5dff23fc5e1e8a2b4243c974b6f7e439840 dist/claude.js
|
|
12
|
+
04ed58933a8ff2c05d92df0068038a6003c8b2fbc2f323a377fa530a16a3a867 dist/extensions/bridge/index.js
|
|
13
13
|
d407e536d0f10651db55f095203d299f5eea7c570f5eed1543b86e106f3bdc42 dist/extensions/gate/index.js
|
|
14
14
|
ebdfe69e12247c6d240d0e3e5350ab2c9f1af7c520c6cf8202f60c3e2842f5c3 dist/extensions/guard/index.js
|
|
15
15
|
0298f1593f8e59463d750a3806c5f5044f22f376b46006710fb9bd3ffded7dac dist/extensions/subagents/index.js
|
|
@@ -25,7 +25,7 @@ d67c42282ef42aa2b6a3ca127dfb9ab5b5d66d7acc4b3c6b48cf8173e183d8cb extensions/bri
|
|
|
25
25
|
b37b20c17e4637a5aa338429b65e2f634e1a30722caee117fd432d61318758ab extensions/bridge/daemon.ts
|
|
26
26
|
870ede448665e0fbbc540074a9e76f653b7badf74baa8c35ac56d02197b0d5cc extensions/bridge/discord.test.ts
|
|
27
27
|
48427d32a6a4b54c9098c982d14754c80fc33b764faea8749b30ca8ba10a87a1 extensions/bridge/gateway.ts
|
|
28
|
-
|
|
28
|
+
92fe5921666bdbbc90aec5b589c9bf1cca5c5006c112357e4b409567098e0638 extensions/bridge/index.ts
|
|
29
29
|
df97cc953c7c1004aee608bcecd7b3c4969b4f868c63b0320baf3f30540bf4ad extensions/bridge/launcher.ts
|
|
30
30
|
423cf0c6aaf2b9d9d8bdcbdec0f5264c1cac088a31c0d11e7027cb65bc3d8fb5 extensions/bridge/lifecycle.test.ts
|
|
31
31
|
77e2ed89d19006eaa9a2c5664beee3c5978e15417ed47f2788e42b1af24b123b extensions/bridge/open-work.ts
|
|
@@ -63,13 +63,13 @@ e2bbd377a4fa2adf212246b735cdf2df24652422f366cba7a90c7f926722a2da extensions/sub
|
|
|
63
63
|
ff2638595576521db52d5a4c22e485aae21c48fd1d463f2740e9f956320d989d extensions/subagents/sessions.ts
|
|
64
64
|
e76423d9c09263e064e48e6608c6eb07f70bc350841153f7c251376b8b424dc6 extensions/subagents/ticker.test.ts
|
|
65
65
|
54ecfb600920d76eb5ec877c9b8ecc5fc61cb3d865f31bd3893aa5bea6b72fb6 extensions/subagents/ticker.ts
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
6c6ebd83da5f53a7a135ff6bad045757da0724017673cc21b4b78a4dba77d54b harness/claude/agents.ts
|
|
67
|
+
e6a327ff2e489bb9f3ed72d4e7eed207f9f2532e1da9b1d520ccf74aeaf594b5 harness/claude/claude.test.ts
|
|
68
68
|
91fa7a981f8ac4436a6377680a6081570af304efbf1cac21a661122ebaf8a2ba harness/claude/hook.ts
|
|
69
|
-
|
|
69
|
+
9d0f68180f5958ea40550df140a677f611108a402faf94b05669ed7807aa598e harness/claude/main.ts
|
|
70
70
|
e1d07bd981bd4ff6385246b6c1ad41349718c1e490b2bff675291dc7b568cd69 harness/claude/mcp.ts
|
|
71
71
|
194b623038d56a2565ad42d30d1db72ca453e654bfc84996800362e8a972282b harness/claude/settings.ts
|
|
72
|
-
|
|
72
|
+
b5971a8d98fd9011a546ab13f3805cf5bca00552d26ce1e21eb01e30dd3bb4ef package.json
|
|
73
73
|
642383b14db5dbfb7caa6a185591263e4294a73323bf4c78606f7b85f0817fd0 specialists/AGENTS.md
|
|
74
74
|
a385cf5e3b59de30b5ed9b0840d6cf6198b577668f18dfd5de13a714fb047c3e specialists/README.md
|
|
75
75
|
729f8c29d7cf716be5b01d5df869eeda6d4683f86a4915a52fb8adfdebe1f9d2 specialists/entry/specialist-cli.sh
|
package/release.sha256.sig
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
-----BEGIN SSH SIGNATURE-----
|
|
2
2
|
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUteIwPdKqPwfNc4vHQPUE+JWMC
|
|
3
3
|
nmuMUwttLeX5wtyIoAAAAOYXN0cm9nYXRlLWNvcmUAAAAAAAAABnNoYTUxMgAAAFMAAAAL
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
c3NoLWVkMjU1MTkAAABAAwn4E/iPEm295nZbAQe2JW5xgyF2jUlmr7yymi1I+NY97vR1pq
|
|
5
|
+
5DeBq3lN0Vmww3tBwOwVVDTezRcfze2nBgAw==
|
|
6
6
|
-----END SSH SIGNATURE-----
|