@fitlab-ai/agent-infra 0.7.3 → 0.7.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.
Files changed (107) hide show
  1. package/README.md +32 -790
  2. package/README.zh-CN.md +32 -763
  3. package/bin/cli.ts +13 -11
  4. package/dist/bin/cli.js +13 -11
  5. package/dist/lib/init.js +1 -1
  6. package/dist/lib/merge.js +1 -1
  7. package/dist/lib/sandbox/commands/create.js +44 -3
  8. package/dist/lib/sandbox/commands/rm.js +99 -19
  9. package/dist/lib/sandbox/index.js +24 -22
  10. package/dist/lib/sandbox/readme-scaffold.js +6 -6
  11. package/dist/lib/task/artifacts.js +58 -0
  12. package/dist/lib/task/commands/cat.js +38 -0
  13. package/dist/lib/task/commands/files.js +47 -0
  14. package/dist/lib/task/commands/grep.js +143 -0
  15. package/dist/lib/task/commands/log.js +75 -0
  16. package/dist/lib/task/commands/show.js +5 -114
  17. package/dist/lib/task/commands/status.js +239 -0
  18. package/dist/lib/task/index.js +37 -0
  19. package/dist/lib/task/resolve-ref.js +150 -0
  20. package/dist/lib/update.js +1 -1
  21. package/lib/init.ts +1 -1
  22. package/lib/merge.ts +1 -1
  23. package/lib/sandbox/commands/create.ts +47 -4
  24. package/lib/sandbox/commands/rm.ts +128 -19
  25. package/lib/sandbox/index.ts +24 -22
  26. package/lib/sandbox/readme-scaffold.ts +6 -6
  27. package/lib/task/artifacts.ts +72 -0
  28. package/lib/task/commands/cat.ts +39 -0
  29. package/lib/task/commands/files.ts +53 -0
  30. package/lib/task/commands/grep.ts +147 -0
  31. package/lib/task/commands/log.ts +80 -0
  32. package/lib/task/commands/show.ts +5 -117
  33. package/lib/task/commands/status.ts +302 -0
  34. package/lib/task/index.ts +37 -0
  35. package/lib/task/resolve-ref.ts +160 -0
  36. package/lib/update.ts +1 -1
  37. package/package.json +1 -1
  38. package/templates/.agents/README.en.md +1 -0
  39. package/templates/.agents/README.zh-CN.md +1 -0
  40. package/templates/.agents/rules/README.en.md +45 -0
  41. package/templates/.agents/rules/README.zh-CN.md +44 -0
  42. package/templates/.agents/rules/cli-help-format.en.md +49 -0
  43. package/templates/.agents/rules/cli-help-format.zh-CN.md +49 -0
  44. package/templates/.agents/rules/debugging-guide.en.md +25 -0
  45. package/templates/.agents/rules/debugging-guide.zh-CN.md +25 -0
  46. package/templates/.agents/rules/no-mid-flow-questions.en.md +14 -2
  47. package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +14 -2
  48. package/templates/.agents/rules/pr-sync.github.en.md +8 -6
  49. package/templates/.agents/rules/pr-sync.github.zh-CN.md +8 -6
  50. package/templates/.agents/rules/review-handshake.en.md +83 -0
  51. package/templates/.agents/rules/review-handshake.zh-CN.md +83 -0
  52. package/templates/.agents/scripts/lib/post-review-commit.js +56 -0
  53. package/templates/.agents/scripts/lib/review-artifacts.js +117 -0
  54. package/templates/.agents/scripts/review-diff-fingerprint.js +99 -0
  55. package/templates/.agents/scripts/validate-artifact.js +240 -0
  56. package/templates/.agents/skills/analyze-task/SKILL.en.md +52 -6
  57. package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +52 -6
  58. package/templates/.agents/skills/code-task/SKILL.en.md +2 -0
  59. package/templates/.agents/skills/code-task/SKILL.zh-CN.md +2 -0
  60. package/templates/.agents/skills/code-task/config/verify.en.json +3 -0
  61. package/templates/.agents/skills/code-task/config/verify.zh-CN.json +3 -0
  62. package/templates/.agents/skills/code-task/reference/fix-mode.en.md +5 -3
  63. package/templates/.agents/skills/code-task/reference/fix-mode.zh-CN.md +5 -3
  64. package/templates/.agents/skills/code-task/reference/report-template.en.md +4 -4
  65. package/templates/.agents/skills/code-task/reference/report-template.zh-CN.md +4 -4
  66. package/templates/.agents/skills/code-task/scripts/detect-mode.js +2 -107
  67. package/templates/.agents/skills/commit/SKILL.en.md +6 -0
  68. package/templates/.agents/skills/commit/SKILL.zh-CN.md +6 -0
  69. package/templates/.agents/skills/commit/reference/task-status-update.en.md +8 -0
  70. package/templates/.agents/skills/commit/reference/task-status-update.zh-CN.md +8 -0
  71. package/templates/.agents/skills/complete-task/SKILL.en.md +10 -0
  72. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +10 -0
  73. package/templates/.agents/skills/complete-task/config/verify.en.json +2 -0
  74. package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +2 -0
  75. package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +1 -1
  76. package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +1 -1
  77. package/templates/.agents/skills/plan-task/SKILL.en.md +1 -1
  78. package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +1 -1
  79. package/templates/.agents/skills/plan-task/config/verify.en.json +3 -0
  80. package/templates/.agents/skills/plan-task/config/verify.zh-CN.json +3 -0
  81. package/templates/.agents/skills/review-analysis/config/verify.en.json +2 -1
  82. package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +2 -1
  83. package/templates/.agents/skills/review-analysis/reference/output-templates.en.md +5 -4
  84. package/templates/.agents/skills/review-analysis/reference/output-templates.zh-CN.md +5 -4
  85. package/templates/.agents/skills/review-analysis/reference/report-template.en.md +4 -0
  86. package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +4 -0
  87. package/templates/.agents/skills/review-code/SKILL.en.md +4 -1
  88. package/templates/.agents/skills/review-code/SKILL.zh-CN.md +4 -1
  89. package/templates/.agents/skills/review-code/config/verify.en.json +5 -2
  90. package/templates/.agents/skills/review-code/config/verify.zh-CN.json +5 -2
  91. package/templates/.agents/skills/review-code/reference/output-templates.en.md +5 -4
  92. package/templates/.agents/skills/review-code/reference/output-templates.zh-CN.md +5 -4
  93. package/templates/.agents/skills/review-code/reference/report-template.en.md +6 -0
  94. package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +6 -0
  95. package/templates/.agents/skills/review-plan/config/verify.en.json +2 -1
  96. package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +2 -1
  97. package/templates/.agents/skills/review-plan/reference/output-templates.en.md +5 -4
  98. package/templates/.agents/skills/review-plan/reference/output-templates.zh-CN.md +5 -4
  99. package/templates/.agents/skills/review-plan/reference/report-template.en.md +4 -0
  100. package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +4 -0
  101. package/templates/.agents/skills/watch-pr/SKILL.en.md +1 -1
  102. package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +1 -1
  103. package/templates/.agents/templates/task.en.md +7 -0
  104. package/templates/.agents/templates/task.zh-CN.md +7 -0
  105. package/templates/.github/workflows/metadata-sync.yml +1 -1
  106. package/templates/.github/workflows/pr-label.yml +1 -1
  107. package/templates/.github/workflows/status-label.yml +1 -1
@@ -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
@@ -0,0 +1,75 @@
1
+ import fs from 'node:fs';
2
+ import { formatTable } from "../../table.js";
3
+ import { resolveTaskRef } from "../resolve-ref.js";
4
+ const USAGE = `Usage: ai task log <N | #N | TASK-id>
5
+
6
+ Renders a task's activity log as a chronological timeline table.
7
+ <ref> Bare numeric / '#N' short id, or a full TASK-YYYYMMDD-HHMMSS id.
8
+
9
+ Columns: # (timeline position) / TIME / STEP / AGENT / NOTE
10
+ `;
11
+ const TABLE_HEADERS = ['#', 'TIME', 'STEP', 'AGENT', 'NOTE'];
12
+ // The activity-log H2 heading is language-dependent (zh template / en template).
13
+ const HEADING_RE = /^##\s+(活动日志|Activity Log)\s*$/;
14
+ const NEXT_H2_RE = /^##\s/;
15
+ // `- {time} — **{step}** by {agent} — {note}` ; the separator is an em-dash
16
+ // (U+2014). STEP/AGENT are non-greedy so a note that itself contains ' — ' or
17
+ // '→' is not mis-split; NOTE greedily takes the rest of the line.
18
+ const ENTRY_RE = /^- (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}) — \*\*(.+?)\*\* by (.+?) — (.*)$/;
19
+ function parseActivityLog(content) {
20
+ const lines = content.split('\n');
21
+ let i = 0;
22
+ while (i < lines.length && !HEADING_RE.test(lines[i]))
23
+ i += 1;
24
+ if (i >= lines.length)
25
+ return { sectionFound: false, entries: [] };
26
+ const parsed = [];
27
+ for (let j = i + 1; j < lines.length; j += 1) {
28
+ if (NEXT_H2_RE.test(lines[j]))
29
+ break;
30
+ const m = ENTRY_RE.exec(lines[j]);
31
+ if (!m)
32
+ continue; // skip blank / non-entry / malformed lines
33
+ parsed.push({
34
+ entry: { time: m[1], step: m[2], agent: m[3], note: m[4] },
35
+ epoch: Date.parse(m[1].replace(' ', 'T')),
36
+ order: parsed.length
37
+ });
38
+ }
39
+ // Ascending by time; stable tie-break on original order for equal timestamps.
40
+ parsed.sort((a, b) => a.epoch - b.epoch || a.order - b.order);
41
+ return { sectionFound: true, entries: parsed.map((p) => p.entry) };
42
+ }
43
+ function log(args = []) {
44
+ if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
45
+ process.stdout.write(USAGE);
46
+ if (args.length === 0)
47
+ process.exitCode = 1;
48
+ return;
49
+ }
50
+ const resolved = resolveTaskRef(args[0]);
51
+ if (!resolved.ok) {
52
+ process.stderr.write(`ai task log: ${resolved.message}\n`);
53
+ process.exitCode = 1;
54
+ return;
55
+ }
56
+ const content = fs.readFileSync(resolved.taskMdPath, 'utf8');
57
+ const { sectionFound, entries } = parseActivityLog(content);
58
+ if (!sectionFound) {
59
+ process.stderr.write(`ai task log: no activity log section ('## 活动日志' or '## Activity Log') found in task ${resolved.taskId}\n`);
60
+ process.exitCode = 1;
61
+ return;
62
+ }
63
+ if (entries.length === 0) {
64
+ process.stderr.write(`ai task log: no activity log entries found in task ${resolved.taskId}\n`);
65
+ process.exitCode = 1;
66
+ return;
67
+ }
68
+ const rows = entries.map((e, idx) => [String(idx + 1), e.time, e.step, e.agent, e.note]);
69
+ for (const line of formatTable(TABLE_HEADERS, rows, { zebra: Boolean(process.stdout.isTTY) })) {
70
+ process.stdout.write(`${line}\n`);
71
+ }
72
+ process.stdout.write(`Total: ${entries.length} entries\n`);
73
+ }
74
+ export { log, parseActivityLog };
75
+ //# sourceMappingURL=log.js.map
@@ -1,7 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { execFileSync, spawnSync } from 'node:child_process';
4
- import { normalizeShortIdInput } from "../short-id.js";
2
+ import { resolveTaskRef } from "../resolve-ref.js";
5
3
  const USAGE = `Usage: ai task show <N | #N | TASK-id>
6
4
 
7
5
  Prints the task.md content for the matching task.
@@ -9,84 +7,6 @@ Prints the task.md content for the matching task.
9
7
  '#N' Compatibility form for old commands.
10
8
  TASK-YYYYMMDD-HHMMSS Locates a task in active / blocked / completed / archive.
11
9
  `;
12
- const TASK_ID_RE = /^TASK-\d{8}-\d{6}$/;
13
- // Flat-structured workspace dirs that hold tasks under `{dir}/{taskId}/task.md`.
14
- // Note: `archive` uses a three-level YYYY/MM/DD layout and is handled separately.
15
- const FLAT_WORKSPACE_DIRS = ['active', 'blocked', 'completed'];
16
- function detectRepoRoot() {
17
- try {
18
- return execFileSync('git', ['rev-parse', '--show-toplevel'], {
19
- encoding: 'utf8',
20
- stdio: ['pipe', 'pipe', 'pipe']
21
- }).trim();
22
- }
23
- catch {
24
- throw new Error('ai task: current directory is not inside a git repository');
25
- }
26
- }
27
- function readShortIdLength(repoRoot) {
28
- try {
29
- const cfg = JSON.parse(fs.readFileSync(path.join(repoRoot, '.agents', '.airc.json'), 'utf8'));
30
- const v = cfg?.task?.shortIdLength;
31
- if (typeof v === 'number' && Number.isFinite(v) && v >= 1)
32
- return v;
33
- }
34
- catch {
35
- // fall through to default
36
- }
37
- return 2;
38
- }
39
- function resolveShortIdToTaskId(arg, repoRoot) {
40
- const scriptPath = path.join(repoRoot, '.agents', 'scripts', 'task-short-id.js');
41
- if (!fs.existsSync(scriptPath)) {
42
- throw new Error(`task-short-id.js not found at ${scriptPath}`);
43
- }
44
- const result = spawnSync('node', [scriptPath, 'resolve', arg], {
45
- encoding: 'utf8',
46
- cwd: repoRoot
47
- });
48
- if (result.status !== 0) {
49
- throw new Error((result.stderr || '').trim() || `failed to resolve '${arg}'`);
50
- }
51
- return result.stdout.trim();
52
- }
53
- function listSortedNumeric(dir, width) {
54
- if (!fs.existsSync(dir))
55
- return [];
56
- const pattern = new RegExp(`^\\d{${width}}$`);
57
- return fs
58
- .readdirSync(dir)
59
- .filter((entry) => pattern.test(entry))
60
- .sort()
61
- .reverse();
62
- }
63
- function findInArchive(repoRoot, taskId) {
64
- // archive-tasks SKILL writes to .agents/workspace/archive/YYYY/MM/DD/{taskId}/task.md
65
- // where YYYY/MM/DD comes from completed_at (or updated_at fallback) — NOT from
66
- // the task id's creation date. So we cannot derive the path from taskId alone;
67
- // walk the bounded YYYY/MM/DD tree instead. Newest-first to favor recent archives.
68
- const archiveDir = path.join(repoRoot, '.agents', 'workspace', 'archive');
69
- for (const year of listSortedNumeric(archiveDir, 4)) {
70
- const yearDir = path.join(archiveDir, year);
71
- for (const month of listSortedNumeric(yearDir, 2)) {
72
- const monthDir = path.join(yearDir, month);
73
- for (const day of listSortedNumeric(monthDir, 2)) {
74
- const candidate = path.join(monthDir, day, taskId, 'task.md');
75
- if (fs.existsSync(candidate))
76
- return candidate;
77
- }
78
- }
79
- }
80
- return null;
81
- }
82
- function findTaskMd(repoRoot, taskId) {
83
- for (const sub of FLAT_WORKSPACE_DIRS) {
84
- const candidate = path.join(repoRoot, '.agents', 'workspace', sub, taskId, 'task.md');
85
- if (fs.existsSync(candidate))
86
- return candidate;
87
- }
88
- return findInArchive(repoRoot, taskId);
89
- }
90
10
  function show(args = []) {
91
11
  if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
92
12
  process.stdout.write(USAGE);
@@ -94,42 +14,13 @@ function show(args = []) {
94
14
  process.exitCode = 1;
95
15
  return;
96
16
  }
97
- const repoRoot = detectRepoRoot();
98
- const arg = args[0];
99
- let taskId;
100
- if (TASK_ID_RE.test(arg)) {
101
- taskId = arg;
102
- }
103
- else {
104
- const shortIdLength = readShortIdLength(repoRoot);
105
- const normalized = normalizeShortIdInput(arg, { shortIdLength });
106
- if (normalized.kind === 'error') {
107
- process.stderr.write(`ai task show: ${normalized.message}\n`);
108
- process.exitCode = 1;
109
- return;
110
- }
111
- if (normalized.kind === 'pass') {
112
- process.stderr.write(`ai task show: '${arg}' is not a valid short id or TASK-id; ` +
113
- `expected bare digits, '#N', or 'TASK-YYYYMMDD-HHMMSS'\n`);
114
- process.exitCode = 1;
115
- return;
116
- }
117
- try {
118
- taskId = resolveShortIdToTaskId(normalized.value, repoRoot);
119
- }
120
- catch (e) {
121
- process.stderr.write(`ai task show: ${e.message}\n`);
122
- process.exitCode = 1;
123
- return;
124
- }
125
- }
126
- const taskMdPath = findTaskMd(repoRoot, taskId);
127
- if (!taskMdPath) {
128
- process.stderr.write(`ai task show: task ${taskId} not found in active / blocked / completed / archive\n`);
17
+ const resolved = resolveTaskRef(args[0]);
18
+ if (!resolved.ok) {
19
+ process.stderr.write(`ai task show: ${resolved.message}\n`);
129
20
  process.exitCode = 1;
130
21
  return;
131
22
  }
132
- process.stdout.write(fs.readFileSync(taskMdPath, 'utf8'));
23
+ process.stdout.write(fs.readFileSync(resolved.taskMdPath, 'utf8'));
133
24
  }
134
25
  export { show };
135
26
  //# sourceMappingURL=show.js.map
@@ -0,0 +1,239 @@
1
+ import fs from 'node:fs';
2
+ import { execFileSync } from 'node:child_process';
3
+ import { resolveTaskRef } from "../resolve-ref.js";
4
+ import { enumerateArtifacts } from "../artifacts.js";
5
+ import { parseTaskFrontmatter, extractTitle } from "../frontmatter.js";
6
+ import { loadShortIdByTaskId } from "../short-id.js";
7
+ const USAGE = `Usage: ai task status <N | #N | TASK-id>
8
+
9
+ Prints an aggregated "health check" view for a task: header, metadata, an
10
+ artifacts summary, git branch state, and best-effort GitHub issue/PR status.
11
+ <ref> Bare numeric / '#N' short id, or a full TASK-YYYYMMDD-HHMMSS id.
12
+
13
+ Git and Platform rows are best-effort: a failed git/gh call degrades that row to
14
+ '-' without failing the command.
15
+ `;
16
+ const DASH = '-';
17
+ function makeRunner(cwd) {
18
+ return (file, args) => execFileSync(file, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
19
+ }
20
+ // Run `run` and swallow any failure into null, so a single failing git/gh call
21
+ // degrades only its own field instead of aborting the whole view.
22
+ function tryRun(run, file, args) {
23
+ try {
24
+ return run(file, args);
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ // Frontmatter keys shown in the Metadata section, in a fixed display order.
31
+ const METADATA_KEYS = [
32
+ 'type',
33
+ 'status',
34
+ 'current_step',
35
+ 'priority',
36
+ 'effort',
37
+ 'branch',
38
+ 'assigned_to',
39
+ 'created_at',
40
+ 'updated_at',
41
+ 'issue_number',
42
+ 'pr_status'
43
+ ];
44
+ function collectMetadata(fm) {
45
+ return METADATA_KEYS.map((key) => [key, fm[key] ? fm[key] : DASH]);
46
+ }
47
+ // Workflow stages in timeline order; artifacts are bucketed by filename prefix.
48
+ // `review-*` prefixes are matched before their bare counterparts so that, e.g.,
49
+ // `review-analysis.md` is never swallowed by the `analysis` bucket.
50
+ const STAGE_ORDER = [
51
+ 'analysis',
52
+ 'review-analysis',
53
+ 'plan',
54
+ 'review-plan',
55
+ 'code',
56
+ 'review-code',
57
+ 'task',
58
+ 'other'
59
+ ];
60
+ function stageOf(name) {
61
+ const stem = name.replace(/\.md$/, '');
62
+ if (stem === 'task')
63
+ return 'task';
64
+ if (stem.startsWith('review-analysis'))
65
+ return 'review-analysis';
66
+ if (stem.startsWith('review-plan'))
67
+ return 'review-plan';
68
+ if (stem.startsWith('review-code'))
69
+ return 'review-code';
70
+ if (stem.startsWith('analysis'))
71
+ return 'analysis';
72
+ if (stem.startsWith('plan'))
73
+ return 'plan';
74
+ if (stem.startsWith('code'))
75
+ return 'code';
76
+ return 'other';
77
+ }
78
+ // Group artifacts by workflow stage, preserving the input order (mtime ascending
79
+ // from enumerateArtifacts) within each stage and dropping empty stages.
80
+ function groupArtifacts(artifacts) {
81
+ const byStage = new Map();
82
+ for (const artifact of artifacts) {
83
+ const stage = stageOf(artifact.name);
84
+ const bucket = byStage.get(stage);
85
+ if (bucket)
86
+ bucket.push(artifact.name);
87
+ else
88
+ byStage.set(stage, [artifact.name]);
89
+ }
90
+ const groups = [];
91
+ for (const stage of STAGE_ORDER) {
92
+ const files = byStage.get(stage);
93
+ if (files && files.length > 0)
94
+ groups.push({ stage, files });
95
+ }
96
+ return groups;
97
+ }
98
+ // `frontmatterBranch` is the task.md `branch` field (caller passes '' when absent).
99
+ // It is read straight from frontmatter and never depends on a subprocess, so it
100
+ // keeps its value even when every git call fails. All other fields degrade to '-'
101
+ // on failure of their own command.
102
+ function collectGit(frontmatterBranch, run) {
103
+ const frontmatter = frontmatterBranch ? frontmatterBranch : DASH;
104
+ let current = DASH;
105
+ const cur = tryRun(run, 'git', ['rev-parse', '--abbrev-ref', 'HEAD']);
106
+ if (cur !== null && cur.trim())
107
+ current = cur.trim();
108
+ let match = DASH;
109
+ if (current !== DASH && frontmatter !== DASH) {
110
+ match = current === frontmatter ? 'yes' : 'no';
111
+ }
112
+ let exists = DASH;
113
+ if (frontmatter !== DASH) {
114
+ const verified = tryRun(run, 'git', ['rev-parse', '--verify', '--quiet', `refs/heads/${frontmatter}`]);
115
+ exists = verified === null ? 'no' : 'yes';
116
+ }
117
+ let uncommitted = DASH;
118
+ const porcelain = tryRun(run, 'git', ['status', '--porcelain']);
119
+ if (porcelain !== null) {
120
+ const changed = porcelain.split('\n').filter((line) => line.trim() !== '');
121
+ uncommitted = changed.length === 0 ? 'clean' : `${changed.length} file(s)`;
122
+ }
123
+ let aheadBehind = DASH;
124
+ if (frontmatter !== DASH) {
125
+ const counts = tryRun(run, 'git', [
126
+ 'rev-list',
127
+ '--left-right',
128
+ '--count',
129
+ `${frontmatter}...${frontmatter}@{upstream}`
130
+ ]);
131
+ if (counts !== null) {
132
+ const parts = counts.trim().split(/\s+/);
133
+ if (parts.length === 2)
134
+ aheadBehind = `${parts[0]} ahead / ${parts[1]} behind`;
135
+ }
136
+ }
137
+ return { current, frontmatter, match, exists, uncommitted, aheadBehind };
138
+ }
139
+ function collectPlatform(fm, run) {
140
+ let issue = DASH;
141
+ if (fm.issue_number && /^\d+$/.test(fm.issue_number)) {
142
+ const out = tryRun(run, 'gh', ['issue', 'view', fm.issue_number, '--json', 'state,labels']);
143
+ if (out !== null) {
144
+ try {
145
+ const data = JSON.parse(out);
146
+ const labels = Array.isArray(data.labels)
147
+ ? data.labels.map((label) => label.name).join(', ')
148
+ : '';
149
+ issue = labels ? `${data.state} [${labels}]` : `${data.state}`;
150
+ }
151
+ catch {
152
+ issue = DASH;
153
+ }
154
+ }
155
+ }
156
+ let pr = DASH;
157
+ if (fm.pr_status === 'created' && fm.pr_number && /^\d+$/.test(fm.pr_number)) {
158
+ const out = tryRun(run, 'gh', ['pr', 'view', fm.pr_number, '--json', 'state,statusCheckRollup']);
159
+ if (out !== null) {
160
+ try {
161
+ const data = JSON.parse(out);
162
+ const rollup = Array.isArray(data.statusCheckRollup) ? data.statusCheckRollup : [];
163
+ const passed = rollup.filter((check) => check.conclusion === 'SUCCESS' || check.state === 'SUCCESS').length;
164
+ pr = rollup.length > 0 ? `${data.state}, checks: ${passed}/${rollup.length}` : `${data.state}`;
165
+ }
166
+ catch {
167
+ pr = DASH;
168
+ }
169
+ }
170
+ }
171
+ return { issue, pr };
172
+ }
173
+ // Indent each label/value pair by two spaces and pad labels to a common width so
174
+ // every section reads as an aligned "key value" block.
175
+ function renderPairs(rows) {
176
+ const width = rows.reduce((max, [label]) => Math.max(max, label.length), 0);
177
+ return rows.map(([label, value]) => ` ${label.padEnd(width)} ${value}`.trimEnd());
178
+ }
179
+ function renderStatus(model) {
180
+ const lines = [];
181
+ lines.push(`Task ${model.taskId} (${model.shortId})`);
182
+ if (model.title)
183
+ lines.push(model.title);
184
+ lines.push('', 'Metadata', ...renderPairs(model.metadata));
185
+ lines.push('', `Artifacts (${model.artifacts.count})`);
186
+ if (model.artifacts.groups.length === 0) {
187
+ lines.push(' (none)');
188
+ }
189
+ else {
190
+ lines.push(...renderPairs(model.artifacts.groups.map((group) => [group.stage, group.files.join(', ')])));
191
+ }
192
+ lines.push('', 'Git', ...renderPairs([
193
+ ['current', model.git.current],
194
+ ['frontmatter', model.git.frontmatter],
195
+ ['match', model.git.match],
196
+ ['exists', model.git.exists],
197
+ ['uncommitted', model.git.uncommitted],
198
+ ['ahead/behind', model.git.aheadBehind]
199
+ ]));
200
+ const issueLabel = model.issueNumber ? `issue #${model.issueNumber}` : 'issue';
201
+ lines.push('', 'Platform', ...renderPairs([
202
+ [issueLabel, model.platform.issue],
203
+ ['pr', model.platform.pr]
204
+ ]));
205
+ return lines;
206
+ }
207
+ function status(args = []) {
208
+ if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
209
+ process.stdout.write(USAGE);
210
+ if (args.length === 0)
211
+ process.exitCode = 1;
212
+ return;
213
+ }
214
+ const resolved = resolveTaskRef(args[0]);
215
+ if (!resolved.ok) {
216
+ process.stderr.write(`ai task status: ${resolved.message}\n`);
217
+ process.exitCode = 1;
218
+ return;
219
+ }
220
+ const content = fs.readFileSync(resolved.taskMdPath, 'utf8');
221
+ const fm = parseTaskFrontmatter(content);
222
+ const run = makeRunner(resolved.repoRoot);
223
+ const artifacts = enumerateArtifacts(resolved.taskDir);
224
+ const model = {
225
+ taskId: resolved.taskId,
226
+ shortId: loadShortIdByTaskId(resolved.repoRoot).get(resolved.taskId) ?? DASH,
227
+ title: extractTitle(content),
228
+ issueNumber: fm.issue_number && /^\d+$/.test(fm.issue_number) ? fm.issue_number : '',
229
+ metadata: collectMetadata(fm),
230
+ artifacts: { count: artifacts.length, groups: groupArtifacts(artifacts) },
231
+ git: collectGit(fm.branch ?? '', run),
232
+ platform: collectPlatform(fm, run)
233
+ };
234
+ for (const line of renderStatus(model)) {
235
+ process.stdout.write(`${line}\n`);
236
+ }
237
+ }
238
+ export { status, makeRunner, collectMetadata, groupArtifacts, collectGit, collectPlatform, renderStatus, METADATA_KEYS };
239
+ //# sourceMappingURL=status.js.map
@@ -1,13 +1,25 @@
1
1
  const USAGE = `Usage: ai task <command> [options]
2
2
 
3
3
  Commands:
4
+ cat <ref> <artifact | N> Print a task artifact (by name or number)
5
+ files <ref> List artifacts in a task dir (numbered)
6
+ grep <pattern> [ref] [artifact | N] Literal search across task artifacts (omit ref to scan all)
7
+ log <ref> Render a task's activity log as a timeline
4
8
  ls [--all | --blocked | --completed] List tasks (default: active)
5
9
  show <N | #N | TASK-id> Print a task.md
10
+ status <ref> Aggregated status view (metadata / artifacts / git / platform)
6
11
 
7
12
  Examples:
13
+ ai task cat 11 analysis
14
+ ai task cat 11 3
15
+ ai task files 11
16
+ ai task grep resolveArtifact
17
+ ai task grep resolveArtifact 11
18
+ ai task log 11
8
19
  ai task ls
9
20
  ai task show 11
10
21
  ai task show TASK-20260612-162737
22
+ ai task status 11
11
23
 
12
24
  Run 'ai task <command> --help' for details.`;
13
25
  export async function runTask(args) {
@@ -22,6 +34,26 @@ export async function runTask(args) {
22
34
  return;
23
35
  }
24
36
  switch (subcommand) {
37
+ case 'cat': {
38
+ const { cat } = await import("./commands/cat.js");
39
+ cat(rest);
40
+ break;
41
+ }
42
+ case 'files': {
43
+ const { files } = await import("./commands/files.js");
44
+ files(rest);
45
+ break;
46
+ }
47
+ case 'grep': {
48
+ const { grep } = await import("./commands/grep.js");
49
+ grep(rest);
50
+ break;
51
+ }
52
+ case 'log': {
53
+ const { log } = await import("./commands/log.js");
54
+ log(rest);
55
+ break;
56
+ }
25
57
  case 'ls': {
26
58
  const { ls } = await import("./commands/ls.js");
27
59
  ls(rest);
@@ -32,6 +64,11 @@ export async function runTask(args) {
32
64
  show(rest);
33
65
  break;
34
66
  }
67
+ case 'status': {
68
+ const { status } = await import("./commands/status.js");
69
+ status(rest);
70
+ break;
71
+ }
35
72
  default:
36
73
  process.stderr.write(`Unknown task command: ${subcommand}\n\n`);
37
74
  process.stdout.write(`${USAGE}\n`);