@fitlab-ai/agent-infra 0.7.6 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/bin/cli.ts +53 -18
- package/dist/bin/cli.js +56 -19
- package/dist/lib/decide.js +110 -0
- package/dist/lib/run/host.js +39 -0
- package/dist/lib/run/index.js +102 -0
- package/dist/lib/run/prompt.js +2 -0
- package/dist/lib/run/skills.js +29 -0
- package/dist/lib/run/tui.js +35 -0
- package/dist/lib/sandbox/capture.js +49 -0
- package/dist/lib/sandbox/commands/create.js +55 -6
- package/dist/lib/sandbox/commands/ls.js +4 -33
- package/dist/lib/sandbox/commands/show.js +67 -0
- package/dist/lib/sandbox/index.js +7 -0
- package/dist/lib/server/adapters/_contract.js +9 -0
- package/dist/lib/server/adapters/feishu/index.js +40 -0
- package/dist/lib/server/adapters/feishu/transport.js +95 -0
- package/dist/lib/server/auth.js +19 -0
- package/dist/lib/server/config.js +183 -0
- package/dist/lib/server/daemon.js +96 -0
- package/dist/lib/server/index.js +47 -0
- package/dist/lib/server/logger.js +34 -0
- package/dist/lib/server/plugin-loader.js +73 -0
- package/dist/lib/server/process-control.js +200 -0
- package/dist/lib/server/protocol.js +69 -0
- package/dist/lib/server/redact.js +12 -0
- package/dist/lib/server/runner.js +75 -0
- package/dist/lib/server/streamer.js +44 -0
- package/dist/lib/task/commands/decisions.js +258 -0
- package/dist/lib/task/commands/issue-body.js +94 -0
- package/dist/lib/task/commands/log.js +67 -9
- package/dist/lib/task/index.js +17 -0
- package/dist/lib/task/issue-form.js +66 -0
- package/dist/lib/task/ledger.js +66 -0
- package/dist/lib/task/sections.js +73 -0
- package/lib/decide.ts +124 -0
- package/lib/run/host.ts +47 -0
- package/lib/run/index.ts +124 -0
- package/lib/run/prompt.ts +1 -0
- package/lib/run/skills.ts +34 -0
- package/lib/run/tui.ts +40 -0
- package/lib/sandbox/capture.ts +84 -0
- package/lib/sandbox/commands/create.ts +61 -9
- package/lib/sandbox/commands/ls.ts +4 -36
- package/lib/sandbox/commands/show.ts +80 -0
- package/lib/sandbox/index.ts +7 -0
- package/lib/server/adapters/_contract.ts +42 -0
- package/lib/server/adapters/feishu/index.ts +47 -0
- package/lib/server/adapters/feishu/transport.ts +128 -0
- package/lib/server/auth.ts +28 -0
- package/lib/server/config.ts +228 -0
- package/lib/server/daemon.ts +110 -0
- package/lib/server/index.ts +50 -0
- package/lib/server/logger.ts +48 -0
- package/lib/server/plugin-loader.ts +84 -0
- package/lib/server/process-control.ts +225 -0
- package/lib/server/protocol.ts +79 -0
- package/lib/server/redact.ts +12 -0
- package/lib/server/runner.ts +95 -0
- package/lib/server/server.schema.json +127 -0
- package/lib/server/streamer.ts +57 -0
- package/lib/task/commands/decisions.ts +272 -0
- package/lib/task/commands/issue-body.ts +102 -0
- package/lib/task/commands/log.ts +73 -9
- package/lib/task/index.ts +17 -0
- package/lib/task/issue-form.ts +77 -0
- package/lib/task/ledger.ts +73 -0
- package/lib/task/sections.ts +73 -0
- package/package.json +9 -4
- package/templates/.agents/QUICKSTART.zh-CN.md +2 -2
- package/templates/.agents/README.en.md +3 -1
- package/templates/.agents/README.zh-CN.md +3 -1
- package/templates/.agents/rules/create-issue.github.en.md +20 -29
- package/templates/.agents/rules/create-issue.github.zh-CN.md +20 -29
- package/templates/.agents/rules/issue-fields.github.en.md +1 -1
- package/templates/.agents/rules/issue-fields.github.zh-CN.md +1 -1
- package/templates/.agents/rules/issue-pr-commands.github.en.md +6 -0
- package/templates/.agents/rules/issue-pr-commands.github.zh-CN.md +6 -0
- package/templates/.agents/rules/next-step-output.en.md +30 -1
- package/templates/.agents/rules/next-step-output.zh-CN.md +30 -1
- package/templates/.agents/rules/no-mid-flow-questions.en.md +7 -2
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +7 -2
- package/templates/.agents/rules/review-handshake.en.md +5 -1
- package/templates/.agents/rules/review-handshake.zh-CN.md +5 -1
- package/templates/.agents/rules/task-management.en.md +3 -1
- package/templates/.agents/rules/task-management.zh-CN.md +3 -1
- package/templates/.agents/scripts/lib/post-review-commit.js +15 -18
- package/templates/.agents/scripts/validate-artifact.js +8 -0
- package/templates/.agents/skills/analyze-task/SKILL.en.md +18 -4
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +18 -4
- package/templates/.agents/skills/analyze-task/config/verify.en.json +2 -1
- package/templates/.agents/skills/analyze-task/config/verify.zh-CN.json +2 -1
- package/templates/.agents/skills/archive-tasks/SKILL.en.md +3 -1
- package/templates/.agents/skills/archive-tasks/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/block-task/SKILL.en.md +3 -1
- package/templates/.agents/skills/block-task/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/cancel-task/SKILL.en.md +3 -1
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/check-task/SKILL.en.md +30 -81
- package/templates/.agents/skills/check-task/SKILL.zh-CN.md +30 -80
- package/templates/.agents/skills/close-codescan/SKILL.en.md +3 -1
- package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/close-dependabot/SKILL.en.md +3 -1
- package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/code-task/SKILL.en.md +4 -2
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +4 -2
- package/templates/.agents/skills/code-task/reference/dual-mode.en.md +7 -2
- package/templates/.agents/skills/code-task/reference/dual-mode.zh-CN.md +7 -2
- package/templates/.agents/skills/code-task/scripts/detect-mode.js +6 -14
- package/templates/.agents/skills/commit/SKILL.en.md +27 -5
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +27 -5
- package/templates/.agents/skills/complete-task/SKILL.en.md +4 -1
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +4 -1
- package/templates/.agents/skills/complete-task/config/verify.en.json +2 -1
- package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +2 -1
- package/templates/.agents/skills/create-pr/SKILL.en.md +3 -1
- package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/create-release-note/SKILL.en.md +3 -1
- package/templates/.agents/skills/create-release-note/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/create-task/SKILL.en.md +4 -4
- package/templates/.agents/skills/create-task/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/import-codescan/SKILL.en.md +3 -4
- package/templates/.agents/skills/import-codescan/SKILL.zh-CN.md +3 -4
- package/templates/.agents/skills/import-dependabot/SKILL.en.md +3 -2
- package/templates/.agents/skills/import-dependabot/SKILL.zh-CN.md +3 -2
- package/templates/.agents/skills/import-issue/SKILL.en.md +20 -4
- package/templates/.agents/skills/import-issue/SKILL.zh-CN.md +20 -4
- package/templates/.agents/skills/init-labels/SKILL.en.md +3 -1
- package/templates/.agents/skills/init-labels/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/init-milestones/SKILL.en.md +3 -1
- package/templates/.agents/skills/init-milestones/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/plan-task/SKILL.en.md +4 -3
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +4 -3
- package/templates/.agents/skills/post-release/SKILL.en.md +3 -1
- package/templates/.agents/skills/post-release/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/refine-title/SKILL.en.md +3 -1
- package/templates/.agents/skills/refine-title/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/release/SKILL.en.md +3 -1
- package/templates/.agents/skills/release/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/restore-task/SKILL.en.md +3 -1
- package/templates/.agents/skills/restore-task/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/review-analysis/SKILL.en.md +6 -2
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +6 -2
- package/templates/.agents/skills/review-analysis/reference/output-templates.en.md +1 -1
- package/templates/.agents/skills/review-analysis/reference/output-templates.zh-CN.md +1 -1
- package/templates/.agents/skills/review-analysis/reference/report-template.en.md +1 -1
- package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +1 -2
- package/templates/.agents/skills/review-code/SKILL.en.md +5 -2
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +5 -2
- package/templates/.agents/skills/review-code/reference/output-templates.en.md +1 -1
- package/templates/.agents/skills/review-code/reference/output-templates.zh-CN.md +1 -1
- package/templates/.agents/skills/review-code/reference/report-template.en.md +1 -1
- package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +1 -2
- package/templates/.agents/skills/review-plan/SKILL.en.md +6 -2
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +6 -2
- package/templates/.agents/skills/review-plan/reference/output-templates.en.md +1 -1
- package/templates/.agents/skills/review-plan/reference/output-templates.zh-CN.md +1 -1
- package/templates/.agents/skills/review-plan/reference/report-template.en.md +1 -1
- package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +1 -2
- package/templates/.agents/skills/test/SKILL.en.md +3 -1
- package/templates/.agents/skills/test/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/test-integration/SKILL.en.md +3 -1
- package/templates/.agents/skills/test-integration/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/update-agent-infra/SKILL.en.md +3 -1
- package/templates/.agents/skills/update-agent-infra/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/upgrade-dependency/SKILL.en.md +3 -1
- package/templates/.agents/skills/upgrade-dependency/SKILL.zh-CN.md +3 -1
- package/templates/.agents/skills/watch-pr/SKILL.en.md +3 -1
- package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +3 -1
- package/templates/.agents/templates/task.en.md +3 -3
- package/templates/.agents/templates/task.zh-CN.md +3 -3
- package/templates/.github/workflows/metadata-sync.yml +0 -18
|
@@ -514,6 +514,58 @@ function readHostJsonSafe(filePath) {
|
|
|
514
514
|
return null;
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
+
const CLAUDE_SETTINGS_INHERIT_TOP_LEVEL_KEYS = [
|
|
518
|
+
'model',
|
|
519
|
+
'fallbackModel',
|
|
520
|
+
'availableModels',
|
|
521
|
+
'modelOverrides',
|
|
522
|
+
'enforceAvailableModels',
|
|
523
|
+
'advisorModel',
|
|
524
|
+
'apiKeyHelper',
|
|
525
|
+
'effortLevel'
|
|
526
|
+
];
|
|
527
|
+
function isJsonObjectRecord(value) {
|
|
528
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
529
|
+
}
|
|
530
|
+
function mergeMissingStringEnvFields(target, source) {
|
|
531
|
+
if (!isJsonObjectRecord(source.env)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (Object.hasOwn(target, 'env') && !isJsonObjectRecord(target.env)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
let targetEnv = target.env;
|
|
538
|
+
let changed = false;
|
|
539
|
+
for (const [key, value] of Object.entries(source.env)) {
|
|
540
|
+
if (typeof value !== 'string' || value === '') {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (!targetEnv) {
|
|
544
|
+
targetEnv = {};
|
|
545
|
+
target.env = targetEnv;
|
|
546
|
+
}
|
|
547
|
+
if (!Object.hasOwn(targetEnv, key)) {
|
|
548
|
+
targetEnv[key] = value;
|
|
549
|
+
changed = true;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return changed;
|
|
553
|
+
}
|
|
554
|
+
function mergeMissingTopLevelSettings(target, source) {
|
|
555
|
+
let changed = false;
|
|
556
|
+
for (const key of CLAUDE_SETTINGS_INHERIT_TOP_LEVEL_KEYS) {
|
|
557
|
+
if (!Object.hasOwn(source, key) || Object.hasOwn(target, key)) {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
const value = source[key];
|
|
561
|
+
if (value === null || value === undefined || value === '') {
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
target[key] = value;
|
|
565
|
+
changed = true;
|
|
566
|
+
}
|
|
567
|
+
return changed;
|
|
568
|
+
}
|
|
517
569
|
export function ensureClaudeOnboarding(toolDir, hostHomeDir) {
|
|
518
570
|
const claudeJsonPath = path.join(toolDir, '.claude.json');
|
|
519
571
|
let data = {};
|
|
@@ -592,12 +644,9 @@ export function ensureClaudeSettings(toolDir, hostHomeDir) {
|
|
|
592
644
|
}
|
|
593
645
|
if (hostHomeDir) {
|
|
594
646
|
const hostSettings = readHostJsonSafe(path.join(hostHomeDir, '.claude', 'settings.json'));
|
|
595
|
-
if (hostSettings
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
&& !Object.hasOwn(data, 'effortLevel')) {
|
|
599
|
-
data.effortLevel = hostSettings.effortLevel;
|
|
600
|
-
changed = true;
|
|
647
|
+
if (hostSettings) {
|
|
648
|
+
changed = mergeMissingStringEnvFields(data, hostSettings) || changed;
|
|
649
|
+
changed = mergeMissingTopLevelSettings(data, hostSettings) || changed;
|
|
601
650
|
}
|
|
602
651
|
}
|
|
603
652
|
if (changed) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import * as p from '@clack/prompts';
|
|
4
2
|
import pc from 'picocolors';
|
|
5
3
|
import { loadConfig } from "../config.js";
|
|
6
4
|
import { sandboxBranchLabel, sandboxLabel } from "../constants.js";
|
|
7
5
|
import { detectEngine } from "../engine.js";
|
|
8
|
-
import { resolveTools, toolProjectDirCandidates } from "../tools.js";
|
|
9
6
|
import { formatTable } from "../../table.js";
|
|
10
7
|
import { lookupShortIdByBranch } from "../../task/short-id.js";
|
|
11
8
|
import { fetchSandboxRows } from "./list-running.js";
|
|
@@ -18,17 +15,14 @@ id bound to each container's branch (via
|
|
|
18
15
|
.agents/workspace/active/.short-ids.json), or '-' if no active task is
|
|
19
16
|
bound. Pass the SHORT value to "ai sandbox exec" (e.g. 'ai sandbox exec 11').
|
|
20
17
|
A '-' means no active task is bound to that branch, so the sandbox is free
|
|
21
|
-
to remove with "ai sandbox rm <branch>"
|
|
18
|
+
to remove with "ai sandbox rm <branch>".
|
|
19
|
+
|
|
20
|
+
Use "ai sandbox show <ref>" for a single sandbox's worktree and per-tool
|
|
21
|
+
state paths.`;
|
|
22
22
|
const CONTAINER_TABLE_HEADERS = ['#', 'SHORT', 'NAMES', 'STATUS', 'BRANCH'];
|
|
23
23
|
export function formatContainerTable(rows, zebra = false) {
|
|
24
24
|
return formatTable(CONTAINER_TABLE_HEADERS, rows.map((r) => [r.row, r.shortId, r.name, r.status, r.branch]), { zebra });
|
|
25
25
|
}
|
|
26
|
-
function listChildren(dir) {
|
|
27
|
-
if (!fs.existsSync(dir)) {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
return fs.readdirSync(dir).sort().map((entry) => path.join(dir, entry));
|
|
31
|
-
}
|
|
32
26
|
export function ls(args = []) {
|
|
33
27
|
if (args.length > 0 && (args[0] === '--help' || args[0] === '-h')) {
|
|
34
28
|
process.stdout.write(`${USAGE}\n`);
|
|
@@ -36,7 +30,6 @@ export function ls(args = []) {
|
|
|
36
30
|
}
|
|
37
31
|
const config = loadConfig();
|
|
38
32
|
const engine = detectEngine(config);
|
|
39
|
-
const tools = resolveTools(config);
|
|
40
33
|
const label = sandboxLabel(config);
|
|
41
34
|
const { running, nonRunning } = fetchSandboxRows(engine, label, sandboxBranchLabel(config));
|
|
42
35
|
p.intro(pc.cyan(`Sandbox status for ${config.project}`));
|
|
@@ -64,27 +57,5 @@ export function ls(args = []) {
|
|
|
64
57
|
process.stdout.write(` SHORT '-' = no active task bound; that sandbox is free to remove with 'ai sandbox rm <branch>'.\n`);
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
|
-
p.log.step('Worktrees');
|
|
68
|
-
const worktrees = listChildren(config.worktreeBase);
|
|
69
|
-
if (worktrees.length === 0) {
|
|
70
|
-
p.log.warn(' No sandbox worktrees');
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
for (const worktree of worktrees) {
|
|
74
|
-
process.stdout.write(` ${worktree}\n`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
for (const tool of tools) {
|
|
78
|
-
p.log.step(`${tool.name} state`);
|
|
79
|
-
const entries = toolProjectDirCandidates(tool, config.project)
|
|
80
|
-
.flatMap((dir) => listChildren(dir));
|
|
81
|
-
if (entries.length === 0) {
|
|
82
|
-
p.log.warn(` No ${tool.name} sandbox state`);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
for (const entry of entries) {
|
|
86
|
-
process.stdout.write(` ${entry}\n`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
60
|
}
|
|
90
61
|
//# sourceMappingURL=ls.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import * as p from '@clack/prompts';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import { loadConfig } from "../config.js";
|
|
5
|
+
import { assertValidBranchName, worktreeDirCandidates } from "../constants.js";
|
|
6
|
+
import { resolveBranchArg } from "./list-running.js";
|
|
7
|
+
import { resolveTools, toolConfigDirCandidates } from "../tools.js";
|
|
8
|
+
const USAGE = `Usage: ai sandbox show <branch | TASK-id | N | '#N'>
|
|
9
|
+
|
|
10
|
+
Shows one sandbox's worktree path and per-tool state paths (Claude Code,
|
|
11
|
+
Codex, Gemini CLI, OpenCode). The argument follows the same contract as
|
|
12
|
+
'ai sandbox exec' and 'ai sandbox start': N (bare) is the recommended form
|
|
13
|
+
for task short ids (e.g. 'ai sandbox show 11'); '#N', a TASK-id, or a plain
|
|
14
|
+
branch name are also accepted. Use 'ai sandbox ls' for the container list.`;
|
|
15
|
+
function existingDirs(candidates) {
|
|
16
|
+
const seen = new Set();
|
|
17
|
+
const result = [];
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
if (!seen.has(candidate) && fs.existsSync(candidate)) {
|
|
20
|
+
seen.add(candidate);
|
|
21
|
+
result.push(candidate);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
export function collectSandboxDetail(config, branch) {
|
|
27
|
+
const worktrees = existingDirs(worktreeDirCandidates(config, branch));
|
|
28
|
+
const toolStates = resolveTools(config).map((tool) => ({
|
|
29
|
+
name: tool.name,
|
|
30
|
+
entries: existingDirs(toolConfigDirCandidates(tool, config.project, branch))
|
|
31
|
+
}));
|
|
32
|
+
return { worktrees, toolStates };
|
|
33
|
+
}
|
|
34
|
+
export function show(args = []) {
|
|
35
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
36
|
+
process.stdout.write(`${USAGE}\n`);
|
|
37
|
+
if (args.length === 0) {
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const config = loadConfig();
|
|
43
|
+
const branch = resolveBranchArg(args[0], { repoRoot: config.repoRoot });
|
|
44
|
+
assertValidBranchName(branch);
|
|
45
|
+
const detail = collectSandboxDetail(config, branch);
|
|
46
|
+
p.intro(pc.cyan(`Sandbox detail for ${config.project} · ${branch}`));
|
|
47
|
+
p.log.step('Worktree');
|
|
48
|
+
if (detail.worktrees.length === 0) {
|
|
49
|
+
p.log.warn(' No worktree for this branch');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
for (const worktree of detail.worktrees) {
|
|
53
|
+
process.stdout.write(` ${worktree}\n`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const tool of detail.toolStates) {
|
|
57
|
+
p.log.step(`${tool.name} state`);
|
|
58
|
+
if (tool.entries.length === 0) {
|
|
59
|
+
p.log.warn(` No ${tool.name} sandbox state`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const entry of tool.entries) {
|
|
63
|
+
process.stdout.write(` ${entry}\n`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=show.js.map
|
|
@@ -9,6 +9,8 @@ Commands:
|
|
|
9
9
|
ls List sandboxes for the current project (the '#'
|
|
10
10
|
column is a display-only row number; the 'SHORT'
|
|
11
11
|
column shows the active task short id, '-' if none)
|
|
12
|
+
show <branch | TASK-id | N | '#N'>
|
|
13
|
+
Show one sandbox's worktree and per-tool state paths
|
|
12
14
|
prune [--dry-run] Remove orphaned per-branch state dirs
|
|
13
15
|
rebuild [--quiet] [--refresh]
|
|
14
16
|
Rebuild the sandbox image (--refresh pulls base + tools)
|
|
@@ -52,6 +54,11 @@ export async function runSandbox(args) {
|
|
|
52
54
|
ls(rest);
|
|
53
55
|
break;
|
|
54
56
|
}
|
|
57
|
+
case 'show': {
|
|
58
|
+
const { show } = await import("./commands/show.js");
|
|
59
|
+
show(rest);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
55
62
|
case 'prune': {
|
|
56
63
|
const { prune } = await import("./commands/prune.js");
|
|
57
64
|
await prune(rest);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Adapter contract for agent-infra-server.
|
|
2
|
+
//
|
|
3
|
+
// This is a pure type + constant module: it carries no runtime logic and no
|
|
4
|
+
// third-party imports. Subtask B (the feishu adapter) and subtask C (the
|
|
5
|
+
// command protocol / runner) build against these shapes. Bump
|
|
6
|
+
// ADAPTER_CONTRACT_VERSION on a breaking change so plugin-loader can reject
|
|
7
|
+
// adapters compiled against an older contract.
|
|
8
|
+
export const ADAPTER_CONTRACT_VERSION = 1;
|
|
9
|
+
//# sourceMappingURL=_contract.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createFeishuTransport, normalizeMessage } from "./transport.js";
|
|
2
|
+
// Assemble the feishu adapter. The transport is injectable so unit tests can
|
|
3
|
+
// drive start/dispatch/reply/sendMessage against a fake transport without the
|
|
4
|
+
// real SDK; production uses the default SDK-backed transport.
|
|
5
|
+
export function createFeishuAdapter(config, transport = createFeishuTransport(config)) {
|
|
6
|
+
let ctx = null;
|
|
7
|
+
return {
|
|
8
|
+
name: 'feishu',
|
|
9
|
+
async start(adapterCtx) {
|
|
10
|
+
ctx = adapterCtx;
|
|
11
|
+
await transport.start(async (raw) => {
|
|
12
|
+
try {
|
|
13
|
+
const normalized = normalizeMessage(raw);
|
|
14
|
+
const message = {
|
|
15
|
+
adapter: 'feishu',
|
|
16
|
+
userId: normalized.userId,
|
|
17
|
+
chatId: normalized.chatId,
|
|
18
|
+
text: normalized.text,
|
|
19
|
+
messageId: normalized.messageId,
|
|
20
|
+
raw: normalized.raw,
|
|
21
|
+
reply: (text) => transport.send(normalized.chatId, text)
|
|
22
|
+
};
|
|
23
|
+
await adapterCtx.dispatch(message);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
ctx?.logger.err(`feishu: dropped message: ${error instanceof Error ? error.message : String(error)}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
async stop() {
|
|
31
|
+
await transport.stop();
|
|
32
|
+
},
|
|
33
|
+
async sendMessage(target, text) {
|
|
34
|
+
await transport.send(target.chatId, text);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const factory = (adapterConfig) => createFeishuAdapter(adapterConfig);
|
|
39
|
+
export default factory;
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as lark from '@larksuiteoapi/node-sdk';
|
|
2
|
+
function asRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null ? value : {};
|
|
4
|
+
}
|
|
5
|
+
// Strip feishu mention placeholders (e.g. "@_user_1") that the platform injects
|
|
6
|
+
// for @-mentions, then collapse surrounding whitespace. A group message like
|
|
7
|
+
// "@_user_1 /ping" normalizes to "/ping" so the daemon dispatcher matches it.
|
|
8
|
+
function stripMentions(text) {
|
|
9
|
+
return text.replace(/@_user_\d+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
10
|
+
}
|
|
11
|
+
// Parse an im.message.receive_v1 event into the daemon's shape. Pure: no SDK,
|
|
12
|
+
// no IO. Throws on missing/invalid fields so the adapter can drop a single bad
|
|
13
|
+
// message without crashing the long connection.
|
|
14
|
+
export function normalizeMessage(event) {
|
|
15
|
+
const message = asRecord(asRecord(event).message);
|
|
16
|
+
const messageId = message.message_id;
|
|
17
|
+
const chatId = message.chat_id;
|
|
18
|
+
const content = message.content;
|
|
19
|
+
if (typeof messageId !== 'string' || typeof chatId !== 'string' || typeof content !== 'string') {
|
|
20
|
+
throw new Error('feishu: malformed im.message.receive_v1 event (missing message_id/chat_id/content)');
|
|
21
|
+
}
|
|
22
|
+
const senderId = asRecord(asRecord(asRecord(event).sender).sender_id);
|
|
23
|
+
const userId = (typeof senderId.open_id === 'string' && senderId.open_id) ||
|
|
24
|
+
(typeof senderId.union_id === 'string' && senderId.union_id) ||
|
|
25
|
+
(typeof senderId.user_id === 'string' && senderId.user_id) ||
|
|
26
|
+
'';
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(content);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new Error('feishu: message.content is not valid JSON');
|
|
33
|
+
}
|
|
34
|
+
const rawText = asRecord(parsed).text;
|
|
35
|
+
if (typeof rawText !== 'string') {
|
|
36
|
+
throw new Error('feishu: unsupported message content (no text field)');
|
|
37
|
+
}
|
|
38
|
+
return { userId, chatId, text: stripMentions(rawText), messageId, raw: event };
|
|
39
|
+
}
|
|
40
|
+
function resolveDomain(value) {
|
|
41
|
+
return value === 'lark' || value === 'Lark' ? lark.Domain.Lark : lark.Domain.Feishu;
|
|
42
|
+
}
|
|
43
|
+
// Build the real SDK-backed transport from adapter config. appId/appSecret come
|
|
44
|
+
// from server config (appSecret only via server.local.json / env). The WSClient
|
|
45
|
+
// long connection delivers events; the Client REST call sends replies.
|
|
46
|
+
// Feishu self-built app IDs have this shape; the SDK's WSClient.start() silently
|
|
47
|
+
// rejects anything else, so we validate up front to fail loudly instead.
|
|
48
|
+
const APP_ID_PATTERN = /^cli_[0-9a-fA-F]{16}$/;
|
|
49
|
+
export function createFeishuTransport(config) {
|
|
50
|
+
const appId = String(config.appId ?? '').trim();
|
|
51
|
+
const appSecret = String(config.appSecret ?? '').trim();
|
|
52
|
+
const domain = resolveDomain(config.domain);
|
|
53
|
+
// Fail fast on missing or malformed credentials. The SDK only logs to its own
|
|
54
|
+
// logger and resolves WSClient.start() for an empty or malformed appId, so
|
|
55
|
+
// without these checks an enabled-but-misconfigured feishu adapter would be
|
|
56
|
+
// counted as loaded while the long connection never opens. Throwing here lets
|
|
57
|
+
// loadAdapters log `failed to load adapter "feishu": ...` and skip it.
|
|
58
|
+
if (appId === '' || appSecret === '') {
|
|
59
|
+
throw new Error('feishu: appId and appSecret are required; put appSecret in .agents/server.local.json or AGENT_INFRA_SERVER_adapters__feishu__appSecret');
|
|
60
|
+
}
|
|
61
|
+
if (!APP_ID_PATTERN.test(appId)) {
|
|
62
|
+
throw new Error('feishu: appId must match cli_[0-9a-fA-F]{16}');
|
|
63
|
+
}
|
|
64
|
+
const client = new lark.Client({ appId, appSecret, domain });
|
|
65
|
+
const wsClient = new lark.WSClient({ appId, appSecret, domain, loggerLevel: lark.LoggerLevel.warn });
|
|
66
|
+
return {
|
|
67
|
+
async start(onMessage) {
|
|
68
|
+
const eventDispatcher = new lark.EventDispatcher({}).register({
|
|
69
|
+
'im.message.receive_v1': async (data) => {
|
|
70
|
+
await onMessage(data);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
wsClient.start({ eventDispatcher });
|
|
74
|
+
},
|
|
75
|
+
async stop() {
|
|
76
|
+
// Best-effort: close the long connection if the SDK exposes it. Never throw
|
|
77
|
+
// from shutdown — unloadAdapters isolates stop failures, but staying quiet
|
|
78
|
+
// keeps the daemon shutdown path clean.
|
|
79
|
+
const closable = wsClient;
|
|
80
|
+
try {
|
|
81
|
+
closable.close?.();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Ignore: the daemon is shutting down regardless.
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async send(chatId, text) {
|
|
88
|
+
await client.im.message.create({
|
|
89
|
+
params: { receive_id_type: 'chat_id' },
|
|
90
|
+
data: { receive_id: chatId, msg_type: 'text', content: JSON.stringify({ text }) }
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const ROLE_RANK = { read: 1, write: 2, exec: 3 };
|
|
2
|
+
function userRole(auth, key) {
|
|
3
|
+
const users = auth.users;
|
|
4
|
+
if (!users || typeof users !== 'object' || Array.isArray(users))
|
|
5
|
+
return null;
|
|
6
|
+
const record = users[key];
|
|
7
|
+
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
8
|
+
return null;
|
|
9
|
+
const role = record.role;
|
|
10
|
+
return role === 'read' || role === 'write' || role === 'exec' ? role : null;
|
|
11
|
+
}
|
|
12
|
+
export function authorize(user, required, auth) {
|
|
13
|
+
const role = userRole(auth ?? {}, `${user.adapter}:${user.userId}`);
|
|
14
|
+
if (!role || ROLE_RANK[role] < ROLE_RANK[required]) {
|
|
15
|
+
return { ok: false, message: `requires ${required}` };
|
|
16
|
+
}
|
|
17
|
+
return { ok: true };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
const ENV_PREFIX = 'AGENT_INFRA_SERVER_';
|
|
7
|
+
// Keys whose presence in the *committed* server.json is treated as a leaked
|
|
8
|
+
// secret. Secrets belong in .agents/server.local.json or the environment.
|
|
9
|
+
const SECRET_KEY_PATTERN = /secret|token|password|passwd|credential|apikey|api_key/i;
|
|
10
|
+
const DEFAULT_ROTATE_BYTES = 52_428_800; // 50 MiB
|
|
11
|
+
export const DEFAULT_SERVER_CONFIG = {
|
|
12
|
+
log: { rotateAtBytes: DEFAULT_ROTATE_BYTES },
|
|
13
|
+
heartbeatMs: 30_000,
|
|
14
|
+
adapters: {}
|
|
15
|
+
};
|
|
16
|
+
function isPlainObject(value) {
|
|
17
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
// Daemon runtime state (log + PID) lives OUTSIDE the repo, under the user's home
|
|
20
|
+
// directory, keyed by the .airc.json "project" AND a stable hash of the repo
|
|
21
|
+
// root path:
|
|
22
|
+
// ~/.agent-infra/logs/<project>/<repo-hash>/server.log
|
|
23
|
+
// ~/.agent-infra/run/<project>/<repo-hash>/server.pid
|
|
24
|
+
// The <project> segment groups a project's checkouts for readability; the
|
|
25
|
+
// <repo-hash> segment guarantees that two checkouts/worktrees of the same
|
|
26
|
+
// project (same "project" but different absolute path) get ISOLATED runtime
|
|
27
|
+
// dirs, so they never read/control each other's daemon. Using os.homedir() +
|
|
28
|
+
// path.join keeps this correct on Windows too (C:\Users\<name>\.agent-infra\...).
|
|
29
|
+
// An explicit log.path in server.json/.local/env still overrides the log default.
|
|
30
|
+
function resolveProjectKey(repoRoot) {
|
|
31
|
+
try {
|
|
32
|
+
const airc = JSON.parse(fs.readFileSync(path.join(repoRoot, '.agents', '.airc.json'), 'utf8'));
|
|
33
|
+
if (typeof airc.project === 'string' && airc.project.trim() !== '') {
|
|
34
|
+
return airc.project.trim();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// No .airc.json / unreadable → fall back to the repo directory name.
|
|
39
|
+
}
|
|
40
|
+
return path.basename(repoRoot);
|
|
41
|
+
}
|
|
42
|
+
// Short, stable, filesystem-safe discriminator for a checkout's absolute path.
|
|
43
|
+
function repoKey(repoRoot) {
|
|
44
|
+
return createHash('sha256').update(repoRoot).digest('hex').slice(0, 12);
|
|
45
|
+
}
|
|
46
|
+
function runtimePath(repoRoot, projectKey, kind, file) {
|
|
47
|
+
return path.join(homedir(), '.agent-infra', kind, projectKey, repoKey(repoRoot), file);
|
|
48
|
+
}
|
|
49
|
+
function detectRepoRoot() {
|
|
50
|
+
try {
|
|
51
|
+
return execFileSync('git', ['rev-parse', '--show-toplevel'], {
|
|
52
|
+
encoding: 'utf8',
|
|
53
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
54
|
+
}).trim();
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new Error('server: current directory is not inside a git repository');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Plain-object deep merge: objects recurse, everything else (arrays, scalars)
|
|
61
|
+
// replaces. Intentionally small — server config is shallow and this avoids
|
|
62
|
+
// coupling to lib/merge.ts, whose semantics target the task workspace.
|
|
63
|
+
function deepMerge(base, override) {
|
|
64
|
+
const result = { ...base };
|
|
65
|
+
for (const [key, value] of Object.entries(override)) {
|
|
66
|
+
const current = result[key];
|
|
67
|
+
if (isPlainObject(current) && isPlainObject(value)) {
|
|
68
|
+
result[key] = deepMerge(current, value);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
result[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function readJsonIfPresent(filePath) {
|
|
77
|
+
if (!fs.existsSync(filePath))
|
|
78
|
+
return {};
|
|
79
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
80
|
+
if (!isPlainObject(parsed)) {
|
|
81
|
+
throw new Error(`server: ${path.basename(filePath)} must contain a JSON object`);
|
|
82
|
+
}
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
function coerceEnvValue(raw) {
|
|
86
|
+
if (raw === 'true')
|
|
87
|
+
return true;
|
|
88
|
+
if (raw === 'false')
|
|
89
|
+
return false;
|
|
90
|
+
if (raw !== '' && !Number.isNaN(Number(raw)))
|
|
91
|
+
return Number(raw);
|
|
92
|
+
return raw;
|
|
93
|
+
}
|
|
94
|
+
// Map AGENT_INFRA_SERVER_<path> env vars into a nested override object. The
|
|
95
|
+
// path after the prefix uses `__` to separate nesting levels and is treated
|
|
96
|
+
// case-sensitively (e.g. AGENT_INFRA_SERVER_adapters__dev__enabled=false ->
|
|
97
|
+
// { adapters: { dev: { enabled: false } } }).
|
|
98
|
+
function envOverrides(env) {
|
|
99
|
+
const override = {};
|
|
100
|
+
for (const [key, rawValue] of Object.entries(env)) {
|
|
101
|
+
if (!key.startsWith(ENV_PREFIX) || rawValue === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
const segments = key.slice(ENV_PREFIX.length).split('__').filter(Boolean);
|
|
104
|
+
if (segments.length === 0)
|
|
105
|
+
continue;
|
|
106
|
+
let cursor = override;
|
|
107
|
+
for (let i = 0; i < segments.length - 1; i += 1) {
|
|
108
|
+
const segment = segments[i];
|
|
109
|
+
const next = cursor[segment];
|
|
110
|
+
if (!isPlainObject(next)) {
|
|
111
|
+
cursor[segment] = {};
|
|
112
|
+
}
|
|
113
|
+
cursor = cursor[segment];
|
|
114
|
+
}
|
|
115
|
+
cursor[segments[segments.length - 1]] = coerceEnvValue(rawValue);
|
|
116
|
+
}
|
|
117
|
+
return override;
|
|
118
|
+
}
|
|
119
|
+
// Collect dotted paths of secret-looking, non-empty string fields.
|
|
120
|
+
function collectSecretFields(value, trail = []) {
|
|
121
|
+
if (!isPlainObject(value))
|
|
122
|
+
return [];
|
|
123
|
+
const found = [];
|
|
124
|
+
for (const [key, child] of Object.entries(value)) {
|
|
125
|
+
const here = [...trail, key];
|
|
126
|
+
if (SECRET_KEY_PATTERN.test(key) && typeof child === 'string' && child.trim() !== '') {
|
|
127
|
+
found.push(here.join('.'));
|
|
128
|
+
}
|
|
129
|
+
else if (isPlainObject(child)) {
|
|
130
|
+
found.push(...collectSecretFields(child, here));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return found;
|
|
134
|
+
}
|
|
135
|
+
// Reject secrets that live in the committed server.json. server.local.json and
|
|
136
|
+
// the environment are the sanctioned places for secrets and are not scanned.
|
|
137
|
+
export function validateServerConfig(committed) {
|
|
138
|
+
const fields = collectSecretFields(committed);
|
|
139
|
+
if (fields.length > 0) {
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
fields,
|
|
143
|
+
error: `server: refusing to start — secret-like field(s) found in committed .agents/server.json: ${fields.join(', ')}. ` +
|
|
144
|
+
'Move them to .agents/server.local.json or AGENT_INFRA_SERVER_* environment variables.'
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return { ok: true };
|
|
148
|
+
}
|
|
149
|
+
export function loadServerConfig({ rootDir } = {}) {
|
|
150
|
+
const repoRoot = rootDir ?? detectRepoRoot();
|
|
151
|
+
const agentsDir = path.join(repoRoot, '.agents');
|
|
152
|
+
const committed = readJsonIfPresent(path.join(agentsDir, 'server.json'));
|
|
153
|
+
const validation = validateServerConfig(committed);
|
|
154
|
+
if (!validation.ok) {
|
|
155
|
+
throw new Error(validation.error);
|
|
156
|
+
}
|
|
157
|
+
const local = readJsonIfPresent(path.join(agentsDir, 'server.local.json'));
|
|
158
|
+
let merged = deepMerge({ log: { rotateAtBytes: DEFAULT_ROTATE_BYTES }, heartbeatMs: DEFAULT_SERVER_CONFIG.heartbeatMs, adapters: {} }, committed);
|
|
159
|
+
merged = deepMerge(merged, local);
|
|
160
|
+
merged = deepMerge(merged, envOverrides(process.env));
|
|
161
|
+
const projectKey = resolveProjectKey(repoRoot);
|
|
162
|
+
const log = isPlainObject(merged.log) ? merged.log : {};
|
|
163
|
+
// No explicit log.path → default under ~/.agent-infra/logs/<project>/.
|
|
164
|
+
// Explicit relative path resolves against the repo root; absolute is used as-is.
|
|
165
|
+
const explicitPath = typeof log.path === 'string' ? log.path : null;
|
|
166
|
+
const resolvedLogPath = explicitPath === null
|
|
167
|
+
? runtimePath(repoRoot, projectKey, 'logs', 'server.log')
|
|
168
|
+
: (path.isAbsolute(explicitPath) ? explicitPath : path.join(repoRoot, explicitPath));
|
|
169
|
+
return {
|
|
170
|
+
repoRoot,
|
|
171
|
+
pidFile: runtimePath(repoRoot, projectKey, 'run', 'server.pid'),
|
|
172
|
+
log: {
|
|
173
|
+
path: resolvedLogPath,
|
|
174
|
+
rotateAtBytes: typeof log.rotateAtBytes === 'number' ? log.rotateAtBytes : DEFAULT_ROTATE_BYTES
|
|
175
|
+
},
|
|
176
|
+
heartbeatMs: typeof merged.heartbeatMs === 'number' ? merged.heartbeatMs : DEFAULT_SERVER_CONFIG.heartbeatMs,
|
|
177
|
+
adapters: isPlainObject(merged.adapters) ? merged.adapters : {},
|
|
178
|
+
command: isPlainObject(merged.command) ? merged.command : undefined,
|
|
179
|
+
auth: isPlainObject(merged.auth) ? merged.auth : undefined,
|
|
180
|
+
stream: isPlainObject(merged.stream) ? merged.stream : undefined
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=config.js.map
|