trackops 2.0.4 → 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 (90) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +695 -640
  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 +41 -41
  9. package/lib/opera-bootstrap.js +942 -936
  10. package/lib/opera.js +495 -486
  11. package/lib/preferences.js +74 -74
  12. package/lib/registry.js +214 -214
  13. package/lib/release.js +56 -56
  14. package/lib/runtime-state.js +144 -144
  15. package/lib/skills.js +74 -57
  16. package/lib/workspace.js +260 -260
  17. package/locales/en.json +192 -170
  18. package/locales/es.json +192 -170
  19. package/package.json +61 -58
  20. package/scripts/postinstall-locale.js +21 -21
  21. package/scripts/skills-marketplace-smoke.js +124 -124
  22. package/scripts/smoke-tests.js +558 -554
  23. package/scripts/sync-skill-version.js +21 -21
  24. package/scripts/validate-skill.js +103 -103
  25. package/skills/trackops/SKILL.md +126 -122
  26. package/skills/trackops/agents/openai.yaml +7 -7
  27. package/skills/trackops/locales/en/SKILL.md +126 -122
  28. package/skills/trackops/locales/en/references/activation.md +94 -90
  29. package/skills/trackops/locales/en/references/troubleshooting.md +73 -67
  30. package/skills/trackops/locales/en/references/workflow.md +55 -32
  31. package/skills/trackops/references/activation.md +94 -90
  32. package/skills/trackops/references/troubleshooting.md +73 -67
  33. package/skills/trackops/references/workflow.md +55 -32
  34. package/skills/trackops/skill.json +29 -29
  35. package/templates/hooks/post-checkout +2 -2
  36. package/templates/hooks/post-commit +2 -2
  37. package/templates/hooks/post-merge +2 -2
  38. package/templates/opera/agent.md +28 -27
  39. package/templates/opera/architecture/dependency-graph.md +24 -24
  40. package/templates/opera/architecture/runtime-automation.md +24 -24
  41. package/templates/opera/architecture/runtime-operations.md +34 -34
  42. package/templates/opera/en/agent.md +22 -21
  43. package/templates/opera/en/architecture/dependency-graph.md +24 -24
  44. package/templates/opera/en/architecture/runtime-automation.md +24 -24
  45. package/templates/opera/en/architecture/runtime-operations.md +34 -34
  46. package/templates/opera/en/reviews/delivery-audit.md +18 -18
  47. package/templates/opera/en/reviews/integration-audit.md +18 -18
  48. package/templates/opera/en/router.md +24 -19
  49. package/templates/opera/references/autonomy-and-recovery.md +117 -117
  50. package/templates/opera/references/opera-cycle.md +193 -193
  51. package/templates/opera/registry.md +28 -28
  52. package/templates/opera/reviews/delivery-audit.md +18 -18
  53. package/templates/opera/reviews/integration-audit.md +18 -18
  54. package/templates/opera/router.md +54 -49
  55. package/templates/skills/changelog-updater/SKILL.md +69 -69
  56. package/templates/skills/commiter/SKILL.md +99 -99
  57. package/templates/skills/opera-contract-auditor/SKILL.md +38 -38
  58. package/templates/skills/opera-contract-auditor/locales/en/SKILL.md +38 -38
  59. package/templates/skills/opera-policy-guard/SKILL.md +26 -26
  60. package/templates/skills/opera-policy-guard/locales/en/SKILL.md +26 -26
  61. package/templates/skills/opera-skill/SKILL.md +279 -0
  62. package/templates/skills/opera-skill/locales/en/SKILL.md +279 -0
  63. package/templates/skills/opera-skill/locales/en/references/phase-dod.md +138 -0
  64. package/templates/skills/opera-skill/references/phase-dod.md +138 -0
  65. package/templates/skills/project-starter-skill/SKILL.md +150 -131
  66. package/templates/skills/project-starter-skill/locales/en/SKILL.md +143 -105
  67. package/templates/skills/project-starter-skill/references/opera-cycle.md +195 -193
  68. package/ui/css/base.css +284 -284
  69. package/ui/css/charts.css +425 -425
  70. package/ui/css/components.css +1107 -1107
  71. package/ui/css/onboarding.css +133 -133
  72. package/ui/css/terminal.css +125 -125
  73. package/ui/css/timeline.css +58 -58
  74. package/ui/css/tokens.css +284 -284
  75. package/ui/favicon.svg +5 -5
  76. package/ui/index.html +99 -99
  77. package/ui/js/charts.js +526 -526
  78. package/ui/js/console-logger.js +172 -172
  79. package/ui/js/filters.js +247 -247
  80. package/ui/js/icons.js +129 -129
  81. package/ui/js/keyboard.js +229 -229
  82. package/ui/js/router.js +142 -142
  83. package/ui/js/theme.js +100 -100
  84. package/ui/js/time-tracker.js +248 -248
  85. package/ui/js/views/dashboard.js +870 -870
  86. package/ui/js/views/flash.js +47 -47
  87. package/ui/js/views/projects.js +745 -745
  88. package/ui/js/views/scrum.js +476 -476
  89. package/ui/js/views/settings.js +331 -331
  90. package/ui/js/views/timeline.js +265 -265
package/lib/env.js CHANGED
@@ -1,244 +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
- };
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
+ };