trackops 1.0.0 → 1.1.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 (72) hide show
  1. package/README.md +341 -232
  2. package/bin/trackops.js +102 -70
  3. package/lib/config.js +260 -35
  4. package/lib/control.js +518 -475
  5. package/lib/env.js +227 -0
  6. package/lib/i18n.js +61 -53
  7. package/lib/init.js +146 -55
  8. package/lib/locale.js +63 -0
  9. package/lib/opera-bootstrap.js +523 -0
  10. package/lib/opera.js +319 -170
  11. package/lib/registry.js +27 -13
  12. package/lib/release.js +56 -0
  13. package/lib/resources.js +42 -0
  14. package/lib/server.js +912 -418
  15. package/lib/skills.js +148 -124
  16. package/lib/workspace.js +260 -0
  17. package/locales/en.json +331 -139
  18. package/locales/es.json +331 -139
  19. package/package.json +14 -3
  20. package/scripts/skills-marketplace-smoke.js +124 -0
  21. package/scripts/smoke-tests.js +445 -0
  22. package/scripts/sync-skill-version.js +21 -0
  23. package/scripts/validate-skill.js +88 -0
  24. package/skills/trackops/SKILL.md +64 -0
  25. package/skills/trackops/agents/openai.yaml +3 -0
  26. package/skills/trackops/references/activation.md +39 -0
  27. package/skills/trackops/references/troubleshooting.md +34 -0
  28. package/skills/trackops/references/workflow.md +20 -0
  29. package/skills/trackops/scripts/bootstrap-trackops.js +201 -0
  30. package/skills/trackops/skill.json +29 -0
  31. package/templates/etapa/agent.md +2 -2
  32. package/templates/etapa/references/etapa-cycle.md +1 -1
  33. package/templates/opera/agent.md +1 -1
  34. package/templates/opera/en/agent.md +26 -0
  35. package/templates/opera/en/genesis.md +79 -0
  36. package/templates/opera/en/references/autonomy-and-recovery.md +23 -0
  37. package/templates/opera/en/references/opera-cycle.md +62 -0
  38. package/templates/opera/en/registry.md +28 -0
  39. package/templates/opera/en/router.md +39 -0
  40. package/templates/opera/genesis.md +79 -94
  41. package/templates/skills/changelog-updater/locales/en/SKILL.md +11 -0
  42. package/templates/skills/commiter/locales/en/SKILL.md +11 -0
  43. package/templates/skills/project-starter-skill/SKILL.md +5 -3
  44. package/templates/skills/project-starter-skill/locales/en/SKILL.md +24 -0
  45. package/ui/css/base.css +266 -0
  46. package/ui/css/charts.css +327 -0
  47. package/ui/css/components.css +570 -0
  48. package/ui/css/panels.css +956 -0
  49. package/ui/css/tokens.css +227 -0
  50. package/ui/favicon.svg +5 -0
  51. package/ui/index.html +91 -351
  52. package/ui/js/api.js +220 -0
  53. package/ui/js/app.js +200 -0
  54. package/ui/js/console-logger.js +172 -0
  55. package/ui/js/i18n.js +14 -0
  56. package/ui/js/icons.js +104 -0
  57. package/ui/js/onboarding.js +439 -0
  58. package/ui/js/router.js +125 -0
  59. package/ui/js/state.js +130 -0
  60. package/ui/js/theme.js +100 -0
  61. package/ui/js/time-tracker.js +248 -0
  62. package/ui/js/utils.js +175 -0
  63. package/ui/js/views/board.js +255 -0
  64. package/ui/js/views/execution.js +256 -0
  65. package/ui/js/views/flash.js +47 -0
  66. package/ui/js/views/insights.js +340 -0
  67. package/ui/js/views/overview.js +365 -0
  68. package/ui/js/views/settings.js +381 -0
  69. package/ui/js/views/sidebar.js +131 -0
  70. package/ui/js/views/skills.js +163 -0
  71. package/ui/js/views/tasks.js +406 -0
  72. package/ui/js/views/topbar.js +239 -0
package/lib/env.js ADDED
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const config = require("./config");
6
+
7
+ const SERVICE_ENV_KEYS = {
8
+ OpenAI: ["OPENAI_API_KEY"],
9
+ Anthropic: ["ANTHROPIC_API_KEY"],
10
+ Stripe: ["STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET"],
11
+ Supabase: ["SUPABASE_URL", "SUPABASE_ANON_KEY", "SUPABASE_SERVICE_ROLE_KEY"],
12
+ PostgreSQL: ["DATABASE_URL"],
13
+ MySQL: ["DATABASE_URL"],
14
+ Redis: ["REDIS_URL"],
15
+ Slack: ["SLACK_BOT_TOKEN", "SLACK_SIGNING_SECRET"],
16
+ "Amazon S3": ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_REGION", "AWS_S3_BUCKET"],
17
+ AWS: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_REGION"],
18
+ "Google Cloud": ["GOOGLE_APPLICATION_CREDENTIALS"],
19
+ Azure: ["AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT"],
20
+ };
21
+
22
+ function unique(items) {
23
+ return [...new Set((items || []).map((item) => String(item || "").trim()).filter(Boolean))];
24
+ }
25
+
26
+ function readText(filePath) {
27
+ return fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
28
+ }
29
+
30
+ function parseEnv(text) {
31
+ const entries = {};
32
+ const lines = String(text || "").split(/\r?\n/);
33
+ for (const line of lines) {
34
+ if (!line || /^\s*#/.test(line)) continue;
35
+ const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
36
+ if (!match) continue;
37
+ entries[match[1]] = match[2] || "";
38
+ }
39
+ return entries;
40
+ }
41
+
42
+ function parseEnvKeys(text) {
43
+ return unique(Object.keys(parseEnv(text)));
44
+ }
45
+
46
+ function normalizeEnvironmentMeta(control, context) {
47
+ const envMeta = control.meta?.environment || {};
48
+ return {
49
+ rootEnvFile: envMeta.rootEnvFile || path.relative(context.workspaceRoot, context.env.rootFile).replace(/\\/g, "/"),
50
+ exampleFile: envMeta.exampleFile || path.relative(context.workspaceRoot, context.env.exampleFile).replace(/\\/g, "/"),
51
+ appBridgeFile: envMeta.appBridgeFile || path.relative(context.workspaceRoot, context.env.appBridgeFile).replace(/\\/g, "/"),
52
+ bridgeMode: envMeta.bridgeMode || (context.layout === "split" ? "symlink-or-copy" : "none"),
53
+ requiredKeys: unique(envMeta.requiredKeys),
54
+ optionalKeys: unique(envMeta.optionalKeys),
55
+ lastAuditAt: envMeta.lastAuditAt || null,
56
+ };
57
+ }
58
+
59
+ function inferRequiredKeys(control, contextOrRoot) {
60
+ const envMeta = control.meta?.environment || {};
61
+ const fromMeta = unique([...(envMeta.requiredKeys || []), ...(envMeta.optionalKeys || [])]);
62
+ const fromServices = unique(
63
+ (control.meta?.opera?.bootstrap?.discovery?.externalServices || [])
64
+ .flatMap((service) => SERVICE_ENV_KEYS[service] || []),
65
+ );
66
+ const context = config.ensureContext(contextOrRoot || process.cwd());
67
+ const fromExample = parseEnvKeys(readText(context.env.exampleFile));
68
+ return unique([...fromMeta, ...fromServices, ...fromExample]);
69
+ }
70
+
71
+ function ensureFileWithHeader(filePath, lines) {
72
+ if (fs.existsSync(filePath)) return;
73
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
74
+ fs.writeFileSync(filePath, `${lines.join("\n")}\n`, "utf8");
75
+ }
76
+
77
+ function appendMissingKeys(filePath, keys, heading) {
78
+ const existing = readText(filePath);
79
+ const parsed = parseEnvKeys(existing);
80
+ const missing = unique(keys).filter((key) => !parsed.includes(key));
81
+ if (!missing.length) return;
82
+
83
+ const chunks = [];
84
+ if (existing.trim()) chunks.push("");
85
+ if (heading) chunks.push(heading);
86
+ missing.forEach((key) => chunks.push(`${key}=`));
87
+ fs.appendFileSync(filePath, `${chunks.join("\n")}\n`, "utf8");
88
+ }
89
+
90
+ function safeUnlink(filePath) {
91
+ try {
92
+ fs.rmSync(filePath, { force: true });
93
+ } catch (_error) {
94
+ // noop
95
+ }
96
+ }
97
+
98
+ function ensureBridge(context, control) {
99
+ const envMeta = normalizeEnvironmentMeta(control, context);
100
+ const bridgePath = context.env.appBridgeFile;
101
+ const exampleBridgePath = context.env.appExampleBridgeFile;
102
+ const sourceEnv = context.env.rootFile;
103
+ const sourceExample = context.env.exampleFile;
104
+
105
+ if (context.layout !== "split") {
106
+ control.meta.environment = { ...envMeta, bridgeMode: "none" };
107
+ return "none";
108
+ }
109
+
110
+ fs.mkdirSync(path.dirname(bridgePath), { recursive: true });
111
+
112
+ let mode = "copy";
113
+ safeUnlink(bridgePath);
114
+ try {
115
+ fs.symlinkSync(path.relative(path.dirname(bridgePath), sourceEnv), bridgePath, "file");
116
+ mode = "symlink";
117
+ } catch (_error) {
118
+ fs.copyFileSync(sourceEnv, bridgePath);
119
+ }
120
+
121
+ safeUnlink(exampleBridgePath);
122
+ try {
123
+ fs.symlinkSync(path.relative(path.dirname(exampleBridgePath), sourceExample), exampleBridgePath, "file");
124
+ } catch (_error) {
125
+ fs.copyFileSync(sourceExample, exampleBridgePath);
126
+ }
127
+
128
+ control.meta.environment = {
129
+ ...envMeta,
130
+ bridgeMode: mode,
131
+ };
132
+ return mode;
133
+ }
134
+
135
+ function syncEnvironment(contextOrRoot, controlState, options = {}) {
136
+ const context = config.ensureContext(contextOrRoot);
137
+ const control = controlState || config.loadControl(context);
138
+ control.meta = control.meta || {};
139
+ control.meta.environment = normalizeEnvironmentMeta(control, context);
140
+
141
+ const requiredKeys = unique(options.requiredKeys || inferRequiredKeys(control, context));
142
+ const optionalKeys = unique(options.optionalKeys || control.meta.environment.optionalKeys);
143
+
144
+ ensureFileWithHeader(context.env.rootFile, [
145
+ "# TrackOps workspace secrets",
146
+ "# Do not commit this file.",
147
+ ]);
148
+ ensureFileWithHeader(context.env.exampleFile, [
149
+ "# TrackOps workspace environment contract",
150
+ "# Safe to commit. Keep only keys, never real values.",
151
+ ]);
152
+
153
+ appendMissingKeys(context.env.rootFile, requiredKeys, "# Required keys");
154
+ appendMissingKeys(context.env.exampleFile, requiredKeys, "# Required keys");
155
+ appendMissingKeys(context.env.exampleFile, optionalKeys, "# Optional keys");
156
+
157
+ const bridgeMode = ensureBridge(context, control);
158
+ control.meta.environment = {
159
+ ...control.meta.environment,
160
+ requiredKeys,
161
+ optionalKeys,
162
+ bridgeMode,
163
+ lastAuditAt: new Date().toISOString(),
164
+ };
165
+
166
+ config.saveControl(context, control);
167
+ return auditEnvironment(context, control);
168
+ }
169
+
170
+ function auditEnvironment(contextOrRoot, controlState) {
171
+ const context = config.ensureContext(contextOrRoot);
172
+ const control = controlState || config.loadControl(context);
173
+ const envMeta = normalizeEnvironmentMeta(control, context);
174
+ const requiredKeys = unique(envMeta.requiredKeys.length ? envMeta.requiredKeys : inferRequiredKeys(control, context));
175
+ const envEntries = parseEnv(readText(context.env.rootFile));
176
+ const presentKeys = requiredKeys.filter((key) => String(envEntries[key] || "").trim());
177
+ const missingKeys = requiredKeys.filter((key) => !String(envEntries[key] || "").trim());
178
+
179
+ return {
180
+ ok: true,
181
+ files: {
182
+ rootEnv: context.env.rootFile,
183
+ rootExample: context.env.exampleFile,
184
+ appBridge: context.env.appBridgeFile,
185
+ },
186
+ bridgeMode: envMeta.bridgeMode,
187
+ requiredKeys,
188
+ optionalKeys: envMeta.optionalKeys,
189
+ presentKeys,
190
+ missingKeys,
191
+ lastAuditAt: envMeta.lastAuditAt,
192
+ };
193
+ }
194
+
195
+ function cmdStatus(contextOrRoot) {
196
+ const audit = auditEnvironment(contextOrRoot);
197
+ console.log("Environment:");
198
+ console.log(` Root .env: ${audit.files.rootEnv}`);
199
+ console.log(` Example: ${audit.files.rootExample}`);
200
+ console.log(` App bridge: ${audit.files.appBridge}`);
201
+ console.log(` Bridge mode: ${audit.bridgeMode}`);
202
+ console.log(` Required keys: ${audit.requiredKeys.length ? audit.requiredKeys.join(", ") : "none"}`);
203
+ console.log(` Present: ${audit.presentKeys.length ? audit.presentKeys.join(", ") : "none"}`);
204
+ console.log(` Missing: ${audit.missingKeys.length ? audit.missingKeys.join(", ") : "none"}`);
205
+ }
206
+
207
+ function cmdSync(contextOrRoot) {
208
+ const context = config.ensureContext(contextOrRoot);
209
+ const control = config.loadControl(context);
210
+ const audit = syncEnvironment(context, control);
211
+ console.log(`Environment synced at ${path.relative(context.workspaceRoot, context.env.rootFile)}`);
212
+ if (audit.missingKeys.length) {
213
+ console.log(`Missing required keys: ${audit.missingKeys.join(", ")}`);
214
+ }
215
+ }
216
+
217
+ module.exports = {
218
+ SERVICE_ENV_KEYS,
219
+ parseEnv,
220
+ parseEnvKeys,
221
+ normalizeEnvironmentMeta,
222
+ inferRequiredKeys,
223
+ syncEnvironment,
224
+ auditEnvironment,
225
+ cmdStatus,
226
+ cmdSync,
227
+ };
package/lib/i18n.js CHANGED
@@ -1,53 +1,61 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require("path");
4
-
5
- const LOCALES_DIR = path.join(__dirname, "..", "locales");
6
-
7
- let currentLocale = "es";
8
- let currentMessages = null;
9
- let fallbackMessages = null;
10
-
11
- function loadMessages(localeId) {
12
- try {
13
- return require(path.join(LOCALES_DIR, `${localeId}.json`));
14
- } catch (_error) {
15
- return null;
16
- }
17
- }
18
-
19
- function ensureLoaded() {
20
- if (currentMessages) return;
21
- currentMessages = loadMessages(currentLocale) || {};
22
- if (currentLocale !== "es") {
23
- fallbackMessages = loadMessages("es") || {};
24
- } else {
25
- fallbackMessages = currentMessages;
26
- }
27
- }
28
-
29
- function setLocale(localeId) {
30
- currentLocale = localeId || "es";
31
- currentMessages = null;
32
- fallbackMessages = null;
33
- }
34
-
35
- function getLocale() {
36
- return currentLocale;
37
- }
38
-
39
- function t(key, params) {
40
- ensureLoaded();
41
- let message =
42
- currentMessages[key] ||
43
- (fallbackMessages && fallbackMessages[key]) ||
44
- key;
45
- if (params) {
46
- message = message.replace(/\{(\w+)\}/g, (match, paramKey) =>
47
- params[paramKey] !== undefined ? String(params[paramKey]) : match
48
- );
49
- }
50
- return message;
51
- }
52
-
53
- module.exports = { setLocale, getLocale, t };
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+
5
+ const LOCALES_DIR = path.join(__dirname, "..", "locales");
6
+
7
+ let currentLocale = "es";
8
+ let currentMessages = null;
9
+ let fallbackMessages = null;
10
+
11
+ function loadMessages(localeId) {
12
+ try {
13
+ return require(path.join(LOCALES_DIR, `${localeId}.json`));
14
+ } catch (_error) {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ function ensureLoaded() {
20
+ if (currentMessages) return;
21
+ currentMessages = loadMessages(currentLocale) || {};
22
+ if (currentLocale !== "es") {
23
+ fallbackMessages = loadMessages("es") || {};
24
+ } else {
25
+ fallbackMessages = currentMessages;
26
+ }
27
+ }
28
+
29
+ function setLocale(localeId) {
30
+ currentLocale = localeId || "es";
31
+ currentMessages = null;
32
+ fallbackMessages = null;
33
+ }
34
+
35
+ function getLocale() {
36
+ return currentLocale;
37
+ }
38
+
39
+ function t(key, params) {
40
+ ensureLoaded();
41
+ let message =
42
+ currentMessages[key] ||
43
+ (fallbackMessages && fallbackMessages[key]) ||
44
+ key;
45
+ if (params) {
46
+ message = message.replace(/\{(\w+)\}/g, (match, paramKey) =>
47
+ params[paramKey] !== undefined ? String(params[paramKey]) : match
48
+ );
49
+ }
50
+ return message;
51
+ }
52
+
53
+ function getMessages(localeId) {
54
+ const locale = localeId || currentLocale || "es";
55
+ return {
56
+ ...(locale !== "es" ? (loadMessages("es") || {}) : {}),
57
+ ...(loadMessages(locale) || {}),
58
+ };
59
+ }
60
+
61
+ module.exports = { setLocale, getLocale, t, getMessages };
package/lib/init.js CHANGED
@@ -4,20 +4,42 @@ const fs = require("fs");
4
4
  const path = require("path");
5
5
  const { spawnSync } = require("child_process");
6
6
 
7
- const { DEFAULT_PHASES, DEFAULT_LOCALE } = require("./config");
7
+ const config = require("./config");
8
8
  const registry = require("./registry");
9
+ const env = require("./env");
10
+ const workspace = require("./workspace");
9
11
  const { t, setLocale } = require("./i18n");
12
+ const { detectSystemLocale, promptForLocale, resolveLocale } = require("./locale");
13
+
14
+ const GENERATED_SCRIPT_COMMANDS = {
15
+ ops: "npx --yes trackops",
16
+ "ops:help": "npx --yes trackops help",
17
+ "ops:dashboard": "npx --yes trackops dashboard",
18
+ "ops:status": "npx --yes trackops status",
19
+ "ops:next": "npx --yes trackops next",
20
+ "ops:sync": "npx --yes trackops sync",
21
+ "ops:repo": "npx --yes trackops refresh-repo",
22
+ };
10
23
 
11
24
  function nowIso() {
12
25
  return new Date().toISOString();
13
26
  }
14
27
 
15
28
  function parseArgs(args) {
16
- const options = { locale: null, name: null, withOpera: false, phases: null };
29
+ const options = {
30
+ locale: null,
31
+ name: null,
32
+ withOpera: false,
33
+ phases: null,
34
+ noBootstrap: false,
35
+ legacyLayout: false,
36
+ };
17
37
  for (let i = 0; i < args.length; i += 1) {
18
38
  if (args[i] === "--locale" && args[i + 1]) { options.locale = args[i + 1]; i += 1; }
19
39
  else if (args[i] === "--name" && args[i + 1]) { options.name = args[i + 1]; i += 1; }
20
40
  else if (args[i] === "--with-opera" || args[i] === "--with-etapa") { options.withOpera = true; }
41
+ else if (args[i] === "--no-bootstrap") { options.noBootstrap = true; }
42
+ else if (args[i] === "--legacy-layout") { options.legacyLayout = true; }
21
43
  else if (args[i] === "--phases" && args[i + 1]) {
22
44
  try { options.phases = JSON.parse(args[i + 1]); } catch (_e) { /* ignore */ }
23
45
  i += 1;
@@ -32,20 +54,17 @@ function detectProjectName(root) {
32
54
  try {
33
55
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
34
56
  return pkg.displayName || pkg.name || path.basename(root);
35
- } catch (_e) { /* ignore */ }
57
+ } catch (_e) {
58
+ // noop
59
+ }
36
60
  }
37
61
  return path.basename(root);
38
62
  }
39
63
 
40
- function hasExistingOpera(root) {
41
- return (
42
- fs.existsSync(path.join(root, ".agent", "hub")) ||
43
- fs.existsSync(path.join(root, ".agents", "skills"))
44
- );
45
- }
46
-
47
- function buildDefaultControl(options) {
48
- const locale = options.locale || DEFAULT_LOCALE;
64
+ function buildDefaultControl(context, options) {
65
+ const locale = resolveLocale(options.locale, config.DEFAULT_LOCALE);
66
+ const phases = options.phases || config.buildDefaultPhases(locale);
67
+ const isSplit = context.layout === "split";
49
68
  setLocale(locale);
50
69
 
51
70
  return {
@@ -53,12 +72,30 @@ function buildDefaultControl(options) {
53
72
  projectName: options.name || "My Project",
54
73
  controlVersion: 2,
55
74
  locale,
56
- phases: options.phases || DEFAULT_PHASES,
75
+ phases,
57
76
  updatedAt: nowIso(),
58
77
  executionSource: "project_control.json",
59
78
  currentFocus: t("init.defaultFocus"),
60
- focusPhase: (options.phases || DEFAULT_PHASES)[0]?.id || "E",
79
+ focusPhase: phases[0]?.id || "O",
61
80
  deliveryTarget: t("init.defaultTarget"),
81
+ workspace: isSplit ? {
82
+ layout: "split",
83
+ workspaceRoot: ".",
84
+ appDir: path.basename(context.appRoot),
85
+ opsDir: path.basename(context.opsRoot),
86
+ developmentBranch: context.branches.development,
87
+ publishBranch: context.branches.publish,
88
+ publishMode: context.publish.mode,
89
+ } : undefined,
90
+ environment: {
91
+ rootEnvFile: path.relative(context.workspaceRoot, context.env.rootFile).replace(/\\/g, "/"),
92
+ exampleFile: path.relative(context.workspaceRoot, context.env.exampleFile).replace(/\\/g, "/"),
93
+ appBridgeFile: path.relative(context.workspaceRoot, context.env.appBridgeFile).replace(/\\/g, "/"),
94
+ bridgeMode: isSplit ? "symlink-or-copy" : "none",
95
+ requiredKeys: [],
96
+ optionalKeys: [],
97
+ lastAuditAt: null,
98
+ },
62
99
  },
63
100
  checks: {
64
101
  lastBuild: { status: "pending", date: null, note: "" },
@@ -77,7 +114,7 @@ function buildDefaultControl(options) {
77
114
  {
78
115
  id: "ops-bootstrap",
79
116
  title: t("init.defaultTaskTitle"),
80
- phase: (options.phases || DEFAULT_PHASES)[0]?.id || "E",
117
+ phase: phases[0]?.id || "O",
81
118
  stream: "Operations",
82
119
  priority: "P0",
83
120
  status: "pending",
@@ -99,62 +136,106 @@ function upsertScripts(root) {
99
136
  try { pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); } catch (_e) { /* ignore */ }
100
137
  }
101
138
  pkg.scripts = pkg.scripts || {};
102
- Object.assign(pkg.scripts, {
103
- ops: "trackops",
104
- "ops:help": "trackops help",
105
- "ops:dashboard": "trackops dashboard",
106
- "ops:status": "trackops status",
107
- "ops:next": "trackops next",
108
- "ops:sync": "trackops sync",
109
- "ops:repo": "trackops refresh-repo",
110
- });
139
+ Object.assign(pkg.scripts, GENERATED_SCRIPT_COMMANDS);
111
140
  fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
112
141
  }
113
142
 
114
- function installHooks(root) {
115
- const hooksDir = path.join(root, ".githooks");
143
+ function installHooks(context) {
144
+ const hooksDir = context.paths.hooksDir;
116
145
  fs.mkdirSync(hooksDir, { recursive: true });
117
146
 
118
- const hookContent = "#!/bin/sh\nnpx trackops refresh-repo --quiet >/dev/null 2>&1 || true\n";
147
+ const relativeCommand = context.layout === "split"
148
+ ? "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n"
149
+ : "npx --yes trackops refresh-repo --quiet >/dev/null 2>&1 || true\n";
150
+ const hookContent = `#!/bin/sh\n${relativeCommand}`;
119
151
  for (const hookName of ["post-commit", "post-checkout", "post-merge"]) {
120
152
  const hookPath = path.join(hooksDir, hookName);
121
153
  fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
122
154
  }
123
155
 
124
- if (fs.existsSync(path.join(root, ".git"))) {
125
- spawnSync("git", ["config", "core.hooksPath", ".githooks"], { cwd: root, encoding: "utf8" });
156
+ if (fs.existsSync(path.join(context.workspaceRoot, ".git"))) {
157
+ const hooksPath = context.layout === "split" ? "ops/.githooks" : ".githooks";
158
+ spawnSync("git", ["config", "core.hooksPath", hooksPath], { cwd: context.workspaceRoot, encoding: "utf8" });
126
159
  }
127
160
  }
128
161
 
129
- function ensureTmpDir(root) {
130
- const tmpDir = path.join(root, ".tmp");
131
- fs.mkdirSync(tmpDir, { recursive: true });
132
- const gitkeep = path.join(tmpDir, ".gitkeep");
162
+ function ensureTmpDir(context) {
163
+ fs.mkdirSync(context.paths.tmpDir, { recursive: true });
164
+ const gitkeep = path.join(context.paths.tmpDir, ".gitkeep");
133
165
  if (!fs.existsSync(gitkeep)) {
134
166
  fs.writeFileSync(gitkeep, "", "utf8");
135
167
  }
136
168
  }
137
169
 
138
- function initProject(root, options) {
170
+ function ensureSplitLayoutAllowed(targetRoot) {
171
+ const entries = fs.readdirSync(targetRoot, { withFileTypes: true });
172
+ const meaningful = entries.filter((entry) => ![".git"].includes(entry.name));
173
+ if (meaningful.length > 0) {
174
+ throw new Error("Directory is not empty. Run 'trackops workspace migrate' to convert an existing project.");
175
+ }
176
+ }
177
+
178
+ function initSplitProject(root, options) {
179
+ const targetRoot = path.resolve(root);
180
+ fs.mkdirSync(targetRoot, { recursive: true });
181
+ ensureSplitLayoutAllowed(targetRoot);
182
+
183
+ const manifest = workspace.buildManifest();
184
+ const context = config.createSplitContext(targetRoot, manifest);
185
+ fs.mkdirSync(context.appRoot, { recursive: true });
186
+ fs.mkdirSync(context.opsRoot, { recursive: true });
187
+ config.saveWorkspaceManifest(context, manifest);
188
+ workspace.ensureRootGitignore(targetRoot);
189
+
190
+ const control = buildDefaultControl(context, options);
191
+ control.meta.projectName = options.name || detectProjectName(context.appRoot);
192
+ config.saveControl(context, control);
193
+
194
+ installHooks(context);
195
+ ensureTmpDir(context);
196
+ const controlApi = require("./control");
197
+ controlApi.syncDocs(context, control);
198
+ env.syncEnvironment(context, control);
199
+
200
+ try {
201
+ registry.registerProject(context.workspaceRoot);
202
+ } catch (_e) {
203
+ // ignore
204
+ }
205
+
206
+ console.log(t("init.created", { file: ".trackops-workspace.json" }));
207
+ console.log(t("init.created", { file: "ops/project_control.json" }));
208
+ console.log(t("init.created", { file: "ops/.githooks/" }));
209
+ console.log(t("init.created", { file: ".env" }));
210
+ console.log(t("init.created", { file: ".env.example" }));
211
+ console.log("");
212
+ console.log(t("init.welcome"));
213
+
214
+ return { root: context.workspaceRoot, context, isUpgrade: false, operaDetected: false };
215
+ }
216
+
217
+ function initLegacyProject(root, options) {
139
218
  const targetRoot = path.resolve(root);
140
- const controlFile = path.join(targetRoot, "project_control.json");
219
+ const context = config.createLegacyContext(targetRoot);
220
+ const controlFile = context.controlFile;
141
221
  const isUpgrade = fs.existsSync(controlFile);
222
+ options.locale = resolveLocale(options.locale, detectSystemLocale());
142
223
 
143
224
  if (!options.name) {
144
225
  options.name = detectProjectName(targetRoot);
145
226
  }
146
227
 
147
228
  if (isUpgrade) {
148
- // Upgrade: add new meta fields if missing
149
229
  const existing = JSON.parse(fs.readFileSync(controlFile, "utf8"));
150
- if (!existing.meta.phases) existing.meta.phases = options.phases || DEFAULT_PHASES;
151
- if (!existing.meta.locale) existing.meta.locale = options.locale || DEFAULT_LOCALE;
230
+ if (!existing.meta.phases) existing.meta.phases = options.phases || config.buildDefaultPhases(options.locale);
231
+ if (!existing.meta.locale) existing.meta.locale = options.locale || config.DEFAULT_LOCALE;
152
232
  if (!existing.meta.controlVersion || existing.meta.controlVersion < 2) existing.meta.controlVersion = 2;
153
233
  existing.meta.updatedAt = nowIso();
154
234
  fs.writeFileSync(controlFile, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
155
235
  console.log(t("init.updated", { file: "project_control.json" }));
156
236
  } else {
157
- const control = buildDefaultControl(options);
237
+ const control = buildDefaultControl(context, options);
238
+ control.meta.projectName = options.name;
158
239
  fs.writeFileSync(controlFile, `${JSON.stringify(control, null, 2)}\n`, "utf8");
159
240
  console.log(t("init.created", { file: "project_control.json" }));
160
241
  }
@@ -162,38 +243,48 @@ function initProject(root, options) {
162
243
  upsertScripts(targetRoot);
163
244
  console.log(t("init.updated", { file: "package.json" }));
164
245
 
165
- installHooks(targetRoot);
246
+ installHooks(context);
166
247
  console.log(t("init.created", { file: ".githooks/" }));
167
-
168
- ensureTmpDir(targetRoot);
248
+ ensureTmpDir(context);
169
249
 
170
250
  try {
171
251
  registry.registerProject(targetRoot);
172
252
  console.log(t("init.registered"));
173
- } catch (_e) { /* ignore */ }
174
-
175
- const operaDetected = hasExistingOpera(targetRoot);
253
+ } catch (_e) {
254
+ // ignore
255
+ }
176
256
 
177
257
  console.log("");
178
258
  console.log(t("init.welcome"));
259
+ return { root: targetRoot, context, isUpgrade, operaDetected: false };
260
+ }
179
261
 
180
- return { root: targetRoot, isUpgrade, operaDetected };
262
+ function initProject(root, options) {
263
+ const normalized = { ...(options || {}) };
264
+ normalized.locale = resolveLocale(normalized.locale, config.DEFAULT_LOCALE);
265
+ setLocale(normalized.locale);
266
+ if (normalized.legacyLayout) {
267
+ return initLegacyProject(root, normalized);
268
+ }
269
+ return initSplitProject(root, normalized);
181
270
  }
182
271
 
183
- function cmdInit(args) {
272
+ async function cmdInit(args) {
184
273
  const options = parseArgs(args || []);
185
- const root = process.cwd();
186
- setLocale(options.locale || DEFAULT_LOCALE);
274
+ options.locale = resolveLocale(options.locale, null);
275
+ if (!options.locale) {
276
+ options.locale = await promptForLocale(detectSystemLocale());
277
+ }
278
+ setLocale(options.locale || config.DEFAULT_LOCALE);
187
279
 
188
- const result = initProject(root, options);
280
+ const result = initProject(process.cwd(), options);
189
281
 
190
282
  if (options.withOpera) {
191
283
  const opera = require("./opera");
192
- opera.install(root, {});
193
- } else if (result.operaDetected) {
194
- console.log("");
195
- console.log(t("opera.primitiveDetected"));
196
- console.log(" Run 'trackops opera install' to upgrade to managed OPERA.");
284
+ await opera.install(result.root, {
285
+ locale: options.locale,
286
+ bootstrap: !options.noBootstrap,
287
+ });
197
288
  }
198
289
  }
199
290