@fitlab-ai/agent-infra 0.7.3 → 0.7.4
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 +32 -790
- package/README.zh-CN.md +32 -763
- package/bin/cli.ts +1 -1
- package/dist/bin/cli.js +1 -1
- package/dist/lib/sandbox/commands/create.js +44 -3
- package/dist/lib/sandbox/commands/rm.js +99 -19
- package/dist/lib/sandbox/index.js +3 -1
- package/dist/lib/sandbox/readme-scaffold.js +6 -6
- package/dist/lib/task/artifacts.js +58 -0
- package/dist/lib/task/commands/cat.js +38 -0
- package/dist/lib/task/commands/files.js +47 -0
- package/dist/lib/task/commands/grep.js +143 -0
- package/dist/lib/task/commands/log.js +75 -0
- package/dist/lib/task/commands/show.js +5 -114
- package/dist/lib/task/commands/status.js +239 -0
- package/dist/lib/task/index.js +37 -0
- package/dist/lib/task/resolve-ref.js +150 -0
- package/lib/sandbox/commands/create.ts +47 -4
- package/lib/sandbox/commands/rm.ts +128 -19
- package/lib/sandbox/index.ts +3 -1
- package/lib/sandbox/readme-scaffold.ts +6 -6
- package/lib/task/artifacts.ts +72 -0
- package/lib/task/commands/cat.ts +39 -0
- package/lib/task/commands/files.ts +53 -0
- package/lib/task/commands/grep.ts +147 -0
- package/lib/task/commands/log.ts +80 -0
- package/lib/task/commands/show.ts +5 -117
- package/lib/task/commands/status.ts +302 -0
- package/lib/task/index.ts +37 -0
- package/lib/task/resolve-ref.ts +160 -0
- package/package.json +1 -1
- package/templates/.agents/README.en.md +1 -0
- package/templates/.agents/README.zh-CN.md +1 -0
- package/templates/.agents/rules/README.en.md +41 -0
- package/templates/.agents/rules/README.zh-CN.md +40 -0
- package/templates/.agents/rules/debugging-guide.en.md +25 -0
- package/templates/.agents/rules/debugging-guide.zh-CN.md +25 -0
- package/templates/.agents/skills/code-task/SKILL.en.md +2 -0
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +2 -0
- package/templates/.agents/skills/watch-pr/SKILL.en.md +1 -1
- package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +1 -1
package/bin/cli.ts
CHANGED
|
@@ -18,7 +18,7 @@ Usage:
|
|
|
18
18
|
agent-infra init Initialize a new project with update-agent-infra seed command
|
|
19
19
|
agent-infra merge Merge tasks from another workspace directory (active/blocked/completed/archive)
|
|
20
20
|
agent-infra sandbox Manage Docker-based AI sandboxes
|
|
21
|
-
agent-infra task Read-only views over .agents/workspace tasks (ls / show)
|
|
21
|
+
agent-infra task Read-only views over .agents/workspace tasks (ls / show / files / cat / status / log / grep)
|
|
22
22
|
agent-infra update Update seed files and sync file registry for an existing project
|
|
23
23
|
agent-infra version Show version
|
|
24
24
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -22,7 +22,7 @@ Usage:
|
|
|
22
22
|
agent-infra init Initialize a new project with update-agent-infra seed command
|
|
23
23
|
agent-infra merge Merge tasks from another workspace directory (active/blocked/completed/archive)
|
|
24
24
|
agent-infra sandbox Manage Docker-based AI sandboxes
|
|
25
|
-
agent-infra task Read-only views over .agents/workspace tasks (ls / show)
|
|
25
|
+
agent-infra task Read-only views over .agents/workspace tasks (ls / show / files / cat / status / log / grep)
|
|
26
26
|
agent-infra update Update seed files and sync file registry for an existing project
|
|
27
27
|
agent-infra version Show version
|
|
28
28
|
|
|
@@ -604,7 +604,32 @@ export function ensureClaudeSettings(toolDir, hostHomeDir) {
|
|
|
604
604
|
fs.writeFileSync(settingsPath, JSON.stringify(data, null, 4), 'utf8');
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
|
-
|
|
607
|
+
function resolveHostCatalogPath(value, hostHomeDir) {
|
|
608
|
+
if (typeof value !== 'string' || value === '') {
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
let resolved;
|
|
612
|
+
if (value === '~' || value.startsWith('~/') || value.startsWith('~\\')) {
|
|
613
|
+
resolved = path.join(hostHomeDir, value.slice(1).replace(/^[/\\]+/, ''));
|
|
614
|
+
}
|
|
615
|
+
else if (path.isAbsolute(value)) {
|
|
616
|
+
resolved = value;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
resolved = path.join(hostHomeDir, '.codex', value);
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
if (!fs.statSync(resolved).isFile()) {
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
fs.accessSync(resolved, fs.constants.R_OK);
|
|
626
|
+
return resolved;
|
|
627
|
+
}
|
|
628
|
+
catch {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
export function ensureCodexModelInheritance(toolDir, hostHomeDir, containerCodexDir = '/home/devuser/.codex') {
|
|
608
633
|
if (!hostHomeDir) {
|
|
609
634
|
return;
|
|
610
635
|
}
|
|
@@ -650,6 +675,22 @@ export function ensureCodexModelInheritance(toolDir, hostHomeDir) {
|
|
|
650
675
|
sandboxParsed[key] = value;
|
|
651
676
|
changed = true;
|
|
652
677
|
}
|
|
678
|
+
if (!Object.hasOwn(sandboxParsed, 'model_catalog_json')) {
|
|
679
|
+
const hostCatalogPath = resolveHostCatalogPath(hostParsed['model_catalog_json'], hostHomeDir);
|
|
680
|
+
if (hostCatalogPath) {
|
|
681
|
+
try {
|
|
682
|
+
const basename = path.basename(hostCatalogPath);
|
|
683
|
+
const destDir = path.join(toolDir, 'model-catalogs');
|
|
684
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
685
|
+
fs.copyFileSync(hostCatalogPath, path.join(destDir, basename));
|
|
686
|
+
sandboxParsed['model_catalog_json'] = path.posix.join(containerCodexDir, 'model-catalogs', basename);
|
|
687
|
+
changed = true;
|
|
688
|
+
}
|
|
689
|
+
catch {
|
|
690
|
+
// Copy failed (e.g. permissions): skip catalog, keep scalar inheritance intact.
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
653
694
|
if (changed) {
|
|
654
695
|
fs.writeFileSync(sandboxConfigPath, `${toml.stringify(sandboxParsed)}\n`, 'utf8');
|
|
655
696
|
}
|
|
@@ -780,7 +821,7 @@ function runEngineTaskCommand(engine, cmd, args, opts = {}) {
|
|
|
780
821
|
return runTaskCommand(command.cmd, command.args, opts);
|
|
781
822
|
}
|
|
782
823
|
export function buildImage(config, tools, dockerfilePath, imageSignature, { engine, runFn = runEngine, runSafeFn = runSafeEngine, runVerboseFn = runVerboseEngine, env = process.env } = {}) {
|
|
783
|
-
const selectedEngine = engine ?? detectEngine(config);
|
|
824
|
+
const selectedEngine = engine ?? detectEngine({ engine: config.engine });
|
|
784
825
|
const { uid: hostUid, gid: hostGid } = resolveBuildUid({
|
|
785
826
|
engine: selectedEngine,
|
|
786
827
|
runFn,
|
|
@@ -1023,7 +1064,7 @@ export async function create(args) {
|
|
|
1023
1064
|
}
|
|
1024
1065
|
const codexEntry = effectiveResolvedTools.find(({ tool }) => tool.id === 'codex');
|
|
1025
1066
|
if (codexEntry) {
|
|
1026
|
-
ensureCodexModelInheritance(codexEntry.dir, effectiveConfig.home);
|
|
1067
|
+
ensureCodexModelInheritance(codexEntry.dir, effectiveConfig.home, codexEntry.tool.containerMount);
|
|
1027
1068
|
ensureCodexWorkspaceTrust(codexEntry.dir);
|
|
1028
1069
|
}
|
|
1029
1070
|
const geminiEntry = effectiveResolvedTools.find(({ tool }) => tool.id === 'gemini-cli');
|
|
@@ -11,12 +11,17 @@ import { removeManagedDir, removeWorktreeDir } from "../managed-fs.js";
|
|
|
11
11
|
import { runOk, runSafe, runSafeEngine } from "../shell.js";
|
|
12
12
|
import { resolveTaskBranch } from "../task-resolver.js";
|
|
13
13
|
import { resolveTools, toolConfigDirCandidates, toolProjectDirCandidates } from "../tools.js";
|
|
14
|
-
|
|
14
|
+
import { fetchSandboxRows } from "./list-running.js";
|
|
15
|
+
import { lookupShortIdByBranch } from "../../task/short-id.js";
|
|
16
|
+
const USAGE = `Usage:
|
|
17
|
+
ai sandbox rm <branch> Remove one sandbox (branch | TASK-id | short id)
|
|
18
|
+
ai sandbox rm --all [--dry-run] [--yes] Remove every sandbox not bound to an active task
|
|
19
|
+
ai sandbox rm --purge Tear down ALL sandboxes for the project (containers, worktrees, image, VM)`;
|
|
15
20
|
export { assertManagedPath } from "../managed-fs.js";
|
|
16
21
|
function projectToolDirs(config, tools) {
|
|
17
22
|
return tools.flatMap((tool) => toolProjectDirCandidates(tool, config.project));
|
|
18
23
|
}
|
|
19
|
-
async function rmOne(config, tools, branch) {
|
|
24
|
+
async function rmOne(config, tools, branch, options = {}) {
|
|
20
25
|
assertValidBranchName(branch);
|
|
21
26
|
const engine = detectEngine(config);
|
|
22
27
|
let effectiveBranch = branch;
|
|
@@ -25,7 +30,9 @@ async function rmOne(config, tools, branch) {
|
|
|
25
30
|
tool,
|
|
26
31
|
candidates: toolConfigDirCandidates(tool, config.project, branch)
|
|
27
32
|
}));
|
|
28
|
-
|
|
33
|
+
if (!options.quiet) {
|
|
34
|
+
p.intro(pc.cyan(`Removing sandbox for ${branch}`));
|
|
35
|
+
}
|
|
29
36
|
const existing = runSafeEngine(engine, 'docker', ['ps', '-a', '--format', '{{.Names}}']).split('\n').filter(Boolean);
|
|
30
37
|
const matchedContainers = containerNameCandidates(config, branch)
|
|
31
38
|
.filter((name) => existing.includes(name));
|
|
@@ -57,10 +64,12 @@ async function rmOne(config, tools, branch) {
|
|
|
57
64
|
}
|
|
58
65
|
const existingWorktrees = worktreeCandidates.filter((candidate) => fs.existsSync(candidate));
|
|
59
66
|
if (existingWorktrees.length > 0) {
|
|
60
|
-
const shouldRemoveWorktree =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const shouldRemoveWorktree = options.assumeYes
|
|
68
|
+
? true
|
|
69
|
+
: await p.confirm({
|
|
70
|
+
message: `Remove worktree(s): ${existingWorktrees.join(', ')}?`,
|
|
71
|
+
initialValue: true
|
|
72
|
+
});
|
|
64
73
|
if (p.isCancel(shouldRemoveWorktree)) {
|
|
65
74
|
p.outro('Cancelled');
|
|
66
75
|
return;
|
|
@@ -69,10 +78,12 @@ async function rmOne(config, tools, branch) {
|
|
|
69
78
|
for (const worktree of existingWorktrees) {
|
|
70
79
|
removeWorktreeDir(config.repoRoot, config.worktreeBase, worktree);
|
|
71
80
|
}
|
|
72
|
-
const shouldDeleteBranch =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
const shouldDeleteBranch = options.assumeYes
|
|
82
|
+
? true
|
|
83
|
+
: await p.confirm({
|
|
84
|
+
message: `Also delete local branch '${effectiveBranch}'?`,
|
|
85
|
+
initialValue: true
|
|
86
|
+
});
|
|
76
87
|
if (!p.isCancel(shouldDeleteBranch) && shouldDeleteBranch) {
|
|
77
88
|
if (!runOk('git', ['-C', config.repoRoot, 'branch', '-D', effectiveBranch])) {
|
|
78
89
|
p.log.warn(`Local branch '${effectiveBranch}' was not deleted`);
|
|
@@ -92,18 +103,22 @@ async function rmOne(config, tools, branch) {
|
|
|
92
103
|
}
|
|
93
104
|
const shareBranch = shareBranchDir(config, effectiveBranch);
|
|
94
105
|
if (fs.existsSync(shareBranch)) {
|
|
95
|
-
const shouldRemoveShare =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
const shouldRemoveShare = options.assumeYes
|
|
107
|
+
? true
|
|
108
|
+
: await p.confirm({
|
|
109
|
+
message: `Remove share dir for branch '${effectiveBranch}' (${shareBranch})?`,
|
|
110
|
+
initialValue: true
|
|
111
|
+
});
|
|
99
112
|
if (!p.isCancel(shouldRemoveShare) && shouldRemoveShare) {
|
|
100
113
|
removeManagedDir(config.shareBase, shareBranch);
|
|
101
114
|
p.log.success(`Share dir removed: ${shareBranch}`);
|
|
102
115
|
}
|
|
103
116
|
}
|
|
104
|
-
|
|
117
|
+
if (!options.quiet) {
|
|
118
|
+
p.outro(pc.green('Sandbox removed'));
|
|
119
|
+
}
|
|
105
120
|
}
|
|
106
|
-
async function
|
|
121
|
+
async function rmPurge(config, tools) {
|
|
107
122
|
const engine = detectEngine(config);
|
|
108
123
|
p.intro(pc.cyan(`Removing all sandboxes for ${config.project}`));
|
|
109
124
|
const containers = runSafeEngine(engine, 'docker', [
|
|
@@ -193,6 +208,52 @@ async function rmAll(config, tools) {
|
|
|
193
208
|
}
|
|
194
209
|
p.outro(pc.green('All project sandboxes removed'));
|
|
195
210
|
}
|
|
211
|
+
async function rmUnbound(config, tools, options) {
|
|
212
|
+
const engine = detectEngine(config);
|
|
213
|
+
const { running, nonRunning } = fetchSandboxRows(engine, sandboxLabel(config), sandboxBranchLabel(config));
|
|
214
|
+
const removable = [...running, ...nonRunning].filter((row) => row.branch && lookupShortIdByBranch(row.branch, config.repoRoot) === null);
|
|
215
|
+
p.intro(pc.cyan(`Removing sandboxes not bound to an active task for ${config.project}`));
|
|
216
|
+
if (removable.length === 0) {
|
|
217
|
+
p.outro('No removable sandboxes: every container is bound to an active task (or none exist)');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
for (const row of removable) {
|
|
221
|
+
p.log.message(`${row.name} ${row.branch}`);
|
|
222
|
+
}
|
|
223
|
+
if (options.dryRun) {
|
|
224
|
+
p.outro(`Dry run: ${removable.length} sandbox(es) would be removed, nothing deleted`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (!options.assumeYes) {
|
|
228
|
+
if (!process.stdin.isTTY) {
|
|
229
|
+
throw new Error('Refusing to remove sandboxes without confirmation in a non-interactive shell; pass --yes to proceed.');
|
|
230
|
+
}
|
|
231
|
+
const confirmed = await p.confirm({
|
|
232
|
+
message: `Remove these ${removable.length} sandbox(es)?`,
|
|
233
|
+
initialValue: false
|
|
234
|
+
});
|
|
235
|
+
if (p.isCancel(confirmed) || !confirmed) {
|
|
236
|
+
p.outro('Cancelled');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const failures = [];
|
|
241
|
+
for (const row of removable) {
|
|
242
|
+
try {
|
|
243
|
+
await rmOne(config, tools, row.branch, { assumeYes: true, quiet: true });
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
failures.push({ branch: row.branch, message: error instanceof Error ? error.message : String(error) });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (failures.length > 0) {
|
|
250
|
+
for (const failure of failures) {
|
|
251
|
+
p.log.error(`Failed to remove '${failure.branch}': ${failure.message}`);
|
|
252
|
+
}
|
|
253
|
+
throw new Error(`Removed ${removable.length - failures.length}/${removable.length} sandbox(es); ${failures.length} failed`);
|
|
254
|
+
}
|
|
255
|
+
p.outro(pc.green(`Removed ${removable.length} sandbox(es)`));
|
|
256
|
+
}
|
|
196
257
|
export async function rm(args) {
|
|
197
258
|
const { values, positionals } = parseArgs({
|
|
198
259
|
args,
|
|
@@ -200,6 +261,9 @@ export async function rm(args) {
|
|
|
200
261
|
strict: true,
|
|
201
262
|
options: {
|
|
202
263
|
all: { type: 'boolean' },
|
|
264
|
+
purge: { type: 'boolean' },
|
|
265
|
+
'dry-run': { type: 'boolean' },
|
|
266
|
+
yes: { type: 'boolean', short: 'y' },
|
|
203
267
|
help: { type: 'boolean', short: 'h' }
|
|
204
268
|
}
|
|
205
269
|
});
|
|
@@ -207,13 +271,29 @@ export async function rm(args) {
|
|
|
207
271
|
process.stdout.write(`${USAGE}\n`);
|
|
208
272
|
return;
|
|
209
273
|
}
|
|
210
|
-
if (
|
|
274
|
+
if (values.all && values.purge) {
|
|
275
|
+
throw new Error('--all and --purge are mutually exclusive');
|
|
276
|
+
}
|
|
277
|
+
if ((values['dry-run'] || values.yes) && !values.all) {
|
|
278
|
+
throw new Error('--dry-run and --yes only apply to --all');
|
|
279
|
+
}
|
|
280
|
+
if ((values.all || values.purge) && positionals.length > 0) {
|
|
281
|
+
throw new Error(`${values.all ? '--all' : '--purge'} does not take a branch argument`);
|
|
282
|
+
}
|
|
283
|
+
if (!values.all && !values.purge && positionals.length !== 1) {
|
|
211
284
|
throw new Error(USAGE);
|
|
212
285
|
}
|
|
213
286
|
const config = loadConfig();
|
|
214
287
|
const tools = resolveTools(config);
|
|
288
|
+
if (values.purge) {
|
|
289
|
+
await rmPurge(config, tools);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
215
292
|
if (values.all) {
|
|
216
|
-
await
|
|
293
|
+
await rmUnbound(config, tools, {
|
|
294
|
+
dryRun: Boolean(values['dry-run']),
|
|
295
|
+
assumeYes: Boolean(values.yes)
|
|
296
|
+
});
|
|
217
297
|
return;
|
|
218
298
|
}
|
|
219
299
|
const branch = resolveTaskBranch(positionals[0] ?? '', config.repoRoot);
|
|
@@ -16,7 +16,9 @@ Commands:
|
|
|
16
16
|
rebuild [--quiet] [--refresh]
|
|
17
17
|
Rebuild the sandbox image (--refresh pulls base + tools)
|
|
18
18
|
refresh Sync host Claude Code credentials to all sandbox copies
|
|
19
|
-
rm <branch>
|
|
19
|
+
rm <branch> | --all | --purge
|
|
20
|
+
Remove one sandbox, all sandboxes not bound to an
|
|
21
|
+
active task (--all), or tear down everything (--purge)
|
|
20
22
|
vm status|start|stop Manage the sandbox VM (macOS) or check the backend (Windows)
|
|
21
23
|
|
|
22
24
|
Run 'ai sandbox <command> --help' for details.`;
|
|
@@ -9,7 +9,7 @@ symlink under \`$HOME\` (e.g. \`.tmux.conf\` -> \`/home/devuser/.tmux.conf\`),
|
|
|
9
9
|
overriding image defaults so your editor, shell, and tool preferences follow
|
|
10
10
|
you across \`ai sandbox destroy + create\`.
|
|
11
11
|
|
|
12
|
-
See: https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
12
|
+
See: https://github.com/fitlab-ai/agent-infra/blob/main/docs/en/sandbox.md#user-level-dotfiles-channel
|
|
13
13
|
|
|
14
14
|
Common usage - drop files or symlinks here:
|
|
15
15
|
|
|
@@ -37,7 +37,7 @@ only writes \`README.md\` when it is missing, never when it already exists.
|
|
|
37
37
|
(例如 \`.tmux.conf -> /home/devuser/.tmux.conf\`),覆盖镜像默认值,让你的编辑器、
|
|
38
38
|
shell、工具偏好跨 \`ai sandbox destroy + create\` 持久存在。
|
|
39
39
|
|
|
40
|
-
参考:https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
40
|
+
参考:https://github.com/fitlab-ai/agent-infra/blob/main/docs/zh-CN/sandbox.md#用户级-dotfiles-通道
|
|
41
41
|
|
|
42
42
|
常见用法:把文件或符号链接放进来:
|
|
43
43
|
|
|
@@ -62,7 +62,7 @@ This directory is mounted **read-write** into every sandbox container of this
|
|
|
62
62
|
project at \`/share/common\`, regardless of branch. Drop files here to share
|
|
63
63
|
between host and any sandbox without polluting the git worktree.
|
|
64
64
|
|
|
65
|
-
See: https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
65
|
+
See: https://github.com/fitlab-ai/agent-infra/blob/main/docs/en/sandbox.md#host-sandbox-file-exchange
|
|
66
66
|
|
|
67
67
|
This file is safe to delete; the next \`ai sandbox create\` will re-create it.
|
|
68
68
|
|
|
@@ -73,7 +73,7 @@ This file is safe to delete; the next \`ai sandbox create\` will re-create it.
|
|
|
73
73
|
该目录被以**读写**方式挂载到本项目所有 sandbox 容器的 \`/share/common\`,
|
|
74
74
|
跨分支可见。可用来在宿主和任意 sandbox 之间传文件,无需弄脏 git worktree。
|
|
75
75
|
|
|
76
|
-
参考:https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
76
|
+
参考:https://github.com/fitlab-ai/agent-infra/blob/main/docs/zh-CN/sandbox.md#宿主-沙箱文件交换
|
|
77
77
|
|
|
78
78
|
该文件可以安全删除;下一次 \`ai sandbox create\` 会重新生成。
|
|
79
79
|
`;
|
|
@@ -83,7 +83,7 @@ This directory is mounted **read-write** into the sandbox container of this
|
|
|
83
83
|
project's current branch at \`/share/branch\`. Files here are exclusive to this
|
|
84
84
|
branch's sandbox and do not leak across branches.
|
|
85
85
|
|
|
86
|
-
See: https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
86
|
+
See: https://github.com/fitlab-ai/agent-infra/blob/main/docs/en/sandbox.md#host-sandbox-file-exchange
|
|
87
87
|
|
|
88
88
|
This file is safe to delete; the next \`ai sandbox create\` will re-create it.
|
|
89
89
|
|
|
@@ -94,7 +94,7 @@ This file is safe to delete; the next \`ai sandbox create\` will re-create it.
|
|
|
94
94
|
该目录被以**读写**方式挂载到本项目当前分支 sandbox 容器的 \`/share/branch\`,
|
|
95
95
|
仅当前分支可见,不会跨分支泄漏。
|
|
96
96
|
|
|
97
|
-
参考:https://github.com/fitlab-ai/agent-infra/blob/main/
|
|
97
|
+
参考:https://github.com/fitlab-ai/agent-infra/blob/main/docs/zh-CN/sandbox.md#宿主-沙箱文件交换
|
|
98
98
|
|
|
99
99
|
该文件可以安全删除;下一次 \`ai sandbox create\` 会重新生成。
|
|
100
100
|
`;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Enumerate a task directory's artifacts ordered by modification time, oldest
|
|
5
|
+
* first, so the listing reads like the task's timeline. Filename ascending is a
|
|
6
|
+
* deterministic tiebreak when two files share the same mtime (e.g. written in
|
|
7
|
+
* the same millisecond).
|
|
8
|
+
*
|
|
9
|
+
* Only top-level regular files are included; subdirectories and dotfiles are
|
|
10
|
+
* skipped so every entry is something `cat` can print. The returned 1-based
|
|
11
|
+
* `index` is the source of truth shared by `files` and `cat`.
|
|
12
|
+
*/
|
|
13
|
+
function enumerateArtifacts(taskDir) {
|
|
14
|
+
const entries = fs
|
|
15
|
+
.readdirSync(taskDir, { withFileTypes: true })
|
|
16
|
+
.filter((dirent) => dirent.isFile() && !dirent.name.startsWith('.'))
|
|
17
|
+
.map((dirent) => {
|
|
18
|
+
const abs = path.join(taskDir, dirent.name);
|
|
19
|
+
const stat = fs.statSync(abs);
|
|
20
|
+
return { name: dirent.name, path: abs, size: stat.size, mtimeMs: stat.mtimeMs };
|
|
21
|
+
});
|
|
22
|
+
entries.sort((a, b) => {
|
|
23
|
+
if (a.mtimeMs !== b.mtimeMs)
|
|
24
|
+
return a.mtimeMs - b.mtimeMs;
|
|
25
|
+
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
26
|
+
});
|
|
27
|
+
return entries.map((entry, i) => ({ index: i + 1, ...entry }));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolve an artifact selector to an absolute path within `taskDir`. The
|
|
31
|
+
* selector is either a 1-based index `N` (as listed by `files`) or a filename
|
|
32
|
+
* (with or without the `.md` suffix). Throws with a clear message on failure.
|
|
33
|
+
*/
|
|
34
|
+
function resolveArtifact(taskDir, artifactOrN) {
|
|
35
|
+
if (path.basename(artifactOrN) !== artifactOrN) {
|
|
36
|
+
throw new Error('artifact name must not contain path separators');
|
|
37
|
+
}
|
|
38
|
+
if (/^\d+$/.test(artifactOrN)) {
|
|
39
|
+
const n = Number(artifactOrN);
|
|
40
|
+
const match = enumerateArtifacts(taskDir).find((a) => a.index === n);
|
|
41
|
+
if (!match) {
|
|
42
|
+
throw new Error(`invalid artifact index ${n} (run 'ai task files <ref>' to list)`);
|
|
43
|
+
}
|
|
44
|
+
return match.path;
|
|
45
|
+
}
|
|
46
|
+
const candidates = artifactOrN.endsWith('.md')
|
|
47
|
+
? [artifactOrN]
|
|
48
|
+
: [artifactOrN, `${artifactOrN}.md`];
|
|
49
|
+
for (const candidate of candidates) {
|
|
50
|
+
const abs = path.join(taskDir, candidate);
|
|
51
|
+
if (fs.existsSync(abs) && fs.statSync(abs).isFile()) {
|
|
52
|
+
return abs;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`artifact '${artifactOrN}' not found in task directory`);
|
|
56
|
+
}
|
|
57
|
+
export { enumerateArtifacts, resolveArtifact };
|
|
58
|
+
//# sourceMappingURL=artifacts.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { resolveTaskRef } from "../resolve-ref.js";
|
|
3
|
+
import { resolveArtifact } from "../artifacts.js";
|
|
4
|
+
const USAGE = `Usage: ai task cat <N | #N | TASK-id> <artifact | N>
|
|
5
|
+
|
|
6
|
+
Prints a task artifact's raw content to stdout.
|
|
7
|
+
<ref> Bare numeric / '#N' short id, or a full TASK-YYYYMMDD-HHMMSS id.
|
|
8
|
+
<artifact | N> Artifact filename (with or without '.md'), or the number from 'ai task files'.
|
|
9
|
+
`;
|
|
10
|
+
function cat(args = []) {
|
|
11
|
+
if (args[0] === '--help' || args[0] === '-h') {
|
|
12
|
+
process.stdout.write(USAGE);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (args.length < 2) {
|
|
16
|
+
process.stdout.write(USAGE);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const resolved = resolveTaskRef(args[0]);
|
|
21
|
+
if (!resolved.ok) {
|
|
22
|
+
process.stderr.write(`ai task cat: ${resolved.message}\n`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let artifactPath;
|
|
27
|
+
try {
|
|
28
|
+
artifactPath = resolveArtifact(resolved.taskDir, args[1]);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
process.stderr.write(`ai task cat: ${e.message}\n`);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
process.stdout.write(fs.readFileSync(artifactPath, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
export { cat };
|
|
38
|
+
//# sourceMappingURL=cat.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { formatTable } from "../../table.js";
|
|
2
|
+
import { resolveTaskRef } from "../resolve-ref.js";
|
|
3
|
+
import { enumerateArtifacts } from "../artifacts.js";
|
|
4
|
+
const USAGE = `Usage: ai task files <N | #N | TASK-id>
|
|
5
|
+
|
|
6
|
+
Lists the artifacts in a task directory with stable numbers.
|
|
7
|
+
<ref> Bare numeric / '#N' short id, or a full TASK-YYYYMMDD-HHMMSS id.
|
|
8
|
+
|
|
9
|
+
Columns: # (artifact number, usable with 'ai task cat') / NAME / SIZE (bytes) / MTIME
|
|
10
|
+
`;
|
|
11
|
+
const TABLE_HEADERS = ['#', 'NAME', 'SIZE', 'MTIME'];
|
|
12
|
+
function pad2(n) {
|
|
13
|
+
return String(n).padStart(2, '0');
|
|
14
|
+
}
|
|
15
|
+
function formatMtime(mtimeMs) {
|
|
16
|
+
const d = new Date(mtimeMs);
|
|
17
|
+
return (`${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ` +
|
|
18
|
+
`${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`);
|
|
19
|
+
}
|
|
20
|
+
function files(args = []) {
|
|
21
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
22
|
+
process.stdout.write(USAGE);
|
|
23
|
+
if (args.length === 0)
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const resolved = resolveTaskRef(args[0]);
|
|
28
|
+
if (!resolved.ok) {
|
|
29
|
+
process.stderr.write(`ai task files: ${resolved.message}\n`);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const artifacts = enumerateArtifacts(resolved.taskDir);
|
|
34
|
+
// Show the name without the `.md` suffix so the NAME column is exactly what
|
|
35
|
+
// `ai task cat <ref> <name>` accepts (the resolver re-adds `.md`).
|
|
36
|
+
const rows = artifacts.map((a) => [
|
|
37
|
+
String(a.index),
|
|
38
|
+
a.name.replace(/\.md$/, ''),
|
|
39
|
+
String(a.size),
|
|
40
|
+
formatMtime(a.mtimeMs)
|
|
41
|
+
]);
|
|
42
|
+
for (const line of formatTable(TABLE_HEADERS, rows, { zebra: Boolean(process.stdout.isTTY) })) {
|
|
43
|
+
process.stdout.write(`${line}\n`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export { files };
|
|
47
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolveTaskRef, detectRepoRoot, enumerateTaskDirs } from "../resolve-ref.js";
|
|
4
|
+
import { enumerateArtifacts, resolveArtifact } from "../artifacts.js";
|
|
5
|
+
import { loadShortIdByTaskId } from "../short-id.js";
|
|
6
|
+
const USAGE = `Usage: ai task grep <pattern> [ref] [artifact | N]
|
|
7
|
+
|
|
8
|
+
Literal (non-regex) line search across task artifacts.
|
|
9
|
+
<pattern> Literal substring to match (NOT a regex). Case-sensitive by default.
|
|
10
|
+
[ref] Bare numeric / '#N' short id, or a full TASK-YYYYMMDD-HHMMSS id.
|
|
11
|
+
Omit to scan every task under active / blocked / completed
|
|
12
|
+
(archive is skipped). With a ref, narrows to that single task
|
|
13
|
+
(a TASK-id ref can also resolve an archived task).
|
|
14
|
+
[artifact | N] Only valid with <ref>. Artifact filename (with or without '.md')
|
|
15
|
+
or the number from 'ai task files'. Narrows to a single artifact.
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
-i, --ignore-case Case-insensitive matching.
|
|
19
|
+
-- Treat the rest as positional (use for patterns starting with '-').
|
|
20
|
+
|
|
21
|
+
Output: '{taskId} [#short] {fileStem}:{line}: {matched-line}' (short id only for active tasks).
|
|
22
|
+
Exits 1 with no output when nothing matches.
|
|
23
|
+
`;
|
|
24
|
+
function makeMatcher(pattern, ignoreCase) {
|
|
25
|
+
if (ignoreCase) {
|
|
26
|
+
const needle = pattern.toLowerCase();
|
|
27
|
+
return (line) => line.toLowerCase().includes(needle);
|
|
28
|
+
}
|
|
29
|
+
return (line) => line.includes(pattern);
|
|
30
|
+
}
|
|
31
|
+
// Split content into lines with grep-like semantics: a trailing newline does
|
|
32
|
+
// not yield a phantom final empty line, but genuine interior blank lines stay.
|
|
33
|
+
function splitLines(content) {
|
|
34
|
+
const lines = content.split(/\r?\n/);
|
|
35
|
+
if (lines.length > 0 && lines[lines.length - 1] === '')
|
|
36
|
+
lines.pop();
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
39
|
+
function scanArtifact(taskId, shortToken, artifactPath, matcher, emit) {
|
|
40
|
+
const content = fs.readFileSync(artifactPath, 'utf8');
|
|
41
|
+
const stem = path.basename(artifactPath).replace(/\.md$/, '');
|
|
42
|
+
const prefix = shortToken ? `${taskId} ${shortToken}` : taskId;
|
|
43
|
+
let count = 0;
|
|
44
|
+
splitLines(content).forEach((line, i) => {
|
|
45
|
+
if (matcher(line)) {
|
|
46
|
+
emit(`${prefix} ${stem}:${i + 1}: ${line}\n`);
|
|
47
|
+
count++;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return count;
|
|
51
|
+
}
|
|
52
|
+
function grep(args = []) {
|
|
53
|
+
const positional = [];
|
|
54
|
+
let ignoreCase = false;
|
|
55
|
+
let optsEnded = false;
|
|
56
|
+
for (const a of args) {
|
|
57
|
+
if (!optsEnded && a === '--') {
|
|
58
|
+
optsEnded = true;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!optsEnded && (a === '-h' || a === '--help')) {
|
|
62
|
+
process.stdout.write(USAGE);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!optsEnded && (a === '-i' || a === '--ignore-case')) {
|
|
66
|
+
ignoreCase = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!optsEnded && a.startsWith('-') && a !== '-') {
|
|
70
|
+
process.stderr.write(`ai task grep: unknown flag: ${a}\n`);
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
positional.push(a);
|
|
75
|
+
}
|
|
76
|
+
if (positional.length === 0) {
|
|
77
|
+
process.stdout.write(USAGE);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (positional.length > 3) {
|
|
82
|
+
process.stderr.write('ai task grep: too many arguments\n');
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const [pattern, ref, artifactOrN] = positional;
|
|
87
|
+
const matcher = makeMatcher(pattern, ignoreCase);
|
|
88
|
+
const chunks = [];
|
|
89
|
+
const emit = (line) => chunks.push(line);
|
|
90
|
+
let total = 0;
|
|
91
|
+
if (ref === undefined) {
|
|
92
|
+
// No ref: full scan across active / blocked / completed (no archive).
|
|
93
|
+
let repoRoot;
|
|
94
|
+
try {
|
|
95
|
+
repoRoot = detectRepoRoot();
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
process.stderr.write(`ai task grep: ${e.message}\n`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const shortMap = loadShortIdByTaskId(repoRoot);
|
|
103
|
+
for (const { taskId, taskDir } of enumerateTaskDirs(repoRoot)) {
|
|
104
|
+
const shortToken = shortMap.get(taskId);
|
|
105
|
+
for (const a of enumerateArtifacts(taskDir)) {
|
|
106
|
+
total += scanArtifact(taskId, shortToken, a.path, matcher, emit);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const resolved = resolveTaskRef(ref);
|
|
112
|
+
if (!resolved.ok) {
|
|
113
|
+
process.stderr.write(`ai task grep: ${resolved.message}\n`);
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const shortToken = loadShortIdByTaskId(resolved.repoRoot).get(resolved.taskId);
|
|
118
|
+
if (artifactOrN !== undefined) {
|
|
119
|
+
let artifactPath;
|
|
120
|
+
try {
|
|
121
|
+
artifactPath = resolveArtifact(resolved.taskDir, artifactOrN);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
process.stderr.write(`ai task grep: ${e.message}\n`);
|
|
125
|
+
process.exitCode = 1;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
total += scanArtifact(resolved.taskId, shortToken, artifactPath, matcher, emit);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
for (const a of enumerateArtifacts(resolved.taskDir)) {
|
|
132
|
+
total += scanArtifact(resolved.taskId, shortToken, a.path, matcher, emit);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (total === 0) {
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
process.stdout.write(chunks.join(''));
|
|
141
|
+
}
|
|
142
|
+
export { grep };
|
|
143
|
+
//# sourceMappingURL=grep.js.map
|