trackops 2.0.3 → 2.0.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 (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +695 -402
  3. package/bin/trackops.js +116 -116
  4. package/lib/config.js +326 -326
  5. package/lib/control.js +208 -208
  6. package/lib/env.js +244 -244
  7. package/lib/init.js +325 -325
  8. package/lib/locale.js +24 -0
  9. package/lib/opera-bootstrap.js +941 -874
  10. package/lib/opera.js +494 -477
  11. package/lib/preferences.js +74 -74
  12. package/lib/registry.js +214 -196
  13. package/lib/release.js +56 -56
  14. package/lib/runtime-state.js +144 -144
  15. package/lib/server.js +312 -207
  16. package/lib/skills.js +74 -57
  17. package/lib/workspace.js +260 -260
  18. package/locales/en.json +192 -166
  19. package/locales/es.json +192 -166
  20. package/package.json +61 -58
  21. package/scripts/postinstall-locale.js +21 -21
  22. package/scripts/skills-marketplace-smoke.js +124 -124
  23. package/scripts/smoke-tests.js +558 -554
  24. package/scripts/sync-skill-version.js +21 -21
  25. package/scripts/validate-skill.js +103 -103
  26. package/skills/trackops/SKILL.md +126 -122
  27. package/skills/trackops/agents/openai.yaml +7 -7
  28. package/skills/trackops/locales/en/SKILL.md +126 -122
  29. package/skills/trackops/locales/en/references/activation.md +94 -75
  30. package/skills/trackops/locales/en/references/troubleshooting.md +73 -55
  31. package/skills/trackops/locales/en/references/workflow.md +55 -32
  32. package/skills/trackops/references/activation.md +94 -75
  33. package/skills/trackops/references/troubleshooting.md +73 -55
  34. package/skills/trackops/references/workflow.md +55 -32
  35. package/skills/trackops/skill.json +29 -29
  36. package/templates/hooks/post-checkout +2 -2
  37. package/templates/hooks/post-commit +2 -2
  38. package/templates/hooks/post-merge +2 -2
  39. package/templates/opera/agent.md +28 -27
  40. package/templates/opera/architecture/dependency-graph.md +24 -24
  41. package/templates/opera/architecture/runtime-automation.md +24 -24
  42. package/templates/opera/architecture/runtime-operations.md +34 -34
  43. package/templates/opera/en/agent.md +22 -21
  44. package/templates/opera/en/architecture/dependency-graph.md +24 -24
  45. package/templates/opera/en/architecture/runtime-automation.md +24 -24
  46. package/templates/opera/en/architecture/runtime-operations.md +34 -34
  47. package/templates/opera/en/reviews/delivery-audit.md +18 -18
  48. package/templates/opera/en/reviews/integration-audit.md +18 -18
  49. package/templates/opera/en/router.md +24 -19
  50. package/templates/opera/references/autonomy-and-recovery.md +117 -117
  51. package/templates/opera/references/opera-cycle.md +193 -193
  52. package/templates/opera/registry.md +28 -28
  53. package/templates/opera/reviews/delivery-audit.md +18 -18
  54. package/templates/opera/reviews/integration-audit.md +18 -18
  55. package/templates/opera/router.md +54 -49
  56. package/templates/skills/changelog-updater/SKILL.md +69 -69
  57. package/templates/skills/commiter/SKILL.md +99 -99
  58. package/templates/skills/opera-contract-auditor/SKILL.md +38 -38
  59. package/templates/skills/opera-contract-auditor/locales/en/SKILL.md +38 -38
  60. package/templates/skills/opera-policy-guard/SKILL.md +26 -26
  61. package/templates/skills/opera-policy-guard/locales/en/SKILL.md +26 -26
  62. package/templates/skills/opera-skill/SKILL.md +279 -0
  63. package/templates/skills/opera-skill/locales/en/SKILL.md +279 -0
  64. package/templates/skills/opera-skill/locales/en/references/phase-dod.md +138 -0
  65. package/templates/skills/opera-skill/references/phase-dod.md +138 -0
  66. package/templates/skills/project-starter-skill/SKILL.md +150 -131
  67. package/templates/skills/project-starter-skill/locales/en/SKILL.md +143 -105
  68. package/templates/skills/project-starter-skill/references/opera-cycle.md +195 -193
  69. package/ui/css/base.css +284 -266
  70. package/ui/css/charts.css +425 -327
  71. package/ui/css/components.css +1107 -570
  72. package/ui/css/onboarding.css +133 -0
  73. package/ui/css/panels.css +345 -406
  74. package/ui/css/terminal.css +125 -0
  75. package/ui/css/timeline.css +58 -0
  76. package/ui/css/tokens.css +284 -227
  77. package/ui/favicon.svg +5 -5
  78. package/ui/index.html +99 -96
  79. package/ui/js/api.js +49 -13
  80. package/ui/js/app.js +28 -32
  81. package/ui/js/charts.js +526 -0
  82. package/ui/js/console-logger.js +172 -172
  83. package/ui/js/filters.js +247 -0
  84. package/ui/js/icons.js +129 -104
  85. package/ui/js/keyboard.js +229 -0
  86. package/ui/js/onboarding.js +33 -42
  87. package/ui/js/router.js +142 -125
  88. package/ui/js/theme.js +100 -100
  89. package/ui/js/time-tracker.js +248 -248
  90. package/ui/js/views/board.js +84 -114
  91. package/ui/js/views/dashboard.js +870 -0
  92. package/ui/js/views/flash.js +47 -47
  93. package/ui/js/views/projects.js +745 -0
  94. package/ui/js/views/scrum.js +476 -0
  95. package/ui/js/views/settings.js +153 -203
  96. package/ui/js/views/sidebar.js +37 -31
  97. package/ui/js/views/tasks.js +218 -101
  98. package/ui/js/views/timeline.js +265 -0
  99. package/ui/js/views/topbar.js +94 -107
  100. package/ui/app.js +0 -950
  101. package/ui/js/views/insights.js +0 -340
  102. package/ui/js/views/overview.js +0 -369
  103. package/ui/styles.css +0 -688
package/lib/init.js CHANGED
@@ -1,325 +1,325 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { spawnSync } = require("child_process");
6
-
7
- const config = require("./config");
8
- const registry = require("./registry");
9
- const env = require("./env");
10
- const workspace = require("./workspace");
11
- const { t, setLocale } = require("./i18n");
12
- const { detectSystemLocale, promptForLocale, resolveLocale } = require("./locale");
13
- const runtimeState = require("./runtime-state");
14
-
15
- const GENERATED_SCRIPT_COMMANDS = {
16
- ops: "npx --yes trackops",
17
- "ops:help": "npx --yes trackops help",
18
- "ops:dashboard": "npx --yes trackops dashboard",
19
- "ops:status": "npx --yes trackops status",
20
- "ops:next": "npx --yes trackops next",
21
- "ops:sync": "npx --yes trackops sync",
22
- "ops:repo": "npx --yes trackops refresh-repo",
23
- };
24
-
25
- function nowIso() {
26
- return new Date().toISOString();
27
- }
28
-
29
- function parseArgs(args) {
30
- const options = {
31
- locale: null,
32
- name: null,
33
- withOpera: false,
34
- phases: null,
35
- noBootstrap: false,
36
- legacyLayout: false,
37
- bootstrapMode: "auto",
38
- technicalLevel: null,
39
- projectState: null,
40
- docsState: null,
41
- decisionOwnership: null,
42
- };
43
- for (let i = 0; i < args.length; i += 1) {
44
- if (args[i] === "--locale" && args[i + 1]) { options.locale = args[i + 1]; i += 1; }
45
- else if (args[i] === "--name" && args[i + 1]) { options.name = args[i + 1]; i += 1; }
46
- else if (args[i] === "--with-opera") { options.withOpera = true; }
47
- else if (args[i] === "--no-bootstrap") { options.noBootstrap = true; }
48
- else if (args[i] === "--legacy-layout") { options.legacyLayout = true; }
49
- else if (args[i] === "--bootstrap-mode" && args[i + 1]) { options.bootstrapMode = args[i + 1]; i += 1; }
50
- else if (args[i] === "--technical-level" && args[i + 1]) { options.technicalLevel = args[i + 1]; i += 1; }
51
- else if (args[i] === "--project-state" && args[i + 1]) { options.projectState = args[i + 1]; i += 1; }
52
- else if (args[i] === "--docs-state" && args[i + 1]) { options.docsState = args[i + 1]; i += 1; }
53
- else if (args[i] === "--decision-ownership" && args[i + 1]) { options.decisionOwnership = args[i + 1]; i += 1; }
54
- else if (args[i] === "--phases" && args[i + 1]) {
55
- try { options.phases = JSON.parse(args[i + 1]); } catch (_e) { /* ignore */ }
56
- i += 1;
57
- }
58
- }
59
- return options;
60
- }
61
-
62
- function detectProjectName(root) {
63
- const pkgPath = path.join(root, "package.json");
64
- if (fs.existsSync(pkgPath)) {
65
- try {
66
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
67
- return pkg.displayName || pkg.name || path.basename(root);
68
- } catch (_e) {
69
- // noop
70
- }
71
- }
72
- return path.basename(root);
73
- }
74
-
75
- function buildDefaultControl(context, options) {
76
- const locale = resolveLocale(options.locale, runtimeState.getGlobalLocale() || config.DEFAULT_LOCALE);
77
- const phases = options.phases || config.buildDefaultPhases(locale);
78
- const isSplit = context.layout === "split";
79
- setLocale(locale);
80
-
81
- return {
82
- meta: {
83
- projectName: options.name || "My Project",
84
- controlVersion: 2,
85
- locale,
86
- phases,
87
- updatedAt: nowIso(),
88
- executionSource: "project_control.json",
89
- currentFocus: t("init.defaultFocus"),
90
- focusPhase: phases[0]?.id || "O",
91
- deliveryTarget: t("init.defaultTarget"),
92
- workspace: isSplit ? {
93
- layout: "split",
94
- workspaceRoot: ".",
95
- appDir: path.basename(context.appRoot),
96
- opsDir: path.basename(context.opsRoot),
97
- developmentBranch: context.branches.development,
98
- publishBranch: context.branches.publish,
99
- publishMode: context.publish.mode,
100
- } : undefined,
101
- environment: {
102
- rootEnvFile: path.relative(context.workspaceRoot, context.env.rootFile).replace(/\\/g, "/"),
103
- exampleFile: path.relative(context.workspaceRoot, context.env.exampleFile).replace(/\\/g, "/"),
104
- appBridgeFile: path.relative(context.workspaceRoot, context.env.appBridgeFile).replace(/\\/g, "/"),
105
- bridgeMode: isSplit ? "symlink-or-copy" : "none",
106
- requiredKeys: [],
107
- optionalKeys: [],
108
- lastAuditAt: null,
109
- },
110
- userProfile: {
111
- technicalLevel: null,
112
- explanationMode: null,
113
- capturedAt: null,
114
- },
115
- discovery: {
116
- projectState: null,
117
- documentationState: null,
118
- availableArtifacts: [],
119
- },
120
- },
121
- checks: {
122
- lastBuild: { status: "pending", date: null, note: "" },
123
- lastTest: { status: "pending", date: null, note: "" },
124
- lastReview: { status: "pending", date: null, note: "" },
125
- },
126
- rituals: {
127
- startOfSession: ["trackops status", "trackops next"],
128
- beforeImplementation: ["trackops task start <task-id>"],
129
- endOfSession: ["trackops task review|complete|block <task-id> <note>", "trackops sync"],
130
- beforeCommit: ["trackops status", "trackops sync"],
131
- },
132
- milestones: [],
133
- decisionsPending: [],
134
- tasks: [
135
- {
136
- id: "ops-bootstrap",
137
- title: t("init.defaultTaskTitle"),
138
- phase: phases[0]?.id || "O",
139
- stream: "Operations",
140
- priority: "P0",
141
- status: "pending",
142
- required: true,
143
- dependsOn: [],
144
- summary: t("init.defaultTaskSummary"),
145
- acceptance: [],
146
- history: [{ at: nowIso(), action: "create", note: "trackops init" }],
147
- },
148
- ],
149
- findings: [],
150
- };
151
- }
152
-
153
- function upsertScripts(root) {
154
- const pkgPath = path.join(root, "package.json");
155
- let pkg = {};
156
- if (fs.existsSync(pkgPath)) {
157
- try { pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); } catch (_e) { /* ignore */ }
158
- }
159
- pkg.scripts = pkg.scripts || {};
160
- Object.assign(pkg.scripts, GENERATED_SCRIPT_COMMANDS);
161
- fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
162
- }
163
-
164
- function installHooks(context) {
165
- const hooksDir = context.paths.hooksDir;
166
- fs.mkdirSync(hooksDir, { recursive: true });
167
-
168
- const relativeCommand = context.layout === "split"
169
- ? "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n"
170
- : "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n";
171
- const hookContent = `#!/bin/sh\n${relativeCommand}`;
172
- for (const hookName of ["post-commit", "post-checkout", "post-merge"]) {
173
- const hookPath = path.join(hooksDir, hookName);
174
- fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
175
- }
176
-
177
- if (fs.existsSync(path.join(context.workspaceRoot, ".git"))) {
178
- const hooksPath = context.layout === "split" ? "ops/.githooks" : ".githooks";
179
- spawnSync("git", ["config", "core.hooksPath", hooksPath], { cwd: context.workspaceRoot, encoding: "utf8" });
180
- }
181
- }
182
-
183
- function ensureTmpDir(context) {
184
- fs.mkdirSync(context.paths.tmpDir, { recursive: true });
185
- const gitkeep = path.join(context.paths.tmpDir, ".gitkeep");
186
- if (!fs.existsSync(gitkeep)) {
187
- fs.writeFileSync(gitkeep, "", "utf8");
188
- }
189
- }
190
-
191
- function ensureSplitLayoutAllowed(targetRoot) {
192
- const entries = fs.readdirSync(targetRoot, { withFileTypes: true });
193
- const meaningful = entries.filter((entry) => ![".git"].includes(entry.name));
194
- if (meaningful.length > 0) {
195
- throw new Error("Directory is not empty. Run 'trackops workspace migrate' to convert an existing project.");
196
- }
197
- }
198
-
199
- function initSplitProject(root, options) {
200
- const targetRoot = path.resolve(root);
201
- fs.mkdirSync(targetRoot, { recursive: true });
202
- ensureSplitLayoutAllowed(targetRoot);
203
-
204
- const manifest = workspace.buildManifest();
205
- const context = config.createSplitContext(targetRoot, manifest);
206
- fs.mkdirSync(context.appRoot, { recursive: true });
207
- fs.mkdirSync(context.opsRoot, { recursive: true });
208
- config.saveWorkspaceManifest(context, manifest);
209
- workspace.ensureRootGitignore(targetRoot);
210
-
211
- const control = buildDefaultControl(context, options);
212
- control.meta.projectName = options.name || detectProjectName(context.workspaceRoot);
213
- config.saveControl(context, control);
214
-
215
- installHooks(context);
216
- ensureTmpDir(context);
217
- const controlApi = require("./control");
218
- controlApi.syncDocs(context, control);
219
- env.syncEnvironment(context, control);
220
-
221
- try {
222
- registry.registerProject(context.workspaceRoot);
223
- } catch (_e) {
224
- // ignore
225
- }
226
-
227
- console.log(t("init.created", { file: ".trackops-workspace.json" }));
228
- console.log(t("init.created", { file: "ops/project_control.json" }));
229
- console.log(t("init.created", { file: "ops/.githooks/" }));
230
- console.log(t("init.created", { file: ".env" }));
231
- console.log(t("init.created", { file: ".env.example" }));
232
- console.log("");
233
- console.log(t("init.welcome"));
234
-
235
- return { root: context.workspaceRoot, context, isUpgrade: false, operaDetected: false };
236
- }
237
-
238
- function initLegacyProject(root, options) {
239
- const targetRoot = path.resolve(root);
240
- const context = config.createLegacyContext(targetRoot);
241
- const controlFile = context.controlFile;
242
- const isUpgrade = fs.existsSync(controlFile);
243
- options.locale = resolveLocale(options.locale, detectSystemLocale());
244
-
245
- if (!options.name) {
246
- options.name = detectProjectName(targetRoot);
247
- }
248
-
249
- if (isUpgrade) {
250
- const existing = JSON.parse(fs.readFileSync(controlFile, "utf8"));
251
- if (!existing.meta.phases) existing.meta.phases = options.phases || config.buildDefaultPhases(options.locale);
252
- if (!existing.meta.locale) existing.meta.locale = options.locale || config.DEFAULT_LOCALE;
253
- if (!existing.meta.controlVersion || existing.meta.controlVersion < 2) existing.meta.controlVersion = 2;
254
- existing.meta.updatedAt = nowIso();
255
- fs.writeFileSync(controlFile, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
256
- console.log(t("init.updated", { file: "project_control.json" }));
257
- } else {
258
- const control = buildDefaultControl(context, options);
259
- control.meta.projectName = options.name;
260
- fs.writeFileSync(controlFile, `${JSON.stringify(control, null, 2)}\n`, "utf8");
261
- console.log(t("init.created", { file: "project_control.json" }));
262
- }
263
-
264
- upsertScripts(targetRoot);
265
- console.log(t("init.updated", { file: "package.json" }));
266
-
267
- installHooks(context);
268
- console.log(t("init.created", { file: ".githooks/" }));
269
- ensureTmpDir(context);
270
-
271
- try {
272
- registry.registerProject(targetRoot);
273
- console.log(t("init.registered"));
274
- } catch (_e) {
275
- // ignore
276
- }
277
-
278
- console.log("");
279
- console.log(t("init.welcome"));
280
- return { root: targetRoot, context, isUpgrade, operaDetected: false };
281
- }
282
-
283
- function initProject(root, options) {
284
- const normalized = { ...(options || {}) };
285
- normalized.locale = resolveLocale(normalized.locale, runtimeState.getGlobalLocale() || config.DEFAULT_LOCALE);
286
- setLocale(normalized.locale);
287
- if (normalized.legacyLayout) {
288
- return initLegacyProject(root, normalized);
289
- }
290
- return initSplitProject(root, normalized);
291
- }
292
-
293
- async function cmdInit(args) {
294
- const options = parseArgs(args || []);
295
- const explicitLocale = resolveLocale(options.locale, null);
296
- const globalLocale = runtimeState.getGlobalLocale();
297
- if (explicitLocale) {
298
- options.locale = explicitLocale;
299
- } else if (!globalLocale) {
300
- options.locale = await promptForLocale(detectSystemLocale());
301
- } else {
302
- options.locale = globalLocale;
303
- }
304
- if (!globalLocale) {
305
- await runtimeState.ensureGlobalLocale({ preferredLocale: options.locale, interactive: false });
306
- }
307
- setLocale(options.locale || config.DEFAULT_LOCALE);
308
-
309
- const result = initProject(process.cwd(), options);
310
-
311
- if (options.withOpera) {
312
- const opera = require("./opera");
313
- await opera.install(result.root, {
314
- locale: options.locale,
315
- bootstrap: !options.noBootstrap,
316
- bootstrapMode: options.bootstrapMode,
317
- technicalLevel: options.technicalLevel,
318
- projectState: options.projectState,
319
- docsState: options.docsState,
320
- decisionOwnership: options.decisionOwnership,
321
- });
322
- }
323
- }
324
-
325
- module.exports = { initProject, cmdInit, buildDefaultControl };
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { spawnSync } = require("child_process");
6
+
7
+ const config = require("./config");
8
+ const registry = require("./registry");
9
+ const env = require("./env");
10
+ const workspace = require("./workspace");
11
+ const { t, setLocale } = require("./i18n");
12
+ const { detectSystemLocale, promptForLocale, maybePromptForLocale, resolveLocale } = require("./locale");
13
+ const runtimeState = require("./runtime-state");
14
+
15
+ const GENERATED_SCRIPT_COMMANDS = {
16
+ ops: "npx --yes trackops",
17
+ "ops:help": "npx --yes trackops help",
18
+ "ops:dashboard": "npx --yes trackops dashboard",
19
+ "ops:status": "npx --yes trackops status",
20
+ "ops:next": "npx --yes trackops next",
21
+ "ops:sync": "npx --yes trackops sync",
22
+ "ops:repo": "npx --yes trackops refresh-repo",
23
+ };
24
+
25
+ function nowIso() {
26
+ return new Date().toISOString();
27
+ }
28
+
29
+ function parseArgs(args) {
30
+ const options = {
31
+ locale: null,
32
+ name: null,
33
+ withOpera: false,
34
+ phases: null,
35
+ noBootstrap: false,
36
+ legacyLayout: false,
37
+ bootstrapMode: "auto",
38
+ technicalLevel: null,
39
+ projectState: null,
40
+ docsState: null,
41
+ decisionOwnership: null,
42
+ };
43
+ for (let i = 0; i < args.length; i += 1) {
44
+ if (args[i] === "--locale" && args[i + 1]) { options.locale = args[i + 1]; i += 1; }
45
+ else if (args[i] === "--name" && args[i + 1]) { options.name = args[i + 1]; i += 1; }
46
+ else if (args[i] === "--with-opera") { options.withOpera = true; }
47
+ else if (args[i] === "--no-bootstrap") { options.noBootstrap = true; }
48
+ else if (args[i] === "--legacy-layout") { options.legacyLayout = true; }
49
+ else if (args[i] === "--bootstrap-mode" && args[i + 1]) { options.bootstrapMode = args[i + 1]; i += 1; }
50
+ else if (args[i] === "--technical-level" && args[i + 1]) { options.technicalLevel = args[i + 1]; i += 1; }
51
+ else if (args[i] === "--project-state" && args[i + 1]) { options.projectState = args[i + 1]; i += 1; }
52
+ else if (args[i] === "--docs-state" && args[i + 1]) { options.docsState = args[i + 1]; i += 1; }
53
+ else if (args[i] === "--decision-ownership" && args[i + 1]) { options.decisionOwnership = args[i + 1]; i += 1; }
54
+ else if (args[i] === "--phases" && args[i + 1]) {
55
+ try { options.phases = JSON.parse(args[i + 1]); } catch (_e) { /* ignore */ }
56
+ i += 1;
57
+ }
58
+ }
59
+ return options;
60
+ }
61
+
62
+ function detectProjectName(root) {
63
+ const pkgPath = path.join(root, "package.json");
64
+ if (fs.existsSync(pkgPath)) {
65
+ try {
66
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
67
+ return pkg.displayName || pkg.name || path.basename(root);
68
+ } catch (_e) {
69
+ // noop
70
+ }
71
+ }
72
+ return path.basename(root);
73
+ }
74
+
75
+ function buildDefaultControl(context, options) {
76
+ const locale = resolveLocale(options.locale, runtimeState.getGlobalLocale() || config.DEFAULT_LOCALE);
77
+ const phases = options.phases || config.buildDefaultPhases(locale);
78
+ const isSplit = context.layout === "split";
79
+ setLocale(locale);
80
+
81
+ return {
82
+ meta: {
83
+ projectName: options.name || "My Project",
84
+ controlVersion: 2,
85
+ locale,
86
+ phases,
87
+ updatedAt: nowIso(),
88
+ executionSource: "project_control.json",
89
+ currentFocus: t("init.defaultFocus"),
90
+ focusPhase: phases[0]?.id || "O",
91
+ deliveryTarget: t("init.defaultTarget"),
92
+ workspace: isSplit ? {
93
+ layout: "split",
94
+ workspaceRoot: ".",
95
+ appDir: path.basename(context.appRoot),
96
+ opsDir: path.basename(context.opsRoot),
97
+ developmentBranch: context.branches.development,
98
+ publishBranch: context.branches.publish,
99
+ publishMode: context.publish.mode,
100
+ } : undefined,
101
+ environment: {
102
+ rootEnvFile: path.relative(context.workspaceRoot, context.env.rootFile).replace(/\\/g, "/"),
103
+ exampleFile: path.relative(context.workspaceRoot, context.env.exampleFile).replace(/\\/g, "/"),
104
+ appBridgeFile: path.relative(context.workspaceRoot, context.env.appBridgeFile).replace(/\\/g, "/"),
105
+ bridgeMode: isSplit ? "symlink-or-copy" : "none",
106
+ requiredKeys: [],
107
+ optionalKeys: [],
108
+ lastAuditAt: null,
109
+ },
110
+ userProfile: {
111
+ technicalLevel: null,
112
+ explanationMode: null,
113
+ capturedAt: null,
114
+ },
115
+ discovery: {
116
+ projectState: null,
117
+ documentationState: null,
118
+ availableArtifacts: [],
119
+ },
120
+ },
121
+ checks: {
122
+ lastBuild: { status: "pending", date: null, note: "" },
123
+ lastTest: { status: "pending", date: null, note: "" },
124
+ lastReview: { status: "pending", date: null, note: "" },
125
+ },
126
+ rituals: {
127
+ startOfSession: ["trackops status", "trackops next"],
128
+ beforeImplementation: ["trackops task start <task-id>"],
129
+ endOfSession: ["trackops task review|complete|block <task-id> <note>", "trackops sync"],
130
+ beforeCommit: ["trackops status", "trackops sync"],
131
+ },
132
+ milestones: [],
133
+ decisionsPending: [],
134
+ tasks: [
135
+ {
136
+ id: "ops-bootstrap",
137
+ title: t("init.defaultTaskTitle"),
138
+ phase: phases[0]?.id || "O",
139
+ stream: "Operations",
140
+ priority: "P0",
141
+ status: "pending",
142
+ required: true,
143
+ dependsOn: [],
144
+ summary: t("init.defaultTaskSummary"),
145
+ acceptance: [],
146
+ history: [{ at: nowIso(), action: "create", note: "trackops init" }],
147
+ },
148
+ ],
149
+ findings: [],
150
+ };
151
+ }
152
+
153
+ function upsertScripts(root) {
154
+ const pkgPath = path.join(root, "package.json");
155
+ let pkg = {};
156
+ if (fs.existsSync(pkgPath)) {
157
+ try { pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); } catch (_e) { /* ignore */ }
158
+ }
159
+ pkg.scripts = pkg.scripts || {};
160
+ Object.assign(pkg.scripts, GENERATED_SCRIPT_COMMANDS);
161
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
162
+ }
163
+
164
+ function installHooks(context) {
165
+ const hooksDir = context.paths.hooksDir;
166
+ fs.mkdirSync(hooksDir, { recursive: true });
167
+
168
+ const relativeCommand = context.layout === "split"
169
+ ? "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n"
170
+ : "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n";
171
+ const hookContent = `#!/bin/sh\n${relativeCommand}`;
172
+ for (const hookName of ["post-commit", "post-checkout", "post-merge"]) {
173
+ const hookPath = path.join(hooksDir, hookName);
174
+ fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
175
+ }
176
+
177
+ if (fs.existsSync(path.join(context.workspaceRoot, ".git"))) {
178
+ const hooksPath = context.layout === "split" ? "ops/.githooks" : ".githooks";
179
+ spawnSync("git", ["config", "core.hooksPath", hooksPath], { cwd: context.workspaceRoot, encoding: "utf8" });
180
+ }
181
+ }
182
+
183
+ function ensureTmpDir(context) {
184
+ fs.mkdirSync(context.paths.tmpDir, { recursive: true });
185
+ const gitkeep = path.join(context.paths.tmpDir, ".gitkeep");
186
+ if (!fs.existsSync(gitkeep)) {
187
+ fs.writeFileSync(gitkeep, "", "utf8");
188
+ }
189
+ }
190
+
191
+ function ensureSplitLayoutAllowed(targetRoot) {
192
+ const entries = fs.readdirSync(targetRoot, { withFileTypes: true });
193
+ const meaningful = entries.filter((entry) => ![".git"].includes(entry.name));
194
+ if (meaningful.length > 0) {
195
+ throw new Error("Directory is not empty. Run 'trackops workspace migrate' to convert an existing project.");
196
+ }
197
+ }
198
+
199
+ function initSplitProject(root, options) {
200
+ const targetRoot = path.resolve(root);
201
+ fs.mkdirSync(targetRoot, { recursive: true });
202
+ ensureSplitLayoutAllowed(targetRoot);
203
+
204
+ const manifest = workspace.buildManifest();
205
+ const context = config.createSplitContext(targetRoot, manifest);
206
+ fs.mkdirSync(context.appRoot, { recursive: true });
207
+ fs.mkdirSync(context.opsRoot, { recursive: true });
208
+ config.saveWorkspaceManifest(context, manifest);
209
+ workspace.ensureRootGitignore(targetRoot);
210
+
211
+ const control = buildDefaultControl(context, options);
212
+ control.meta.projectName = options.name || detectProjectName(context.workspaceRoot);
213
+ config.saveControl(context, control);
214
+
215
+ installHooks(context);
216
+ ensureTmpDir(context);
217
+ const controlApi = require("./control");
218
+ controlApi.syncDocs(context, control);
219
+ env.syncEnvironment(context, control);
220
+
221
+ try {
222
+ registry.registerProject(context.workspaceRoot);
223
+ } catch (_e) {
224
+ // ignore
225
+ }
226
+
227
+ console.log(t("init.created", { file: ".trackops-workspace.json" }));
228
+ console.log(t("init.created", { file: "ops/project_control.json" }));
229
+ console.log(t("init.created", { file: "ops/.githooks/" }));
230
+ console.log(t("init.created", { file: ".env" }));
231
+ console.log(t("init.created", { file: ".env.example" }));
232
+ console.log("");
233
+ console.log(t("init.welcome"));
234
+
235
+ return { root: context.workspaceRoot, context, isUpgrade: false, operaDetected: false };
236
+ }
237
+
238
+ function initLegacyProject(root, options) {
239
+ const targetRoot = path.resolve(root);
240
+ const context = config.createLegacyContext(targetRoot);
241
+ const controlFile = context.controlFile;
242
+ const isUpgrade = fs.existsSync(controlFile);
243
+ options.locale = resolveLocale(options.locale, detectSystemLocale());
244
+
245
+ if (!options.name) {
246
+ options.name = detectProjectName(targetRoot);
247
+ }
248
+
249
+ if (isUpgrade) {
250
+ const existing = JSON.parse(fs.readFileSync(controlFile, "utf8"));
251
+ if (!existing.meta.phases) existing.meta.phases = options.phases || config.buildDefaultPhases(options.locale);
252
+ if (!existing.meta.locale) existing.meta.locale = options.locale || config.DEFAULT_LOCALE;
253
+ if (!existing.meta.controlVersion || existing.meta.controlVersion < 2) existing.meta.controlVersion = 2;
254
+ existing.meta.updatedAt = nowIso();
255
+ fs.writeFileSync(controlFile, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
256
+ console.log(t("init.updated", { file: "project_control.json" }));
257
+ } else {
258
+ const control = buildDefaultControl(context, options);
259
+ control.meta.projectName = options.name;
260
+ fs.writeFileSync(controlFile, `${JSON.stringify(control, null, 2)}\n`, "utf8");
261
+ console.log(t("init.created", { file: "project_control.json" }));
262
+ }
263
+
264
+ upsertScripts(targetRoot);
265
+ console.log(t("init.updated", { file: "package.json" }));
266
+
267
+ installHooks(context);
268
+ console.log(t("init.created", { file: ".githooks/" }));
269
+ ensureTmpDir(context);
270
+
271
+ try {
272
+ registry.registerProject(targetRoot);
273
+ console.log(t("init.registered"));
274
+ } catch (_e) {
275
+ // ignore
276
+ }
277
+
278
+ console.log("");
279
+ console.log(t("init.welcome"));
280
+ return { root: targetRoot, context, isUpgrade, operaDetected: false };
281
+ }
282
+
283
+ function initProject(root, options) {
284
+ const normalized = { ...(options || {}) };
285
+ normalized.locale = resolveLocale(normalized.locale, runtimeState.getGlobalLocale() || config.DEFAULT_LOCALE);
286
+ setLocale(normalized.locale);
287
+ if (normalized.legacyLayout) {
288
+ return initLegacyProject(root, normalized);
289
+ }
290
+ return initSplitProject(root, normalized);
291
+ }
292
+
293
+ async function cmdInit(args) {
294
+ const options = parseArgs(args || []);
295
+ const explicitLocale = resolveLocale(options.locale, null);
296
+ const globalLocale = runtimeState.getGlobalLocale();
297
+ if (explicitLocale) {
298
+ options.locale = explicitLocale;
299
+ } else if (!globalLocale) {
300
+ options.locale = await promptForLocale(detectSystemLocale());
301
+ } else {
302
+ options.locale = await maybePromptForLocale(globalLocale, { promptMode: "always" });
303
+ }
304
+ if (!globalLocale) {
305
+ await runtimeState.ensureGlobalLocale({ preferredLocale: options.locale, interactive: false });
306
+ }
307
+ setLocale(options.locale || config.DEFAULT_LOCALE);
308
+
309
+ const result = initProject(process.cwd(), options);
310
+
311
+ if (options.withOpera) {
312
+ const opera = require("./opera");
313
+ await opera.install(result.root, {
314
+ locale: options.locale,
315
+ bootstrap: !options.noBootstrap,
316
+ bootstrapMode: options.bootstrapMode,
317
+ technicalLevel: options.technicalLevel,
318
+ projectState: options.projectState,
319
+ docsState: options.docsState,
320
+ decisionOwnership: options.decisionOwnership,
321
+ });
322
+ }
323
+ }
324
+
325
+ module.exports = { initProject, cmdInit, buildDefaultControl };