trackops 1.0.1 → 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.
- package/README.md +326 -270
- package/bin/trackops.js +102 -70
- package/lib/config.js +260 -35
- package/lib/control.js +517 -475
- package/lib/env.js +227 -0
- package/lib/i18n.js +61 -53
- package/lib/init.js +135 -46
- package/lib/locale.js +63 -0
- package/lib/opera-bootstrap.js +523 -0
- package/lib/opera.js +319 -170
- package/lib/registry.js +27 -13
- package/lib/release.js +56 -0
- package/lib/resources.js +42 -0
- package/lib/server.js +907 -554
- package/lib/skills.js +148 -124
- package/lib/workspace.js +260 -0
- package/locales/en.json +331 -139
- package/locales/es.json +331 -139
- package/package.json +7 -9
- package/scripts/skills-marketplace-smoke.js +124 -0
- package/scripts/smoke-tests.js +445 -0
- package/scripts/sync-skill-version.js +21 -0
- package/scripts/validate-skill.js +88 -0
- package/skills/trackops/SKILL.md +64 -0
- package/skills/trackops/agents/openai.yaml +3 -0
- package/skills/trackops/references/activation.md +39 -0
- package/skills/trackops/references/troubleshooting.md +34 -0
- package/skills/trackops/references/workflow.md +20 -0
- package/skills/trackops/scripts/bootstrap-trackops.js +201 -0
- package/skills/trackops/skill.json +29 -0
- package/templates/opera/en/agent.md +26 -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/router.md +39 -0
- package/templates/opera/genesis.md +79 -94
- package/templates/skills/changelog-updater/locales/en/SKILL.md +11 -0
- package/templates/skills/commiter/locales/en/SKILL.md +11 -0
- package/templates/skills/project-starter-skill/locales/en/SKILL.md +24 -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 +365 -364
- 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/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
|
-
|
|
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,12 @@ 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");
|
|
10
13
|
|
|
11
14
|
const GENERATED_SCRIPT_COMMANDS = {
|
|
12
15
|
ops: "npx --yes trackops",
|
|
@@ -23,11 +26,20 @@ function nowIso() {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
function parseArgs(args) {
|
|
26
|
-
const options = {
|
|
29
|
+
const options = {
|
|
30
|
+
locale: null,
|
|
31
|
+
name: null,
|
|
32
|
+
withOpera: false,
|
|
33
|
+
phases: null,
|
|
34
|
+
noBootstrap: false,
|
|
35
|
+
legacyLayout: false,
|
|
36
|
+
};
|
|
27
37
|
for (let i = 0; i < args.length; i += 1) {
|
|
28
38
|
if (args[i] === "--locale" && args[i + 1]) { options.locale = args[i + 1]; i += 1; }
|
|
29
39
|
else if (args[i] === "--name" && args[i + 1]) { options.name = args[i + 1]; i += 1; }
|
|
30
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; }
|
|
31
43
|
else if (args[i] === "--phases" && args[i + 1]) {
|
|
32
44
|
try { options.phases = JSON.parse(args[i + 1]); } catch (_e) { /* ignore */ }
|
|
33
45
|
i += 1;
|
|
@@ -42,20 +54,17 @@ function detectProjectName(root) {
|
|
|
42
54
|
try {
|
|
43
55
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
44
56
|
return pkg.displayName || pkg.name || path.basename(root);
|
|
45
|
-
} catch (_e) {
|
|
57
|
+
} catch (_e) {
|
|
58
|
+
// noop
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
return path.basename(root);
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function buildDefaultControl(options) {
|
|
58
|
-
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";
|
|
59
68
|
setLocale(locale);
|
|
60
69
|
|
|
61
70
|
return {
|
|
@@ -63,12 +72,30 @@ function buildDefaultControl(options) {
|
|
|
63
72
|
projectName: options.name || "My Project",
|
|
64
73
|
controlVersion: 2,
|
|
65
74
|
locale,
|
|
66
|
-
phases
|
|
75
|
+
phases,
|
|
67
76
|
updatedAt: nowIso(),
|
|
68
77
|
executionSource: "project_control.json",
|
|
69
78
|
currentFocus: t("init.defaultFocus"),
|
|
70
|
-
focusPhase:
|
|
79
|
+
focusPhase: phases[0]?.id || "O",
|
|
71
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
|
+
},
|
|
72
99
|
},
|
|
73
100
|
checks: {
|
|
74
101
|
lastBuild: { status: "pending", date: null, note: "" },
|
|
@@ -87,7 +114,7 @@ function buildDefaultControl(options) {
|
|
|
87
114
|
{
|
|
88
115
|
id: "ops-bootstrap",
|
|
89
116
|
title: t("init.defaultTaskTitle"),
|
|
90
|
-
phase:
|
|
117
|
+
phase: phases[0]?.id || "O",
|
|
91
118
|
stream: "Operations",
|
|
92
119
|
priority: "P0",
|
|
93
120
|
status: "pending",
|
|
@@ -113,50 +140,102 @@ function upsertScripts(root) {
|
|
|
113
140
|
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
114
141
|
}
|
|
115
142
|
|
|
116
|
-
function installHooks(
|
|
117
|
-
const hooksDir =
|
|
143
|
+
function installHooks(context) {
|
|
144
|
+
const hooksDir = context.paths.hooksDir;
|
|
118
145
|
fs.mkdirSync(hooksDir, { recursive: true });
|
|
119
146
|
|
|
120
|
-
const
|
|
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}`;
|
|
121
151
|
for (const hookName of ["post-commit", "post-checkout", "post-merge"]) {
|
|
122
152
|
const hookPath = path.join(hooksDir, hookName);
|
|
123
153
|
fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
|
|
124
154
|
}
|
|
125
155
|
|
|
126
|
-
if (fs.existsSync(path.join(
|
|
127
|
-
|
|
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" });
|
|
128
159
|
}
|
|
129
160
|
}
|
|
130
161
|
|
|
131
|
-
function ensureTmpDir(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
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");
|
|
135
165
|
if (!fs.existsSync(gitkeep)) {
|
|
136
166
|
fs.writeFileSync(gitkeep, "", "utf8");
|
|
137
167
|
}
|
|
138
168
|
}
|
|
139
169
|
|
|
140
|
-
function
|
|
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) {
|
|
141
179
|
const targetRoot = path.resolve(root);
|
|
142
|
-
|
|
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) {
|
|
218
|
+
const targetRoot = path.resolve(root);
|
|
219
|
+
const context = config.createLegacyContext(targetRoot);
|
|
220
|
+
const controlFile = context.controlFile;
|
|
143
221
|
const isUpgrade = fs.existsSync(controlFile);
|
|
222
|
+
options.locale = resolveLocale(options.locale, detectSystemLocale());
|
|
144
223
|
|
|
145
224
|
if (!options.name) {
|
|
146
225
|
options.name = detectProjectName(targetRoot);
|
|
147
226
|
}
|
|
148
227
|
|
|
149
228
|
if (isUpgrade) {
|
|
150
|
-
// Upgrade: add new meta fields if missing
|
|
151
229
|
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;
|
|
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;
|
|
154
232
|
if (!existing.meta.controlVersion || existing.meta.controlVersion < 2) existing.meta.controlVersion = 2;
|
|
155
233
|
existing.meta.updatedAt = nowIso();
|
|
156
234
|
fs.writeFileSync(controlFile, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
|
|
157
235
|
console.log(t("init.updated", { file: "project_control.json" }));
|
|
158
236
|
} else {
|
|
159
|
-
const control = buildDefaultControl(options);
|
|
237
|
+
const control = buildDefaultControl(context, options);
|
|
238
|
+
control.meta.projectName = options.name;
|
|
160
239
|
fs.writeFileSync(controlFile, `${JSON.stringify(control, null, 2)}\n`, "utf8");
|
|
161
240
|
console.log(t("init.created", { file: "project_control.json" }));
|
|
162
241
|
}
|
|
@@ -164,38 +243,48 @@ function initProject(root, options) {
|
|
|
164
243
|
upsertScripts(targetRoot);
|
|
165
244
|
console.log(t("init.updated", { file: "package.json" }));
|
|
166
245
|
|
|
167
|
-
installHooks(
|
|
246
|
+
installHooks(context);
|
|
168
247
|
console.log(t("init.created", { file: ".githooks/" }));
|
|
169
|
-
|
|
170
|
-
ensureTmpDir(targetRoot);
|
|
248
|
+
ensureTmpDir(context);
|
|
171
249
|
|
|
172
250
|
try {
|
|
173
251
|
registry.registerProject(targetRoot);
|
|
174
252
|
console.log(t("init.registered"));
|
|
175
|
-
} catch (_e) {
|
|
176
|
-
|
|
177
|
-
|
|
253
|
+
} catch (_e) {
|
|
254
|
+
// ignore
|
|
255
|
+
}
|
|
178
256
|
|
|
179
257
|
console.log("");
|
|
180
258
|
console.log(t("init.welcome"));
|
|
259
|
+
return { root: targetRoot, context, isUpgrade, operaDetected: false };
|
|
260
|
+
}
|
|
181
261
|
|
|
182
|
-
|
|
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);
|
|
183
270
|
}
|
|
184
271
|
|
|
185
|
-
function cmdInit(args) {
|
|
272
|
+
async function cmdInit(args) {
|
|
186
273
|
const options = parseArgs(args || []);
|
|
187
|
-
|
|
188
|
-
|
|
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);
|
|
189
279
|
|
|
190
|
-
const result = initProject(
|
|
280
|
+
const result = initProject(process.cwd(), options);
|
|
191
281
|
|
|
192
282
|
if (options.withOpera) {
|
|
193
283
|
const opera = require("./opera");
|
|
194
|
-
opera.install(root, {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
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
|
+
});
|
|
199
288
|
}
|
|
200
289
|
}
|
|
201
290
|
|