trackops 1.0.1 → 2.0.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.
- package/README.md +292 -272
- package/bin/trackops.js +108 -50
- package/lib/config.js +267 -38
- package/lib/control.js +534 -480
- package/lib/env.js +244 -0
- package/lib/i18n.js +61 -53
- package/lib/init.js +170 -47
- package/lib/locale.js +63 -0
- package/lib/opera-bootstrap.js +1075 -0
- package/lib/opera.js +524 -125
- package/lib/preferences.js +74 -0
- package/lib/registry.js +27 -13
- package/lib/release.js +56 -0
- package/lib/resources.js +42 -0
- package/lib/runtime-state.js +144 -0
- package/lib/server.js +1004 -521
- package/lib/skills.js +148 -124
- package/lib/workspace.js +260 -0
- package/locales/en.json +418 -132
- package/locales/es.json +418 -132
- package/package.json +8 -9
- package/scripts/postinstall-locale.js +21 -0
- package/scripts/skills-marketplace-smoke.js +124 -0
- package/scripts/smoke-tests.js +570 -0
- package/scripts/sync-skill-version.js +21 -0
- package/scripts/validate-skill.js +89 -0
- package/skills/trackops/SKILL.md +89 -0
- package/skills/trackops/agents/openai.yaml +3 -0
- package/skills/trackops/references/activation.md +73 -0
- package/skills/trackops/references/troubleshooting.md +49 -0
- package/skills/trackops/references/workflow.md +26 -0
- package/skills/trackops/scripts/bootstrap-trackops.js +203 -0
- package/skills/trackops/skill.json +29 -0
- package/templates/opera/agent.md +10 -9
- package/templates/opera/architecture/dependency-graph.md +24 -0
- package/templates/opera/architecture/runtime-automation.md +24 -0
- package/templates/opera/architecture/runtime-operations.md +34 -0
- package/templates/opera/en/agent.md +27 -0
- package/templates/opera/en/architecture/dependency-graph.md +24 -0
- package/templates/opera/en/architecture/runtime-automation.md +24 -0
- package/templates/opera/en/architecture/runtime-operations.md +34 -0
- package/templates/opera/en/genesis.md +79 -0
- package/templates/opera/en/references/autonomy-and-recovery.md +23 -0
- package/templates/opera/en/references/opera-cycle.md +62 -0
- package/templates/opera/en/registry.md +28 -0
- package/templates/opera/en/reviews/delivery-audit.md +18 -0
- package/templates/opera/en/reviews/integration-audit.md +18 -0
- package/templates/opera/en/router.md +49 -0
- package/templates/opera/genesis.md +79 -94
- package/templates/opera/reviews/delivery-audit.md +18 -0
- package/templates/opera/reviews/integration-audit.md +18 -0
- package/templates/opera/router.md +15 -5
- package/templates/skills/changelog-updater/locales/en/SKILL.md +11 -0
- package/templates/skills/commiter/locales/en/SKILL.md +11 -0
- package/templates/skills/opera-contract-auditor/SKILL.md +38 -0
- package/templates/skills/opera-contract-auditor/locales/en/SKILL.md +38 -0
- package/templates/skills/opera-policy-guard/SKILL.md +26 -0
- package/templates/skills/opera-policy-guard/locales/en/SKILL.md +26 -0
- package/templates/skills/project-starter-skill/SKILL.md +89 -164
- package/templates/skills/project-starter-skill/locales/en/SKILL.md +104 -0
- package/ui/css/panels.css +956 -953
- package/ui/index.html +1 -1
- package/ui/js/api.js +211 -194
- package/ui/js/app.js +200 -199
- package/ui/js/i18n.js +14 -0
- package/ui/js/onboarding.js +439 -437
- package/ui/js/state.js +130 -129
- package/ui/js/utils.js +175 -172
- package/ui/js/views/board.js +255 -254
- package/ui/js/views/execution.js +256 -256
- package/ui/js/views/insights.js +340 -339
- package/ui/js/views/overview.js +366 -361
- package/ui/js/views/settings.js +340 -202
- package/ui/js/views/sidebar.js +131 -132
- package/ui/js/views/skills.js +163 -162
- package/ui/js/views/tasks.js +406 -405
- package/ui/js/views/topbar.js +239 -183
- package/templates/etapa/agent.md +0 -26
- package/templates/etapa/genesis.md +0 -94
- package/templates/etapa/references/autonomy-and-recovery.md +0 -117
- package/templates/etapa/references/etapa-cycle.md +0 -193
- package/templates/etapa/registry.md +0 -28
- package/templates/etapa/router.md +0 -39
package/lib/env.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
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 contractServices = readContractServices(contextOrRoot, control);
|
|
63
|
+
const bootstrapServices = unique([
|
|
64
|
+
...(control.meta?.opera?.bootstrap?.discovery?.externalServices || []),
|
|
65
|
+
...(control.meta?.opera?.bootstrap?.externalServices || []),
|
|
66
|
+
]);
|
|
67
|
+
const fromServices = unique(
|
|
68
|
+
(contractServices.length ? contractServices : bootstrapServices)
|
|
69
|
+
.flatMap((service) => SERVICE_ENV_KEYS[service] || []),
|
|
70
|
+
);
|
|
71
|
+
const context = config.ensureContext(contextOrRoot || process.cwd());
|
|
72
|
+
const fromExample = parseEnvKeys(readText(context.env.exampleFile));
|
|
73
|
+
return unique([...fromMeta, ...fromServices, ...fromExample]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function readContractServices(contextOrRoot, control) {
|
|
77
|
+
const context = config.ensureContext(contextOrRoot || process.cwd());
|
|
78
|
+
const contractFile = context.paths.contractFile;
|
|
79
|
+
if (!fs.existsSync(contractFile)) return [];
|
|
80
|
+
try {
|
|
81
|
+
const contract = JSON.parse(fs.readFileSync(contractFile, "utf8"));
|
|
82
|
+
return Array.isArray(contract?.system?.externalServices) ? contract.system.externalServices : [];
|
|
83
|
+
} catch (_error) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ensureFileWithHeader(filePath, lines) {
|
|
89
|
+
if (fs.existsSync(filePath)) return;
|
|
90
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
91
|
+
fs.writeFileSync(filePath, `${lines.join("\n")}\n`, "utf8");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function appendMissingKeys(filePath, keys, heading) {
|
|
95
|
+
const existing = readText(filePath);
|
|
96
|
+
const parsed = parseEnvKeys(existing);
|
|
97
|
+
const missing = unique(keys).filter((key) => !parsed.includes(key));
|
|
98
|
+
if (!missing.length) return;
|
|
99
|
+
|
|
100
|
+
const chunks = [];
|
|
101
|
+
if (existing.trim()) chunks.push("");
|
|
102
|
+
if (heading) chunks.push(heading);
|
|
103
|
+
missing.forEach((key) => chunks.push(`${key}=`));
|
|
104
|
+
fs.appendFileSync(filePath, `${chunks.join("\n")}\n`, "utf8");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function safeUnlink(filePath) {
|
|
108
|
+
try {
|
|
109
|
+
fs.rmSync(filePath, { force: true });
|
|
110
|
+
} catch (_error) {
|
|
111
|
+
// noop
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function ensureBridge(context, control) {
|
|
116
|
+
const envMeta = normalizeEnvironmentMeta(control, context);
|
|
117
|
+
const bridgePath = context.env.appBridgeFile;
|
|
118
|
+
const exampleBridgePath = context.env.appExampleBridgeFile;
|
|
119
|
+
const sourceEnv = context.env.rootFile;
|
|
120
|
+
const sourceExample = context.env.exampleFile;
|
|
121
|
+
|
|
122
|
+
if (context.layout !== "split") {
|
|
123
|
+
control.meta.environment = { ...envMeta, bridgeMode: "none" };
|
|
124
|
+
return "none";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fs.mkdirSync(path.dirname(bridgePath), { recursive: true });
|
|
128
|
+
|
|
129
|
+
let mode = "copy";
|
|
130
|
+
safeUnlink(bridgePath);
|
|
131
|
+
try {
|
|
132
|
+
fs.symlinkSync(path.relative(path.dirname(bridgePath), sourceEnv), bridgePath, "file");
|
|
133
|
+
mode = "symlink";
|
|
134
|
+
} catch (_error) {
|
|
135
|
+
fs.copyFileSync(sourceEnv, bridgePath);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
safeUnlink(exampleBridgePath);
|
|
139
|
+
try {
|
|
140
|
+
fs.symlinkSync(path.relative(path.dirname(exampleBridgePath), sourceExample), exampleBridgePath, "file");
|
|
141
|
+
} catch (_error) {
|
|
142
|
+
fs.copyFileSync(sourceExample, exampleBridgePath);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
control.meta.environment = {
|
|
146
|
+
...envMeta,
|
|
147
|
+
bridgeMode: mode,
|
|
148
|
+
};
|
|
149
|
+
return mode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function syncEnvironment(contextOrRoot, controlState, options = {}) {
|
|
153
|
+
const context = config.ensureContext(contextOrRoot);
|
|
154
|
+
const control = controlState || config.loadControl(context);
|
|
155
|
+
control.meta = control.meta || {};
|
|
156
|
+
control.meta.environment = normalizeEnvironmentMeta(control, context);
|
|
157
|
+
|
|
158
|
+
const requiredKeys = unique(options.requiredKeys || inferRequiredKeys(control, context));
|
|
159
|
+
const optionalKeys = unique(options.optionalKeys || control.meta.environment.optionalKeys);
|
|
160
|
+
|
|
161
|
+
ensureFileWithHeader(context.env.rootFile, [
|
|
162
|
+
"# TrackOps workspace secrets",
|
|
163
|
+
"# Do not commit this file.",
|
|
164
|
+
]);
|
|
165
|
+
ensureFileWithHeader(context.env.exampleFile, [
|
|
166
|
+
"# TrackOps workspace environment contract",
|
|
167
|
+
"# Safe to commit. Keep only keys, never real values.",
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
appendMissingKeys(context.env.rootFile, requiredKeys, "# Required keys");
|
|
171
|
+
appendMissingKeys(context.env.exampleFile, requiredKeys, "# Required keys");
|
|
172
|
+
appendMissingKeys(context.env.exampleFile, optionalKeys, "# Optional keys");
|
|
173
|
+
|
|
174
|
+
const bridgeMode = ensureBridge(context, control);
|
|
175
|
+
control.meta.environment = {
|
|
176
|
+
...control.meta.environment,
|
|
177
|
+
requiredKeys,
|
|
178
|
+
optionalKeys,
|
|
179
|
+
bridgeMode,
|
|
180
|
+
lastAuditAt: new Date().toISOString(),
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
config.saveControl(context, control);
|
|
184
|
+
return auditEnvironment(context, control);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function auditEnvironment(contextOrRoot, controlState) {
|
|
188
|
+
const context = config.ensureContext(contextOrRoot);
|
|
189
|
+
const control = controlState || config.loadControl(context);
|
|
190
|
+
const envMeta = normalizeEnvironmentMeta(control, context);
|
|
191
|
+
const requiredKeys = unique(envMeta.requiredKeys.length ? envMeta.requiredKeys : inferRequiredKeys(control, context));
|
|
192
|
+
const envEntries = parseEnv(readText(context.env.rootFile));
|
|
193
|
+
const presentKeys = requiredKeys.filter((key) => String(envEntries[key] || "").trim());
|
|
194
|
+
const missingKeys = requiredKeys.filter((key) => !String(envEntries[key] || "").trim());
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
ok: true,
|
|
198
|
+
files: {
|
|
199
|
+
rootEnv: context.env.rootFile,
|
|
200
|
+
rootExample: context.env.exampleFile,
|
|
201
|
+
appBridge: context.env.appBridgeFile,
|
|
202
|
+
},
|
|
203
|
+
bridgeMode: envMeta.bridgeMode,
|
|
204
|
+
requiredKeys,
|
|
205
|
+
optionalKeys: envMeta.optionalKeys,
|
|
206
|
+
presentKeys,
|
|
207
|
+
missingKeys,
|
|
208
|
+
lastAuditAt: envMeta.lastAuditAt,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function cmdStatus(contextOrRoot) {
|
|
213
|
+
const audit = auditEnvironment(contextOrRoot);
|
|
214
|
+
console.log("Environment:");
|
|
215
|
+
console.log(` Root .env: ${audit.files.rootEnv}`);
|
|
216
|
+
console.log(` Example: ${audit.files.rootExample}`);
|
|
217
|
+
console.log(` App bridge: ${audit.files.appBridge}`);
|
|
218
|
+
console.log(` Bridge mode: ${audit.bridgeMode}`);
|
|
219
|
+
console.log(` Required keys: ${audit.requiredKeys.length ? audit.requiredKeys.join(", ") : "none"}`);
|
|
220
|
+
console.log(` Present: ${audit.presentKeys.length ? audit.presentKeys.join(", ") : "none"}`);
|
|
221
|
+
console.log(` Missing: ${audit.missingKeys.length ? audit.missingKeys.join(", ") : "none"}`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function cmdSync(contextOrRoot) {
|
|
225
|
+
const context = config.ensureContext(contextOrRoot);
|
|
226
|
+
const control = config.loadControl(context);
|
|
227
|
+
const audit = syncEnvironment(context, control);
|
|
228
|
+
console.log(`Environment synced at ${path.relative(context.workspaceRoot, context.env.rootFile)}`);
|
|
229
|
+
if (audit.missingKeys.length) {
|
|
230
|
+
console.log(`Missing required keys: ${audit.missingKeys.join(", ")}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = {
|
|
235
|
+
SERVICE_ENV_KEYS,
|
|
236
|
+
parseEnv,
|
|
237
|
+
parseEnvKeys,
|
|
238
|
+
normalizeEnvironmentMeta,
|
|
239
|
+
inferRequiredKeys,
|
|
240
|
+
syncEnvironment,
|
|
241
|
+
auditEnvironment,
|
|
242
|
+
cmdStatus,
|
|
243
|
+
cmdSync,
|
|
244
|
+
};
|
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
|
-
|
|
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,9 +4,13 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const { spawnSync } = require("child_process");
|
|
6
6
|
|
|
7
|
-
const
|
|
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
|
+
const runtimeState = require("./runtime-state");
|
|
10
14
|
|
|
11
15
|
const GENERATED_SCRIPT_COMMANDS = {
|
|
12
16
|
ops: "npx --yes trackops",
|
|
@@ -23,11 +27,30 @@ function nowIso() {
|
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
function parseArgs(args) {
|
|
26
|
-
const options = {
|
|
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
|
+
};
|
|
27
43
|
for (let i = 0; i < args.length; i += 1) {
|
|
28
44
|
if (args[i] === "--locale" && args[i + 1]) { options.locale = args[i + 1]; i += 1; }
|
|
29
45
|
else if (args[i] === "--name" && args[i + 1]) { options.name = args[i + 1]; i += 1; }
|
|
30
|
-
else if (args[i] === "--with-opera"
|
|
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; }
|
|
31
54
|
else if (args[i] === "--phases" && args[i + 1]) {
|
|
32
55
|
try { options.phases = JSON.parse(args[i + 1]); } catch (_e) { /* ignore */ }
|
|
33
56
|
i += 1;
|
|
@@ -42,20 +65,17 @@ function detectProjectName(root) {
|
|
|
42
65
|
try {
|
|
43
66
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
44
67
|
return pkg.displayName || pkg.name || path.basename(root);
|
|
45
|
-
} catch (_e) {
|
|
68
|
+
} catch (_e) {
|
|
69
|
+
// noop
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
return path.basename(root);
|
|
48
73
|
}
|
|
49
74
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function buildDefaultControl(options) {
|
|
58
|
-
const locale = options.locale || DEFAULT_LOCALE;
|
|
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";
|
|
59
79
|
setLocale(locale);
|
|
60
80
|
|
|
61
81
|
return {
|
|
@@ -63,12 +83,40 @@ function buildDefaultControl(options) {
|
|
|
63
83
|
projectName: options.name || "My Project",
|
|
64
84
|
controlVersion: 2,
|
|
65
85
|
locale,
|
|
66
|
-
phases
|
|
86
|
+
phases,
|
|
67
87
|
updatedAt: nowIso(),
|
|
68
88
|
executionSource: "project_control.json",
|
|
69
89
|
currentFocus: t("init.defaultFocus"),
|
|
70
|
-
focusPhase:
|
|
90
|
+
focusPhase: phases[0]?.id || "O",
|
|
71
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
|
+
},
|
|
72
120
|
},
|
|
73
121
|
checks: {
|
|
74
122
|
lastBuild: { status: "pending", date: null, note: "" },
|
|
@@ -87,7 +135,7 @@ function buildDefaultControl(options) {
|
|
|
87
135
|
{
|
|
88
136
|
id: "ops-bootstrap",
|
|
89
137
|
title: t("init.defaultTaskTitle"),
|
|
90
|
-
phase:
|
|
138
|
+
phase: phases[0]?.id || "O",
|
|
91
139
|
stream: "Operations",
|
|
92
140
|
priority: "P0",
|
|
93
141
|
status: "pending",
|
|
@@ -113,50 +161,102 @@ function upsertScripts(root) {
|
|
|
113
161
|
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
114
162
|
}
|
|
115
163
|
|
|
116
|
-
function installHooks(
|
|
117
|
-
const hooksDir =
|
|
164
|
+
function installHooks(context) {
|
|
165
|
+
const hooksDir = context.paths.hooksDir;
|
|
118
166
|
fs.mkdirSync(hooksDir, { recursive: true });
|
|
119
167
|
|
|
120
|
-
const
|
|
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}`;
|
|
121
172
|
for (const hookName of ["post-commit", "post-checkout", "post-merge"]) {
|
|
122
173
|
const hookPath = path.join(hooksDir, hookName);
|
|
123
174
|
fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
|
|
124
175
|
}
|
|
125
176
|
|
|
126
|
-
if (fs.existsSync(path.join(
|
|
127
|
-
|
|
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" });
|
|
128
180
|
}
|
|
129
181
|
}
|
|
130
182
|
|
|
131
|
-
function ensureTmpDir(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const gitkeep = path.join(tmpDir, ".gitkeep");
|
|
183
|
+
function ensureTmpDir(context) {
|
|
184
|
+
fs.mkdirSync(context.paths.tmpDir, { recursive: true });
|
|
185
|
+
const gitkeep = path.join(context.paths.tmpDir, ".gitkeep");
|
|
135
186
|
if (!fs.existsSync(gitkeep)) {
|
|
136
187
|
fs.writeFileSync(gitkeep, "", "utf8");
|
|
137
188
|
}
|
|
138
189
|
}
|
|
139
190
|
|
|
140
|
-
function
|
|
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) {
|
|
141
200
|
const targetRoot = path.resolve(root);
|
|
142
|
-
|
|
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;
|
|
143
242
|
const isUpgrade = fs.existsSync(controlFile);
|
|
243
|
+
options.locale = resolveLocale(options.locale, detectSystemLocale());
|
|
144
244
|
|
|
145
245
|
if (!options.name) {
|
|
146
246
|
options.name = detectProjectName(targetRoot);
|
|
147
247
|
}
|
|
148
248
|
|
|
149
249
|
if (isUpgrade) {
|
|
150
|
-
// Upgrade: add new meta fields if missing
|
|
151
250
|
const existing = JSON.parse(fs.readFileSync(controlFile, "utf8"));
|
|
152
|
-
if (!existing.meta.phases) existing.meta.phases = options.phases ||
|
|
153
|
-
if (!existing.meta.locale) existing.meta.locale = options.locale || DEFAULT_LOCALE;
|
|
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;
|
|
154
253
|
if (!existing.meta.controlVersion || existing.meta.controlVersion < 2) existing.meta.controlVersion = 2;
|
|
155
254
|
existing.meta.updatedAt = nowIso();
|
|
156
255
|
fs.writeFileSync(controlFile, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
|
|
157
256
|
console.log(t("init.updated", { file: "project_control.json" }));
|
|
158
257
|
} else {
|
|
159
|
-
const control = buildDefaultControl(options);
|
|
258
|
+
const control = buildDefaultControl(context, options);
|
|
259
|
+
control.meta.projectName = options.name;
|
|
160
260
|
fs.writeFileSync(controlFile, `${JSON.stringify(control, null, 2)}\n`, "utf8");
|
|
161
261
|
console.log(t("init.created", { file: "project_control.json" }));
|
|
162
262
|
}
|
|
@@ -164,38 +264,61 @@ function initProject(root, options) {
|
|
|
164
264
|
upsertScripts(targetRoot);
|
|
165
265
|
console.log(t("init.updated", { file: "package.json" }));
|
|
166
266
|
|
|
167
|
-
installHooks(
|
|
267
|
+
installHooks(context);
|
|
168
268
|
console.log(t("init.created", { file: ".githooks/" }));
|
|
169
|
-
|
|
170
|
-
ensureTmpDir(targetRoot);
|
|
269
|
+
ensureTmpDir(context);
|
|
171
270
|
|
|
172
271
|
try {
|
|
173
272
|
registry.registerProject(targetRoot);
|
|
174
273
|
console.log(t("init.registered"));
|
|
175
|
-
} catch (_e) {
|
|
176
|
-
|
|
177
|
-
|
|
274
|
+
} catch (_e) {
|
|
275
|
+
// ignore
|
|
276
|
+
}
|
|
178
277
|
|
|
179
278
|
console.log("");
|
|
180
279
|
console.log(t("init.welcome"));
|
|
280
|
+
return { root: targetRoot, context, isUpgrade, operaDetected: false };
|
|
281
|
+
}
|
|
181
282
|
|
|
182
|
-
|
|
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);
|
|
183
291
|
}
|
|
184
292
|
|
|
185
|
-
function cmdInit(args) {
|
|
293
|
+
async function cmdInit(args) {
|
|
186
294
|
const options = parseArgs(args || []);
|
|
187
|
-
const
|
|
188
|
-
|
|
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);
|
|
189
308
|
|
|
190
|
-
const result = initProject(
|
|
309
|
+
const result = initProject(process.cwd(), options);
|
|
191
310
|
|
|
192
311
|
if (options.withOpera) {
|
|
193
312
|
const opera = require("./opera");
|
|
194
|
-
opera.install(root, {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
});
|
|
199
322
|
}
|
|
200
323
|
}
|
|
201
324
|
|