@magnusekdahl/parallix 1.2.0 → 1.3.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.
Files changed (127) hide show
  1. package/index.js +190 -185
  2. package/lib/agents/agents.js +737 -838
  3. package/lib/agents/agents.ts +930 -0
  4. package/lib/agents/claude-telemetry.js +149 -154
  5. package/lib/agents/claude-telemetry.ts +233 -0
  6. package/lib/agents/claude.js +121 -131
  7. package/lib/agents/claude.ts +156 -0
  8. package/lib/agents/codex-telemetry.js +176 -164
  9. package/lib/agents/codex-telemetry.ts +205 -0
  10. package/lib/agents/codex.js +168 -201
  11. package/lib/agents/codex.ts +236 -0
  12. package/lib/agents/limit-hit.js +216 -226
  13. package/lib/agents/limit-hit.ts +262 -0
  14. package/lib/agents/mistral-telemetry.js +7 -10
  15. package/lib/agents/mistral-telemetry.ts +44 -0
  16. package/lib/agents/mistral.js +40 -58
  17. package/lib/agents/mistral.ts +84 -0
  18. package/lib/agents/opencode-export.js +126 -127
  19. package/lib/agents/opencode-export.ts +160 -0
  20. package/lib/agents/opencode-telemetry.js +282 -261
  21. package/lib/agents/opencode-telemetry.ts +350 -0
  22. package/lib/agents/opencode.js +263 -305
  23. package/lib/agents/opencode.ts +370 -0
  24. package/lib/agents/stage-telemetry.js +23 -24
  25. package/lib/agents/stage-telemetry.ts +47 -0
  26. package/lib/commands/active.js +502 -579
  27. package/lib/commands/active.ts +665 -0
  28. package/lib/commands/checkpoint.js +98 -74
  29. package/lib/commands/checkpoint.ts +79 -0
  30. package/lib/commands/config.js +61 -31
  31. package/lib/commands/config.ts +47 -0
  32. package/lib/commands/coverage-gate.js +271 -246
  33. package/lib/commands/coverage-gate.ts +362 -0
  34. package/lib/commands/diff.js +140 -119
  35. package/lib/commands/diff.ts +125 -0
  36. package/lib/commands/draft.js +770 -923
  37. package/lib/commands/draft.ts +1021 -0
  38. package/lib/commands/handoff.js +588 -608
  39. package/lib/commands/handoff.ts +694 -0
  40. package/lib/commands/integrate.js +1332 -1463
  41. package/lib/commands/integrate.ts +1688 -0
  42. package/lib/commands/mission-start.js +279 -237
  43. package/lib/commands/mission-start.ts +263 -0
  44. package/lib/commands/rebase.js +606 -582
  45. package/lib/commands/rebase.ts +635 -0
  46. package/lib/commands/repair-handoff.js +181 -179
  47. package/lib/commands/repair-handoff.ts +228 -0
  48. package/lib/commands/resolve-conflict.js +121 -102
  49. package/lib/commands/resolve-conflict.ts +112 -0
  50. package/lib/commands/review.js +3 -4
  51. package/lib/commands/review.ts +14 -0
  52. package/lib/commands/setup-review.js +4 -5
  53. package/lib/commands/setup-review.ts +14 -0
  54. package/lib/commands/setup.js +3 -3
  55. package/lib/commands/setup.ts +2 -0
  56. package/lib/commands/stats-backfill.js +394 -359
  57. package/lib/commands/stats-backfill.ts +418 -0
  58. package/lib/commands/stats.js +1424 -1665
  59. package/lib/commands/stats.ts +2186 -0
  60. package/lib/commands/status.js +219 -200
  61. package/lib/commands/status.ts +219 -0
  62. package/lib/commands/verify.js +3 -1
  63. package/lib/commands/verify.ts +2 -0
  64. package/lib/core/fmt.js +140 -211
  65. package/lib/core/fmt.ts +189 -0
  66. package/lib/core/git.js +121 -102
  67. package/lib/core/git.ts +146 -0
  68. package/lib/core/gitignore.js +59 -106
  69. package/lib/core/gitignore.ts +103 -0
  70. package/lib/core/mission-utils.js +833 -875
  71. package/lib/core/mission-utils.ts +998 -0
  72. package/lib/core/nels.js +112 -127
  73. package/lib/core/nels.ts +189 -0
  74. package/lib/core/persistent-data-migration.js +247 -205
  75. package/lib/core/persistent-data-migration.ts +255 -0
  76. package/lib/core/product-config.js +400 -476
  77. package/lib/core/product-config.ts +518 -0
  78. package/lib/core/runtime-matrix.js +41 -87
  79. package/lib/core/runtime-matrix.ts +84 -0
  80. package/lib/core/spawn-tee.js +152 -192
  81. package/lib/core/spawn-tee.ts +202 -0
  82. package/lib/core/state-map.js +92 -92
  83. package/lib/core/state-map.ts +115 -0
  84. package/lib/core/storage.js +101 -129
  85. package/lib/core/storage.ts +182 -0
  86. package/lib/core/subagent-limit.js +15 -16
  87. package/lib/core/subagent-limit.ts +25 -0
  88. package/lib/core/verification.js +148 -138
  89. package/lib/core/verification.ts +200 -0
  90. package/lib/index.js +142 -59
  91. package/lib/index.ts +134 -0
  92. package/lib/review/rebase.js +142 -145
  93. package/lib/review/rebase.ts +188 -0
  94. package/lib/review/review-adapter.js +99 -87
  95. package/lib/review/review-adapter.ts +198 -0
  96. package/lib/review/review-artifacts.js +486 -629
  97. package/lib/review/review-artifacts.ts +622 -0
  98. package/lib/review/review-commands.js +1220 -1373
  99. package/lib/review/review-commands.ts +1579 -0
  100. package/lib/review/review-events.js +544 -886
  101. package/lib/review/review-events.ts +954 -0
  102. package/lib/review/review-loop.js +945 -1020
  103. package/lib/review/review-loop.ts +1174 -0
  104. package/lib/review/review-polling.js +86 -115
  105. package/lib/review/review-polling.ts +194 -0
  106. package/lib/review/review-prompts.js +154 -189
  107. package/lib/review/review-prompts.ts +182 -0
  108. package/lib/review/review-state.js +246 -225
  109. package/lib/review/review-state.ts +353 -0
  110. package/lib/review/review.js +63 -84
  111. package/lib/review/review.ts +138 -0
  112. package/lib/tools/backlog.js +694 -680
  113. package/lib/tools/backlog.ts +835 -0
  114. package/lib/tools/forgejo.js +1270 -1405
  115. package/lib/tools/forgejo.ts +1793 -0
  116. package/lib/tools/gatekeeper.js +106 -96
  117. package/lib/tools/gatekeeper.ts +124 -0
  118. package/lib/tools/redgreen.js +200 -181
  119. package/lib/tools/redgreen.ts +221 -0
  120. package/lib/tools/sessions.js +58 -52
  121. package/lib/tools/sessions.ts +81 -0
  122. package/lib/tools/setup-review.js +902 -975
  123. package/lib/tools/setup-review.ts +1152 -0
  124. package/package.json +7 -5
  125. package/prompts/draft.md +1 -0
  126. package/prompts/portfolio.md +1 -1
  127. package/px.js +226 -210
@@ -1,327 +1,370 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const fmt = require('../core/fmt');
5
- const stats = require('./stats');
6
- const gitLib = require('../core/git');
7
- const {
8
- getTaskFrontmatterValue,
9
- getTaskStatus,
10
- resolveTaskFile,
11
- } = require('../tools/backlog');
12
- const { findMissionDir } = require('../core/mission-utils');
13
-
14
- /** @param {string} missionDir */
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const fs = __importStar(require("node:fs"));
36
+ const path = __importStar(require("node:path"));
37
+ const fmt = __importStar(require("../core/fmt.js"));
38
+ const stats = require("./stats.js");
39
+ const git_js_1 = require("../core/git.js");
40
+ const backlog_js_1 = require("../tools/backlog.js");
41
+ const mission_utils_js_1 = require("../core/mission-utils.js");
42
+ function getStats() {
43
+ return stats;
44
+ }
15
45
  function hasCheckpointFiles(missionDir) {
16
- if (!missionDir || !fs.existsSync(missionDir)) {return false;}
17
- return fs.readdirSync(missionDir).some(file => /^CP-\d+\.md$/i.test(file) || /^CHECKPOINT_FINAL\.md$/i.test(file));
46
+ if (!missionDir || !fs.existsSync(missionDir)) {
47
+ return false;
48
+ }
49
+ return fs.readdirSync(missionDir).some(file => /^CP-\d+\.md$/i.test(file) || /^CHECKPOINT_FINAL\.md$/i.test(file));
18
50
  }
19
-
20
51
  function listHistoricalMissionSlugs(rootDir = process.cwd()) {
21
- const missionsRoot = path.join(rootDir, 'docs', 'missions');
22
- if (!fs.existsSync(missionsRoot)) {return [];}
23
-
24
- const slugs = [];
25
- for (const year of fs.readdirSync(missionsRoot).sort()) {
26
- const yearDir = path.join(missionsRoot, year);
27
- if (!/^\d{4}$/.test(year) || !fs.statSync(yearDir).isDirectory()) {continue;}
28
- for (const slug of fs.readdirSync(yearDir).sort()) {
29
- if (!/^task-\d+/i.test(slug)) {continue;}
30
- const missionDir = path.join(yearDir, slug);
31
- if (!fs.statSync(missionDir).isDirectory()) {continue;}
32
- if (!hasCheckpointFiles(missionDir)) {continue;}
33
- slugs.push(slug);
34
- }
35
- }
36
- return slugs;
52
+ const missionsRoot = path.join(rootDir, 'docs', 'missions');
53
+ if (!fs.existsSync(missionsRoot)) {
54
+ return [];
55
+ }
56
+ const slugs = [];
57
+ for (const year of fs.readdirSync(missionsRoot).sort()) {
58
+ const yearDir = path.join(missionsRoot, year);
59
+ if (!/^\d{4}$/.test(year) || !fs.statSync(yearDir).isDirectory()) {
60
+ continue;
61
+ }
62
+ for (const slug of fs.readdirSync(yearDir).sort()) {
63
+ if (!/^task-\d+/i.test(slug)) {
64
+ continue;
65
+ }
66
+ const missionDir = path.join(yearDir, slug);
67
+ if (!fs.statSync(missionDir).isDirectory()) {
68
+ continue;
69
+ }
70
+ if (!hasCheckpointFiles(missionDir)) {
71
+ continue;
72
+ }
73
+ slugs.push(slug);
74
+ }
75
+ }
76
+ return slugs;
37
77
  }
38
-
39
- /** @param {*} value */
40
78
  function extractDateOnly(value) {
41
- const match = String(value || '').match(/^(\d{4}-\d{2}-\d{2})/);
42
- return match ? match[1] : null;
79
+ const match = String(value || '').match(/^(\d{4}-\d{2}-\d{2})/);
80
+ return match ? match[1] : null;
43
81
  }
44
-
45
- /** @param {*} value */
46
82
  function normalizeHistoricalImplementer(value) {
47
- const normalized = String(value || '').trim().toLowerCase();
48
- if (!normalized) {return null;}
49
- if (/(^|[^a-z])codex([^a-z]|$)/.test(normalized)) {return 'codex';}
50
- if (/(^|[^a-z])claude([^a-z]|$)/.test(normalized)) {return 'claude';}
51
- if (/(^|[^a-z])gemini([^a-z]|$)/.test(normalized)) {return 'gemini';}
52
- if (/(^|[^a-z])custom([^a-z]|$)/.test(normalized)) {return 'custom';}
53
- if (/(^|[^a-z])mistral([^a-z]|$)/.test(normalized)) {return 'mistral';}
54
- if (/(^|[^a-z])magnus([^a-z]|$)/.test(normalized)) {return 'magnus';}
55
- if (/(^|[^a-z])human([^a-z]|$)/.test(normalized)) {return 'human';}
56
- return null;
83
+ const normalized = String(value || '').trim().toLowerCase();
84
+ if (!normalized) {
85
+ return null;
86
+ }
87
+ if (/(^|[^a-z])codex([^a-z]|$)/.test(normalized)) {
88
+ return 'codex';
89
+ }
90
+ if (/(^|[^a-z])claude([^a-z]|$)/.test(normalized)) {
91
+ return 'claude';
92
+ }
93
+ if (/(^|[^a-z])gemini([^a-z]|$)/.test(normalized)) {
94
+ return 'gemini';
95
+ }
96
+ if (/(^|[^a-z])custom([^a-z]|$)/.test(normalized)) {
97
+ return 'custom';
98
+ }
99
+ if (/(^|[^a-z])mistral([^a-z]|$)/.test(normalized)) {
100
+ return 'mistral';
101
+ }
102
+ if (/(^|[^a-z])magnus([^a-z]|$)/.test(normalized)) {
103
+ return 'magnus';
104
+ }
105
+ if (/(^|[^a-z])human([^a-z]|$)/.test(normalized)) {
106
+ return 'human';
107
+ }
108
+ return null;
57
109
  }
58
-
59
- function deriveImplementerFromGitHistory(/** @type {string} */ slug, /** @type {string} */ taskFile, rootDir = process.cwd()) {
60
- const missionDir = findMissionDir(slug, rootDir);
61
- const targets = [missionDir, taskFile].filter(Boolean);
62
- if (targets.length === 0) {return null;}
63
-
64
- const result = gitLib.git(['-C', rootDir, 'log', '--all', '--format=%an|%ae', '--', ...(/** @type {string[]} */ (targets))]);
65
- if (result.status !== 0) {return null;}
66
-
67
- const authors = result.stdout
68
- .split('\n')
69
- .map(line => line.trim())
70
- .filter(Boolean)
71
- .map(line => {
72
- const [name = '', email = ''] = line.split('|');
73
- return normalizeHistoricalImplementer(email) || normalizeHistoricalImplementer(name);
110
+ function deriveImplementerFromGitHistory(slug, taskFile, rootDir = process.cwd()) {
111
+ const missionDir = (0, mission_utils_js_1.findMissionDir)(slug, rootDir);
112
+ const targets = [missionDir, taskFile].filter((x) => Boolean(x));
113
+ if (targets.length === 0) {
114
+ return null;
115
+ }
116
+ const result = (0, git_js_1.git)(['-C', rootDir, 'log', '--all', '--format=%an|%ae', '--', ...targets]);
117
+ if (result.status !== 0) {
118
+ return null;
119
+ }
120
+ const authors = result.stdout
121
+ .split('\n')
122
+ .map(line => line.trim())
123
+ .filter(Boolean)
124
+ .map(line => {
125
+ const [name = '', email = ''] = line.split('|');
126
+ return normalizeHistoricalImplementer(email) || normalizeHistoricalImplementer(name);
74
127
  })
75
- .filter(Boolean);
76
-
77
- if (authors.length === 0) {return null;}
78
- const uniqueAuthors = [...new Set(authors)];
79
- return uniqueAuthors.length === 1 ? uniqueAuthors[0] : uniqueAuthors[0];
128
+ .filter(Boolean);
129
+ if (authors.length === 0) {
130
+ return null;
131
+ }
132
+ const uniqueAuthors = [...new Set(authors)];
133
+ return uniqueAuthors.length === 1 ? uniqueAuthors[0] : uniqueAuthors[0];
80
134
  }
81
-
82
- function deriveDateFromGitHistory(/** @type {string} */ slug, /** @type {string} */ taskFile, rootDir = process.cwd()) {
83
- const missionDir = findMissionDir(slug, rootDir);
84
- const targets = [missionDir, taskFile].filter(Boolean);
85
- if (targets.length === 0) {return null;}
86
-
87
- const result = gitLib.git(['-C', rootDir, 'log', '--all', '-1', '--format=%cs', '--', ...(/** @type {string[]} */ (targets))]);
88
- if (result.status !== 0) {return null;}
89
- return extractDateOnly(result.stdout.trim());
135
+ function deriveDateFromGitHistory(slug, taskFile, rootDir = process.cwd()) {
136
+ const missionDir = (0, mission_utils_js_1.findMissionDir)(slug, rootDir);
137
+ const targets = [missionDir, taskFile].filter((x) => Boolean(x));
138
+ if (targets.length === 0) {
139
+ return null;
140
+ }
141
+ const result = (0, git_js_1.git)(['-C', rootDir, 'log', '--all', '-1', '--format=%cs', '--', ...targets]);
142
+ if (result.status !== 0) {
143
+ return null;
144
+ }
145
+ return extractDateOnly(result.stdout.trim());
90
146
  }
91
-
92
- function inferHistoricalClassificationFromMissionDoc(/** @type {string} */ slug, rootDir = process.cwd()) {
93
- const missionDir = findMissionDir(slug, rootDir);
94
- if (!missionDir) {return null;}
95
-
96
- const missionFile = path.join(missionDir, 'MISSION.md');
97
- if (!fs.existsSync(missionFile)) {return null;}
98
- const text = fs.readFileSync(missionFile, 'utf8').toLowerCase();
99
-
100
- const productSurfacePatterns = [
101
- /web-client\//g,
102
- /\bios\b/g,
103
- /\bandroid\b/g,
104
- /\bwearos\b/g,
105
- /\bauth-server\b/g,
106
- /\bserver\/src\b/g,
107
- /\bgrocer(?:y|ies)\b/g,
108
- /\bboard\b/g,
109
- /\bdelta\b/g,
110
- /\bsync\b/g,
111
- /\bprice\b/g,
112
- /\bstore\b/g,
113
- /\bshopping\b/g,
114
- /\bui\b/g,
115
- /\bclient\b/g,
116
- /\bcheapest\b/g,
117
- ];
118
- const workflowPatterns = [
119
- /workflow\//g,
120
- /node parallix\/index\.js/g,
121
- /\bworkflow\b/g,
122
- /\bagent\b/g,
123
- /\bbacklog\b/g,
124
- /\bforgejo\b/g,
125
- /\breview loop\b/g,
126
- /\breview\b/g,
127
- /\bdraft\b/g,
128
- /\bintegrate\b/g,
129
- /\brebase\b/g,
130
- /\bcheckpoint\b/g,
131
- /\bprompt\b/g,
132
- /\bstats\b/g,
133
- /\bworktree\b/g,
134
- /\bcli\b/g,
135
- /\bgit\b/g,
136
- /\bcoverage\b/g,
137
- /\bverification\b/g,
138
- ];
139
-
140
- const score = (/** @type {RegExp[]} */ patterns) => patterns.reduce((/** @type {number} */ sum, /** @type {RegExp} */ pattern) => sum + ((text.match(pattern) || []).length), 0);
141
- const productScore = score(productSurfacePatterns);
142
- const workflowScore = score(workflowPatterns);
143
-
144
- if (productScore === 0 && workflowScore === 0) {return null;}
145
- if (workflowScore >= productScore + 2) {return 'ai_sdlc';}
146
- if (productScore >= workflowScore + 2) {return 'user_value';}
147
-
148
- const titleLine = text.split('\n')[0] || '';
149
- if (/\bworkflow|agent|forgejo|backlog|review|rebase|checkpoint|stats|cli\b/.test(titleLine)) {
150
- return 'ai_sdlc';
151
- }
152
- if (/\bweb client|web-client|ios|android|grocer|board|delta|sync|store|price\b/.test(titleLine)) {
153
- return 'user_value';
154
- }
155
-
156
- return null;
147
+ function inferHistoricalClassificationFromMissionDoc(slug, rootDir = process.cwd()) {
148
+ const missionDir = (0, mission_utils_js_1.findMissionDir)(slug, rootDir);
149
+ if (!missionDir) {
150
+ return null;
151
+ }
152
+ const missionFile = path.join(missionDir, 'MISSION.md');
153
+ if (!fs.existsSync(missionFile)) {
154
+ return null;
155
+ }
156
+ const text = fs.readFileSync(missionFile, 'utf8').toLowerCase();
157
+ const productSurfacePatterns = [
158
+ /web-client\//g,
159
+ /\bios\b/g,
160
+ /\bandroid\b/g,
161
+ /\bwearos\b/g,
162
+ /\bauth-server\b/g,
163
+ /\bserver\/src\b/g,
164
+ /\bgrocer(?:y|ies)\b/g,
165
+ /\bboard\b/g,
166
+ /\bdelta\b/g,
167
+ /\bsync\b/g,
168
+ /\bprice\b/g,
169
+ /\bstore\b/g,
170
+ /\bshopping\b/g,
171
+ /\bui\b/g,
172
+ /\bclient\b/g,
173
+ /\bcheapest\b/g,
174
+ ];
175
+ const workflowPatterns = [
176
+ /workflow\//g,
177
+ /node parallix\/index\.js/g,
178
+ /\bworkflow\b/g,
179
+ /\bagent\b/g,
180
+ /\bbacklog\b/g,
181
+ /\bforgejo\b/g,
182
+ /\breview loop\b/g,
183
+ /\breview\b/g,
184
+ /\bdraft\b/g,
185
+ /\bintegrate\b/g,
186
+ /\brebase\b/g,
187
+ /\bcheckpoint\b/g,
188
+ /\bprompt\b/g,
189
+ /\bstats\b/g,
190
+ /\bworktree\b/g,
191
+ /\bcli\b/g,
192
+ /\bgit\b/g,
193
+ /\bcoverage\b/g,
194
+ /\bverification\b/g,
195
+ ];
196
+ const score = (patterns) => patterns.reduce((sum, pattern) => sum + ((text.match(pattern) || []).length), 0);
197
+ const productScore = score(productSurfacePatterns);
198
+ const workflowScore = score(workflowPatterns);
199
+ if (productScore === 0 && workflowScore === 0) {
200
+ return null;
201
+ }
202
+ if (workflowScore >= productScore + 2) {
203
+ return 'ai_sdlc';
204
+ }
205
+ if (productScore >= workflowScore + 2) {
206
+ return 'user_value';
207
+ }
208
+ const titleLine = text.split('\n')[0] || '';
209
+ if (/\bworkflow|agent|forgejo|backlog|review|rebase|checkpoint|stats|cli\b/.test(titleLine)) {
210
+ return 'ai_sdlc';
211
+ }
212
+ if (/\bweb client|web-client|ios|android|grocer|board|delta|sync|store|price\b/.test(titleLine)) {
213
+ return 'user_value';
214
+ }
215
+ return null;
157
216
  }
158
-
159
- /** @param {string} slug @param {string} taskFile @param {string} [rootDir] */
160
217
  function resolveHistoricalClassification(slug, taskFile, rootDir = process.cwd()) {
161
- const resolution = stats.resolveMissionClassification(slug, rootDir);
162
- if (resolution.classification) {
163
- return { value: resolution.classification, source: 'backlog-label' };
164
- }
165
- // Classification missing or invalid — fall through to fallbacks.
166
- const legacy = stats._internals.normalizeClassification(getTaskFrontmatterValue(taskFile, 'classification'));
167
- if (legacy) {
168
- return { value: legacy, source: 'backlog-classification' };
169
- }
170
- const inferred = inferHistoricalClassificationFromMissionDoc(slug, rootDir);
171
- if (inferred) {
172
- return { value: inferred, source: 'mission-doc-heuristic' };
173
- }
174
- return { value: null, source: null };
175
- }
176
-
177
- /** @param {string} [rootDir] @param {string|null} [filePath] */
178
- function collectHistoricalStatsBackfill(rootDir = process.cwd(), filePath = null) {
179
- filePath = filePath || stats.resolveStatsPath();
180
- const repoName = stats.resolveStatsRepoName(rootDir);
181
- const existingMissions = new Set(
182
- stats.loadStatsCsv(filePath, { rootDir }).rows
183
- .filter(row => String(row.repo || '').trim() === repoName)
184
- .map(row => row.mission)
185
- );
186
- const rows = [];
187
- const unresolved = [];
188
- const skipped = [];
189
-
190
- for (const slug of listHistoricalMissionSlugs(rootDir)) {
191
- if (existingMissions.has(slug)) {continue;}
192
-
193
- const taskResolution = resolveTaskFile(slug, rootDir);
194
- if (!taskResolution.ok) {
195
- unresolved.push({
196
- slug,
197
- reason: 'task-resolution',
198
- detail: taskResolution.reason,
199
- });
200
- continue;
201
- }
202
-
203
- const taskFile = /** @type {string} */ (taskResolution.taskFile);
204
- const status = getTaskStatus(taskFile);
205
- if (status !== 'done') {
206
- skipped.push({ slug, reason: `status=${status || 'unknown'}` });
207
- continue;
218
+ const s = getStats();
219
+ const resolution = s.resolveMissionClassification(slug, rootDir);
220
+ if (resolution.classification) {
221
+ return { value: resolution.classification, source: 'backlog-label' };
208
222
  }
209
-
210
- const date = extractDateOnly(getTaskFrontmatterValue(taskFile, 'updated_date')) || deriveDateFromGitHistory(slug, taskFile, rootDir);
211
- const classification = resolveHistoricalClassification(slug, taskFile, rootDir);
212
-
213
- let implementerInfo = null;
214
- let implementerError = null;
215
- try {
216
- implementerInfo = stats.deriveImplementerAndFixRounds(slug, rootDir);
217
- } catch (/** @type {unknown} */ error) {
218
- implementerError = /** @type{Error} */(error).message;
223
+ // Classification missing or invalid — fall through to fallbacks.
224
+ const classificationValue = (0, backlog_js_1.getTaskFrontmatterValue)(taskFile, 'classification');
225
+ const legacy = s._internals.normalizeClassification(classificationValue ?? '');
226
+ if (legacy) {
227
+ return { value: legacy, source: 'backlog-classification' };
219
228
  }
220
-
221
- if (!implementerInfo?.implementer || implementerInfo.implementer === 'unknown') {
222
- const gitHistoryImplementer = deriveImplementerFromGitHistory(slug, taskFile, rootDir);
223
- if (gitHistoryImplementer) {
224
- implementerInfo = {
225
- implementer: gitHistoryImplementer,
226
- prFixRounds: 0,
227
- source: 'git-history-author',
228
- };
229
- }
229
+ const inferred = inferHistoricalClassificationFromMissionDoc(slug, rootDir);
230
+ if (inferred) {
231
+ return { value: inferred, source: 'mission-doc-heuristic' };
230
232
  }
231
-
232
- if (!date || !classification.value || !implementerInfo?.implementer) {
233
- unresolved.push({
234
- slug,
235
- reason: 'missing-fields',
236
- date: date || null,
237
- classification: classification.value || null,
238
- implementer: implementerInfo?.implementer || null,
239
- prFixRounds: implementerInfo?.prFixRounds ?? null,
240
- sources: {
241
- classification: classification.source,
242
- implementer: implementerInfo?.source || null,
243
- },
244
- missing: [
245
- ...(!date ? ['date'] : []),
246
- ...(!classification.value ? ['classification'] : []),
247
- ...(!implementerInfo?.implementer ? ['implementer'] : []),
248
- ],
249
- detail: implementerError,
250
- });
251
- continue;
233
+ return { value: null, source: null };
234
+ }
235
+ function collectHistoricalStatsBackfill(rootDir = process.cwd(), filePath = null) {
236
+ const s = getStats();
237
+ filePath = filePath || s.resolveStatsPath();
238
+ const repoName = s.resolveStatsRepoName(rootDir);
239
+ const existingMissions = new Set(s.loadStatsCsv(filePath, { rootDir }).rows
240
+ .filter((row) => String(row.repo || '').trim() === repoName)
241
+ .map((row) => row.mission));
242
+ const rows = [];
243
+ const unresolved = [];
244
+ const skipped = [];
245
+ for (const slug of listHistoricalMissionSlugs(rootDir)) {
246
+ if (existingMissions.has(slug)) {
247
+ continue;
248
+ }
249
+ const taskResolution = (0, backlog_js_1.resolveTaskFile)(slug, rootDir);
250
+ if (!taskResolution.ok) {
251
+ unresolved.push({
252
+ slug,
253
+ reason: 'task-resolution',
254
+ detail: taskResolution.reason,
255
+ });
256
+ continue;
257
+ }
258
+ const taskFile = taskResolution.taskFile;
259
+ const status = (0, backlog_js_1.getTaskStatus)(taskFile);
260
+ if (status !== 'done') {
261
+ skipped.push({ slug, reason: `status=${status || 'unknown'}` });
262
+ continue;
263
+ }
264
+ const date = extractDateOnly((0, backlog_js_1.getTaskFrontmatterValue)(taskFile, 'updated_date') ?? '') || deriveDateFromGitHistory(slug, taskFile, rootDir);
265
+ const classification = resolveHistoricalClassification(slug, taskFile, rootDir);
266
+ let implementerInfo = null;
267
+ let implementerError = null;
268
+ try {
269
+ implementerInfo = s.deriveImplementerAndFixRounds(slug, rootDir);
270
+ }
271
+ catch (error) {
272
+ implementerError = error instanceof Error ? error.message : String(error);
273
+ }
274
+ if (!implementerInfo?.implementer || implementerInfo.implementer === 'unknown') {
275
+ const gitHistoryImplementer = deriveImplementerFromGitHistory(slug, taskFile, rootDir);
276
+ if (gitHistoryImplementer) {
277
+ implementerInfo = {
278
+ implementer: gitHistoryImplementer,
279
+ prFixRounds: 0,
280
+ source: 'git-history-author',
281
+ };
282
+ }
283
+ }
284
+ if (!date || !classification.value || !implementerInfo?.implementer) {
285
+ unresolved.push({
286
+ slug,
287
+ reason: 'missing-fields',
288
+ date: date || null,
289
+ classification: classification.value || null,
290
+ implementer: implementerInfo?.implementer || null,
291
+ prFixRounds: implementerInfo?.prFixRounds ?? null,
292
+ sources: {
293
+ classification: classification.source,
294
+ implementer: implementerInfo?.source || null,
295
+ },
296
+ missing: [
297
+ ...(!date ? ['date'] : []),
298
+ ...(!classification.value ? ['classification'] : []),
299
+ ...(!implementerInfo?.implementer ? ['implementer'] : []),
300
+ ],
301
+ detail: implementerError,
302
+ });
303
+ continue;
304
+ }
305
+ rows.push({
306
+ date,
307
+ repo: repoName,
308
+ mission: slug,
309
+ classification: classification.value,
310
+ implementer: implementerInfo.implementer,
311
+ pr_fix_rounds: String(implementerInfo.prFixRounds),
312
+ sources: {
313
+ date: 'backlog-updated_date',
314
+ classification: classification.source,
315
+ implementer: implementerInfo.source,
316
+ },
317
+ });
252
318
  }
253
-
254
- rows.push({
255
- date,
256
- repo: repoName,
257
- mission: slug,
258
- classification: classification.value,
259
- implementer: implementerInfo.implementer,
260
- pr_fix_rounds: String(implementerInfo.prFixRounds),
261
- sources: {
262
- date: 'backlog-updated_date',
263
- classification: classification.source,
264
- implementer: implementerInfo.source,
265
- },
266
- });
267
- }
268
-
269
- rows.sort((a, b) => a.date.localeCompare(b.date) || a.mission.localeCompare(b.mission));
270
- unresolved.sort((a, b) => a.slug.localeCompare(b.slug));
271
- skipped.sort((a, b) => a.slug.localeCompare(b.slug));
272
-
273
- return { rows, unresolved, skipped };
319
+ rows.sort((a, b) => a.date.localeCompare(b.date) || a.mission.localeCompare(b.mission));
320
+ unresolved.sort((a, b) => a.slug.localeCompare(b.slug));
321
+ skipped.sort((a, b) => a.slug.localeCompare(b.slug));
322
+ return { rows, unresolved, skipped };
274
323
  }
275
-
276
- /** @param {{rows: any[], unresolved: any[], skipped: any[]}} report */
277
324
  function renderBackfillSummary(report) {
278
- const lines = [];
279
- lines.push(`Resolved rows: ${report.rows.length}`);
280
- lines.push(`Unresolved missions: ${report.unresolved.length}`);
281
- lines.push(`Skipped missions: ${report.skipped.length}`);
282
- lines.push('');
283
-
284
- if (report.rows.length > 0) {
285
- lines.push('Resolved:');
286
- for (const row of report.rows) {
287
- lines.push(`- ${row.date} ${row.mission} ${row.classification} ${row.implementer} ${row.pr_fix_rounds} [${row.sources.classification}/${row.sources.implementer}]`);
288
- }
325
+ const lines = [];
326
+ lines.push(`Resolved rows: ${report.rows.length}`);
327
+ lines.push(`Unresolved missions: ${report.unresolved.length}`);
328
+ lines.push(`Skipped missions: ${report.skipped.length}`);
289
329
  lines.push('');
290
- }
291
-
292
- if (report.unresolved.length > 0) {
293
- lines.push('Unresolved:');
294
- for (const item of report.unresolved) {
295
- const missing = Array.isArray(item.missing) && item.missing.length > 0 ? ` missing=${item.missing.join(',')}` : '';
296
- const detail = item.detail ? ` detail=${item.detail}` : '';
297
- lines.push(`- ${item.slug} reason=${item.reason}${missing}${detail}`);
330
+ if (report.rows.length > 0) {
331
+ lines.push('Resolved:');
332
+ for (const row of report.rows) {
333
+ lines.push(`- ${row.date} ${row.mission} ${row.classification} ${row.implementer} ${row.pr_fix_rounds} [${row.sources.classification}/${row.sources.implementer}]`);
334
+ }
335
+ lines.push('');
298
336
  }
299
- lines.push('');
300
- }
301
-
302
- if (report.skipped.length > 0) {
303
- lines.push('Skipped:');
304
- for (const item of report.skipped) {
305
- lines.push(`- ${item.slug} ${item.reason}`);
337
+ if (report.unresolved.length > 0) {
338
+ lines.push('Unresolved:');
339
+ for (const item of report.unresolved) {
340
+ const missing = Array.isArray(item.missing) && item.missing.length > 0 ? ` missing=${item.missing.join(',')}` : '';
341
+ const detail = item.detail ? ` detail=${item.detail}` : '';
342
+ lines.push(`- ${item.slug} reason=${item.reason}${missing}${detail}`);
343
+ }
344
+ lines.push('');
306
345
  }
307
- }
308
-
309
- return lines.join('\n');
346
+ if (report.skipped.length > 0) {
347
+ lines.push('Skipped:');
348
+ for (const item of report.skipped) {
349
+ lines.push(`- ${item.slug} ${item.reason}`);
350
+ }
351
+ }
352
+ return lines.join('\n');
310
353
  }
311
-
312
- /** @param {any[]} rows @param {string|null} [filePath] @param {string} [rootDir] */
313
354
  function applyBackfillRows(rows, filePath = null, rootDir = process.cwd()) {
314
- filePath = filePath || stats.resolveStatsPath({ ensureDir: true });
315
- let changed = 0;
316
- for (const row of rows) {
317
- const result = stats.upsertStatsRow(row, { filePath, rootDir });
318
- if (result.changed) {changed += 1;}
319
- }
320
- return changed;
355
+ const s = getStats();
356
+ filePath = filePath || s.resolveStatsPath({ ensureDir: true });
357
+ let changed = 0;
358
+ for (const row of rows) {
359
+ const result = s.upsertStatsRow(row, { filePath, rootDir });
360
+ if (result.changed) {
361
+ changed += 1;
362
+ }
363
+ }
364
+ return changed;
321
365
  }
322
-
323
366
  function printUsage(log = fmt.log.plain) {
324
- log(`Usage: px stats-backfill [--apply] [--json] [--csv-file <path>]
367
+ log(`Usage: px stats-backfill [--apply] [--json] [--csv-file <path>]
325
368
 
326
369
  Examples:
327
370
  px stats-backfill
@@ -334,69 +377,61 @@ Notes:
334
377
  - It uses strict workflow stats derivation for implementer/fix rounds and historical fallbacks for classification.
335
378
  - Non-done missions are skipped and unresolved missions are reported without being written.`);
336
379
  }
337
-
338
- /** @param {string[]} args @param {{log?: Function, error?: Function, rootDir?: string}} options */
339
380
  function statsBackfill(args, options = {}) {
340
- /** @type{{log?: Function, error?: Function, rootDir?: string}} */
341
- const opts = options;
342
- const log = opts.log || fmt.log.plain;
343
- const error = opts.error || fmt.log.plainError;
344
- const rootDir = opts.rootDir || process.cwd();
345
-
346
- if (args.includes('--help') || args.includes('-h')) {
347
- printUsage(log);
348
- return;
349
- }
350
-
351
- let apply = false;
352
- let json = false;
353
- let filePath = null;
354
-
355
- for (let i = 0; i < args.length; i += 1) {
356
- const arg = args[i];
357
- if (arg === '--apply') {
358
- apply = true;
359
- continue;
360
- }
361
- if (arg === '--json') {
362
- json = true;
363
- continue;
364
- }
365
- if (arg === '--csv-file' && i + 1 < args.length) {
366
- filePath = args[i + 1];
367
- i += 1;
368
- }
369
- }
370
- filePath = filePath || stats.resolveStatsPath({ ensureDir: apply });
371
-
381
+ const opts = options;
382
+ const log = opts.log || fmt.log.plain;
383
+ const error = opts.error || fmt.log.plainError;
384
+ const rootDir = opts.rootDir || process.cwd();
385
+ if (args.includes('--help') || args.includes('-h')) {
386
+ printUsage(log);
387
+ return;
388
+ }
389
+ let apply = false;
390
+ let json = false;
391
+ let filePath = null;
392
+ for (let i = 0; i < args.length; i += 1) {
393
+ const arg = args[i];
394
+ if (arg === '--apply') {
395
+ apply = true;
396
+ continue;
397
+ }
398
+ if (arg === '--json') {
399
+ json = true;
400
+ continue;
401
+ }
402
+ if (arg === '--csv-file' && i + 1 < args.length) {
403
+ filePath = args[i + 1];
404
+ i += 1;
405
+ }
406
+ }
407
+ const s = getStats();
408
+ filePath = filePath || s.resolveStatsPath({ ensureDir: apply });
372
409
  const report = collectHistoricalStatsBackfill(rootDir, filePath);
373
410
  const changed = apply ? applyBackfillRows(report.rows, filePath, rootDir) : 0;
374
- const payload = {
375
- resolved: report.rows.length,
376
- unresolved: report.unresolved.length,
377
- skipped: report.skipped.length,
378
- changed,
379
- rows: report.rows,
380
- unresolvedItems: report.unresolved,
381
- skippedItems: report.skipped,
382
- };
383
-
384
- if (json) {
385
- log(JSON.stringify(payload, null, 2));
386
- } else {
387
- log(renderBackfillSummary(report));
388
- if (apply) {
389
- log('');
390
- log(fmt.status('PASS', `Applied ${changed} stats rows to ${filePath}`));
391
- }
392
- }
393
-
394
- if (apply && report.unresolved.length > 0) {
395
- error(fmt.status('INFO', `${report.unresolved.length} missions remain unresolved and were not written.`));
396
- }
411
+ const payload = {
412
+ resolved: report.rows.length,
413
+ unresolved: report.unresolved.length,
414
+ skipped: report.skipped.length,
415
+ changed,
416
+ rows: report.rows,
417
+ unresolvedItems: report.unresolved,
418
+ skippedItems: report.skipped,
419
+ };
420
+ if (json) {
421
+ log(JSON.stringify(payload, null, 2));
422
+ }
423
+ else {
424
+ log(renderBackfillSummary(report));
425
+ if (apply) {
426
+ log('');
427
+ log(fmt.status('PASS', `Applied ${changed} stats rows to ${filePath}`));
428
+ }
429
+ }
430
+ if (apply && report.unresolved.length > 0) {
431
+ error(fmt.status('INFO', `${report.unresolved.length} missions remain unresolved and were not written.`));
432
+ }
397
433
  }
398
-
434
+ statsBackfill.collectHistoricalStatsBackfill = collectHistoricalStatsBackfill;
435
+ statsBackfill.inferHistoricalClassificationFromMissionDoc = inferHistoricalClassificationFromMissionDoc;
436
+ statsBackfill.extractDateOnly = extractDateOnly;
399
437
  module.exports = statsBackfill;
400
- module.exports.collectHistoricalStatsBackfill = collectHistoricalStatsBackfill;
401
- module.exports.inferHistoricalClassificationFromMissionDoc = inferHistoricalClassificationFromMissionDoc;
402
- module.exports.extractDateOnly = extractDateOnly;