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/skills.js
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
const config = require("./config");
|
|
7
|
-
const { t, setLocale } = require("./i18n");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const config = require("./config");
|
|
7
|
+
const { t, setLocale } = require("./i18n");
|
|
8
|
+
const { resolveSkillFile } = require("./resources");
|
|
9
|
+
|
|
10
|
+
const SKILLS_TEMPLATES_DIR = path.join(__dirname, "..", "templates", "skills");
|
|
11
|
+
|
|
12
|
+
function copyDirRecursive(src, dest) {
|
|
13
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
14
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
15
|
+
const srcPath = path.join(src, entry.name);
|
|
16
|
+
const destPath = path.join(dest, entry.name);
|
|
17
|
+
if (entry.isDirectory()) {
|
|
18
|
+
copyDirRecursive(srcPath, destPath);
|
|
19
|
+
} else {
|
|
20
|
+
fs.copyFileSync(srcPath, destPath);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
24
25
|
function parseFrontmatter(content) {
|
|
25
26
|
const match = content.match(/^---\s*\n([\s\S]*?)\n---/);
|
|
26
27
|
if (!match) return {};
|
|
27
|
-
const fm = {};
|
|
28
|
-
for (const line of match[1].split("\n")) {
|
|
29
|
-
const sep = line.indexOf(":");
|
|
30
|
-
if (sep > 0) {
|
|
31
|
-
const key = line.slice(0, sep).trim().replace(/^["']|["']$/g, "");
|
|
32
|
-
const val = line.slice(sep + 1).trim().replace(/^["']|["']$/g, "");
|
|
33
|
-
fm[key] = val;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
28
|
+
const fm = {};
|
|
29
|
+
for (const line of match[1].split("\n")) {
|
|
30
|
+
const sep = line.indexOf(":");
|
|
31
|
+
if (sep > 0) {
|
|
32
|
+
const key = line.slice(0, sep).trim().replace(/^["']|["']$/g, "");
|
|
33
|
+
const val = line.slice(sep + 1).trim().replace(/^["']|["']$/g, "");
|
|
34
|
+
fm[key] = val;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
36
37
|
return fm;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function getSkillsDir(root) {
|
|
40
|
-
return
|
|
41
|
+
return config.ensureContext(root).paths.skillsDir;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function getRegistryPath(root) {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function catalogSkills() {
|
|
48
|
-
if (!fs.existsSync(SKILLS_TEMPLATES_DIR)) return [];
|
|
49
|
-
return fs.readdirSync(SKILLS_TEMPLATES_DIR, { withFileTypes: true })
|
|
50
|
-
.filter((e) => e.isDirectory())
|
|
51
|
-
.map((e) => {
|
|
52
|
-
const skillMd = path.join(SKILLS_TEMPLATES_DIR, e.name, "SKILL.md");
|
|
53
|
-
if (!fs.existsSync(skillMd)) return null;
|
|
54
|
-
const fm = parseFrontmatter(fs.readFileSync(skillMd, "utf8"));
|
|
55
|
-
return { name: e.name, description: fm.description || "", version: fm.version || "1.0" };
|
|
56
|
-
})
|
|
57
|
-
.filter(Boolean);
|
|
45
|
+
return config.ensureContext(root).paths.registryPath;
|
|
58
46
|
}
|
|
59
|
-
|
|
47
|
+
|
|
48
|
+
function catalogSkills() {
|
|
49
|
+
if (!fs.existsSync(SKILLS_TEMPLATES_DIR)) return [];
|
|
50
|
+
return fs.readdirSync(SKILLS_TEMPLATES_DIR, { withFileTypes: true })
|
|
51
|
+
.filter((e) => e.isDirectory())
|
|
52
|
+
.map((e) => {
|
|
53
|
+
const skillMd = path.join(SKILLS_TEMPLATES_DIR, e.name, "SKILL.md");
|
|
54
|
+
if (!fs.existsSync(skillMd)) return null;
|
|
55
|
+
const fm = parseFrontmatter(fs.readFileSync(skillMd, "utf8"));
|
|
56
|
+
return { name: e.name, description: fm.description || "", version: fm.version || "1.0" };
|
|
57
|
+
})
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
}
|
|
60
|
+
|
|
60
61
|
function installedSkills(root) {
|
|
61
62
|
const skillsDir = getSkillsDir(root);
|
|
62
63
|
if (!fs.existsSync(skillsDir)) return [];
|
|
@@ -65,95 +66,118 @@ function installedSkills(root) {
|
|
|
65
66
|
.map((e) => {
|
|
66
67
|
const fm = parseFrontmatter(fs.readFileSync(path.join(skillsDir, e.name, "SKILL.md"), "utf8"));
|
|
67
68
|
return { name: e.name, description: fm.description || "", version: fm.version || "1.0" };
|
|
68
|
-
})
|
|
69
|
+
})
|
|
70
|
+
.filter(Boolean);
|
|
69
71
|
}
|
|
70
|
-
|
|
71
|
-
function updateRegistry(root) {
|
|
72
|
-
const registryPath = getRegistryPath(root);
|
|
73
|
-
fs.mkdirSync(path.dirname(registryPath), { recursive: true });
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
lines.push(`| ${s.name} | ${s.version} | ${s.description} |`);
|
|
78
|
-
}
|
|
79
|
-
fs.writeFileSync(registryPath, lines.join("\n") + "\n", "utf8");
|
|
80
|
-
|
|
81
|
-
// Also update control meta
|
|
82
|
-
const controlFile = config.controlFilePath(root);
|
|
72
|
+
|
|
73
|
+
function updateRegistry(root) {
|
|
74
|
+
const registryPath = getRegistryPath(root);
|
|
75
|
+
fs.mkdirSync(path.dirname(registryPath), { recursive: true });
|
|
76
|
+
let locale = "es";
|
|
77
|
+
const context = config.ensureContext(root);
|
|
78
|
+
const controlFile = config.controlFilePath(context);
|
|
83
79
|
if (fs.existsSync(controlFile)) {
|
|
84
80
|
try {
|
|
85
|
-
|
|
81
|
+
locale = config.getLocale(config.loadControl(context));
|
|
82
|
+
setLocale(locale);
|
|
83
|
+
} catch (_error) {
|
|
84
|
+
setLocale("es");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const skills = installedSkills(root);
|
|
88
|
+
const header = locale === "en" ? "# Skills Registry" : "# Skills Registry";
|
|
89
|
+
const empty = locale === "en"
|
|
90
|
+
? "_No skills installed yet. Use `trackops skill install <name>` to add one._"
|
|
91
|
+
: "_Sin skills instaladas. Usa `trackops skill install <nombre>` para añadir una._";
|
|
92
|
+
const lines = [header, "", "| Skill | Version | Description |", "|-------|---------|-------------|"];
|
|
93
|
+
for (const s of skills) {
|
|
94
|
+
lines.push(`| ${s.name} | ${s.version} | ${s.description} |`);
|
|
95
|
+
}
|
|
96
|
+
if (!skills.length) lines.push("", empty);
|
|
97
|
+
fs.writeFileSync(registryPath, lines.join("\n") + "\n", "utf8");
|
|
98
|
+
|
|
99
|
+
// Also update control meta
|
|
100
|
+
if (fs.existsSync(controlFile)) {
|
|
101
|
+
try {
|
|
102
|
+
const control = config.loadControl(context);
|
|
86
103
|
if (control.meta.opera) {
|
|
87
104
|
control.meta.opera.skills = skills.map((s) => s.name);
|
|
88
|
-
config.saveControl(
|
|
105
|
+
config.saveControl(context, control);
|
|
89
106
|
}
|
|
90
|
-
} catch (_e) { /* ignore */ }
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
107
|
+
} catch (_e) { /* ignore */ }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
function installSkill(root, skillName) {
|
|
95
|
-
const
|
|
112
|
+
const context = config.ensureContext(root);
|
|
113
|
+
const control = config.loadControl(context);
|
|
96
114
|
setLocale(config.getLocale(control));
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
const locale = config.getLocale(control);
|
|
116
|
+
|
|
117
|
+
const templateDir = path.join(SKILLS_TEMPLATES_DIR, skillName);
|
|
118
|
+
if (!fs.existsSync(templateDir)) {
|
|
119
|
+
throw new Error(t("skill.notFound", { name: skillName }));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const targetDir = path.join(getSkillsDir(context), skillName);
|
|
123
|
+
if (fs.existsSync(path.join(targetDir, "SKILL.md"))) {
|
|
124
|
+
console.log(t("skill.alreadyInstalled", { name: skillName }));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
copyDirRecursive(templateDir, targetDir);
|
|
129
|
+
const localizedSkill = resolveSkillFile(SKILLS_TEMPLATES_DIR, skillName, locale);
|
|
130
|
+
if (localizedSkill) {
|
|
131
|
+
fs.copyFileSync(localizedSkill, path.join(targetDir, "SKILL.md"));
|
|
132
|
+
}
|
|
133
|
+
updateRegistry(context);
|
|
111
134
|
console.log(t("skill.installed", { name: skillName }));
|
|
112
135
|
}
|
|
113
136
|
|
|
114
137
|
function removeSkill(root, skillName) {
|
|
115
|
-
const
|
|
138
|
+
const context = config.ensureContext(root);
|
|
139
|
+
const control = config.loadControl(context);
|
|
116
140
|
setLocale(config.getLocale(control));
|
|
117
141
|
|
|
118
|
-
const targetDir = path.join(getSkillsDir(
|
|
119
|
-
if (!fs.existsSync(targetDir)) {
|
|
120
|
-
console.log(t("skill.notInstalled", { name: skillName }));
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
125
|
-
updateRegistry(
|
|
142
|
+
const targetDir = path.join(getSkillsDir(context), skillName);
|
|
143
|
+
if (!fs.existsSync(targetDir)) {
|
|
144
|
+
console.log(t("skill.notInstalled", { name: skillName }));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
149
|
+
updateRegistry(context);
|
|
126
150
|
console.log(t("skill.removed", { name: skillName }));
|
|
127
151
|
}
|
|
128
|
-
|
|
129
|
-
/* ── CLI commands ── */
|
|
130
|
-
|
|
131
|
-
function cmdInstall(root, skillName) {
|
|
132
|
-
if (!skillName) { console.error("Skill name required."); process.exit(1); }
|
|
133
|
-
installSkill(root, skillName);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function cmdList(root) {
|
|
137
|
-
const skills = installedSkills(root);
|
|
138
|
-
if (!skills.length) { console.log("No skills installed."); return; }
|
|
139
|
-
console.log(t("skill.listTitle"));
|
|
140
|
-
for (const s of skills) {
|
|
141
|
-
console.log(` ${s.name} (v${s.version}) — ${s.description}`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function cmdRemove(root, skillName) {
|
|
146
|
-
if (!skillName) { console.error("Skill name required."); process.exit(1); }
|
|
147
|
-
removeSkill(root, skillName);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function cmdCatalog() {
|
|
151
|
-
const skills = catalogSkills();
|
|
152
|
-
if (!skills.length) { console.log("No skills available in catalog."); return; }
|
|
153
|
-
console.log(t("skill.catalogTitle"));
|
|
154
|
-
for (const s of skills) {
|
|
155
|
-
console.log(` ${s.name} (v${s.version}) — ${s.description}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
module.exports = { installSkill, removeSkill, installedSkills, catalogSkills, updateRegistry, cmdInstall, cmdList, cmdRemove, cmdCatalog };
|
|
152
|
+
|
|
153
|
+
/* ── CLI commands ── */
|
|
154
|
+
|
|
155
|
+
function cmdInstall(root, skillName) {
|
|
156
|
+
if (!skillName) { console.error("Skill name required."); process.exit(1); }
|
|
157
|
+
installSkill(root, skillName);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function cmdList(root) {
|
|
161
|
+
const skills = installedSkills(root);
|
|
162
|
+
if (!skills.length) { console.log("No skills installed."); return; }
|
|
163
|
+
console.log(t("skill.listTitle"));
|
|
164
|
+
for (const s of skills) {
|
|
165
|
+
console.log(` ${s.name} (v${s.version}) — ${s.description}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function cmdRemove(root, skillName) {
|
|
170
|
+
if (!skillName) { console.error("Skill name required."); process.exit(1); }
|
|
171
|
+
removeSkill(root, skillName);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function cmdCatalog() {
|
|
175
|
+
const skills = catalogSkills();
|
|
176
|
+
if (!skills.length) { console.log("No skills available in catalog."); return; }
|
|
177
|
+
console.log(t("skill.catalogTitle"));
|
|
178
|
+
for (const s of skills) {
|
|
179
|
+
console.log(` ${s.name} (v${s.version}) — ${s.description}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = { installSkill, removeSkill, installedSkills, catalogSkills, updateRegistry, cmdInstall, cmdList, cmdRemove, cmdCatalog };
|
package/lib/workspace.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const config = require("./config");
|
|
8
|
+
const registry = require("./registry");
|
|
9
|
+
const env = require("./env");
|
|
10
|
+
|
|
11
|
+
const OPS_ARTIFACTS = [
|
|
12
|
+
"project_control.json",
|
|
13
|
+
"task_plan.md",
|
|
14
|
+
"progress.md",
|
|
15
|
+
"findings.md",
|
|
16
|
+
"genesis.md",
|
|
17
|
+
".agent",
|
|
18
|
+
".agents",
|
|
19
|
+
".githooks",
|
|
20
|
+
".tmp",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function nowStamp() {
|
|
24
|
+
return new Date().toISOString().replace(/[:.]/g, "-");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function git(args, cwd) {
|
|
28
|
+
return spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isIgnorableDirtyLine(line) {
|
|
32
|
+
const normalized = String(line || "").replace(/\\/g, "/");
|
|
33
|
+
return normalized.endsWith(".tmp/project-control-runtime.json");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isRetryableMoveError(error) {
|
|
37
|
+
return ["EPERM", "EXDEV", "EBUSY", "ENOTEMPTY"].includes(error?.code);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertCleanGit(root, allowDirty = false) {
|
|
41
|
+
const status = git(["status", "--porcelain"], root);
|
|
42
|
+
const dirtyLines = String(status.stdout || "")
|
|
43
|
+
.split(/\r?\n/)
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.filter((line) => !isIgnorableDirtyLine(line));
|
|
46
|
+
if (!allowDirty && dirtyLines.length > 0) {
|
|
47
|
+
throw new Error("Workspace migration requires a clean git worktree.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createBackupBranch(root) {
|
|
52
|
+
const name = `backup/trackops-workspace-${nowStamp()}`;
|
|
53
|
+
const result = git(["branch", name], root);
|
|
54
|
+
if (result.status !== 0) {
|
|
55
|
+
throw new Error(result.stderr || `Could not create backup branch ${name}`);
|
|
56
|
+
}
|
|
57
|
+
return name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildManifest() {
|
|
61
|
+
return {
|
|
62
|
+
version: 1,
|
|
63
|
+
layout: "split",
|
|
64
|
+
appDir: config.DEFAULT_APP_DIR,
|
|
65
|
+
opsDir: config.DEFAULT_OPS_DIR,
|
|
66
|
+
env: {
|
|
67
|
+
rootFile: ".env",
|
|
68
|
+
exampleFile: ".env.example",
|
|
69
|
+
appBridgeFile: "app/.env",
|
|
70
|
+
bridgeMode: "symlink-or-copy",
|
|
71
|
+
},
|
|
72
|
+
branches: {
|
|
73
|
+
development: config.DEFAULT_DEV_BRANCH,
|
|
74
|
+
publish: config.DEFAULT_PUBLISH_BRANCH,
|
|
75
|
+
},
|
|
76
|
+
publish: {
|
|
77
|
+
mode: "subtree-flatten",
|
|
78
|
+
sourceDir: config.DEFAULT_APP_DIR,
|
|
79
|
+
includeRootFiles: [".env.example"],
|
|
80
|
+
requireCleanWorktree: true,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function ensureRootGitignore(workspaceRoot) {
|
|
86
|
+
const gitignorePath = path.join(workspaceRoot, ".gitignore");
|
|
87
|
+
const required = ["/.env", "/app/.env", "/ops/.tmp/"];
|
|
88
|
+
let lines = [];
|
|
89
|
+
if (fs.existsSync(gitignorePath)) {
|
|
90
|
+
lines = fs.readFileSync(gitignorePath, "utf8").split(/\r?\n/);
|
|
91
|
+
}
|
|
92
|
+
for (const entry of required) {
|
|
93
|
+
if (!lines.includes(entry)) lines.push(entry);
|
|
94
|
+
}
|
|
95
|
+
fs.writeFileSync(gitignorePath, `${lines.filter(Boolean).join("\n")}\n`, "utf8");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function stripOpsScripts(packageFile) {
|
|
99
|
+
if (!fs.existsSync(packageFile)) return;
|
|
100
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, "utf8"));
|
|
101
|
+
if (!pkg.scripts) return;
|
|
102
|
+
["ops", "ops:help", "ops:dashboard", "ops:status", "ops:next", "ops:sync", "ops:repo"].forEach((key) => {
|
|
103
|
+
delete pkg.scripts[key];
|
|
104
|
+
});
|
|
105
|
+
fs.writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function moveEntry(fromPath, toPath) {
|
|
109
|
+
if (!fs.existsSync(fromPath)) return;
|
|
110
|
+
fs.mkdirSync(path.dirname(toPath), { recursive: true });
|
|
111
|
+
try {
|
|
112
|
+
fs.renameSync(fromPath, toPath);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (!isRetryableMoveError(error)) throw error;
|
|
115
|
+
const stat = fs.statSync(fromPath);
|
|
116
|
+
if (stat.isDirectory()) {
|
|
117
|
+
fs.cpSync(fromPath, toPath, { recursive: true, force: true });
|
|
118
|
+
fs.rmSync(fromPath, { recursive: true, force: true });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
fs.copyFileSync(fromPath, toPath);
|
|
122
|
+
fs.rmSync(fromPath, { force: true });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function shouldResumePartialMigration(root, manifest) {
|
|
127
|
+
if (!fs.existsSync(path.join(root, config.WORKSPACE_MANIFEST))) return false;
|
|
128
|
+
const excluded = new Set([
|
|
129
|
+
".git",
|
|
130
|
+
config.WORKSPACE_MANIFEST,
|
|
131
|
+
manifest.appDir,
|
|
132
|
+
manifest.opsDir,
|
|
133
|
+
".env",
|
|
134
|
+
".env.example",
|
|
135
|
+
]);
|
|
136
|
+
const hasPendingOps = OPS_ARTIFACTS.some((entry) => fs.existsSync(path.join(root, entry)));
|
|
137
|
+
const hasPendingAppEntries = fs.readdirSync(root, { withFileTypes: true })
|
|
138
|
+
.some((entry) => !excluded.has(entry.name));
|
|
139
|
+
return hasPendingOps || hasPendingAppEntries;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function migrateWorkspace(rootDir, options = {}) {
|
|
143
|
+
const resolved = config.resolveWorkspaceContext(rootDir);
|
|
144
|
+
if (!resolved) {
|
|
145
|
+
throw new Error("workspace migrate only applies to legacy TrackOps projects.");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const root = resolved.workspaceRoot;
|
|
149
|
+
let manifest;
|
|
150
|
+
if (resolved.layout === "legacy") {
|
|
151
|
+
manifest = buildManifest();
|
|
152
|
+
} else {
|
|
153
|
+
manifest = config.loadWorkspaceManifest(resolved) || buildManifest();
|
|
154
|
+
if (!shouldResumePartialMigration(root, manifest)) {
|
|
155
|
+
throw new Error("workspace migrate only applies to legacy TrackOps projects.");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
assertCleanGit(root, options.allowDirty === true);
|
|
160
|
+
const backupBranch = createBackupBranch(root);
|
|
161
|
+
|
|
162
|
+
const appDir = path.join(root, manifest.appDir);
|
|
163
|
+
const opsDir = path.join(root, manifest.opsDir);
|
|
164
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
165
|
+
fs.mkdirSync(opsDir, { recursive: true });
|
|
166
|
+
config.saveWorkspaceManifest(config.createSplitContext(root, manifest), manifest);
|
|
167
|
+
|
|
168
|
+
for (const entry of OPS_ARTIFACTS) {
|
|
169
|
+
moveEntry(path.join(root, entry), path.join(opsDir, entry));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const excluded = new Set([
|
|
173
|
+
".git",
|
|
174
|
+
config.WORKSPACE_MANIFEST,
|
|
175
|
+
manifest.appDir,
|
|
176
|
+
manifest.opsDir,
|
|
177
|
+
".env",
|
|
178
|
+
".env.example",
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
const topLevel = fs.readdirSync(root, { withFileTypes: true });
|
|
182
|
+
for (const entry of topLevel) {
|
|
183
|
+
if (excluded.has(entry.name)) continue;
|
|
184
|
+
moveEntry(path.join(root, entry.name), path.join(appDir, entry.name));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
ensureRootGitignore(root);
|
|
188
|
+
stripOpsScripts(path.join(appDir, "package.json"));
|
|
189
|
+
|
|
190
|
+
const context = config.createSplitContext(root, manifest);
|
|
191
|
+
const control = config.loadControl(context);
|
|
192
|
+
control.meta = control.meta || {};
|
|
193
|
+
control.meta.workspace = {
|
|
194
|
+
layout: "split",
|
|
195
|
+
workspaceRoot: ".",
|
|
196
|
+
appDir: manifest.appDir,
|
|
197
|
+
opsDir: manifest.opsDir,
|
|
198
|
+
developmentBranch: manifest.branches.development,
|
|
199
|
+
publishBranch: manifest.branches.publish,
|
|
200
|
+
publishMode: manifest.publish.mode,
|
|
201
|
+
};
|
|
202
|
+
control.meta.environment = {
|
|
203
|
+
...(control.meta.environment || {}),
|
|
204
|
+
rootEnvFile: ".env",
|
|
205
|
+
exampleFile: ".env.example",
|
|
206
|
+
appBridgeFile: "app/.env",
|
|
207
|
+
bridgeMode: "symlink-or-copy",
|
|
208
|
+
requiredKeys: control.meta.environment?.requiredKeys || [],
|
|
209
|
+
optionalKeys: control.meta.environment?.optionalKeys || [],
|
|
210
|
+
lastAuditAt: control.meta.environment?.lastAuditAt || null,
|
|
211
|
+
};
|
|
212
|
+
config.saveControl(context, control);
|
|
213
|
+
env.syncEnvironment(context, control);
|
|
214
|
+
const controlApi = require("./control");
|
|
215
|
+
controlApi.syncDocs(context, config.loadControl(context));
|
|
216
|
+
controlApi.refreshRepoRuntime(context, { quiet: true });
|
|
217
|
+
|
|
218
|
+
const hookConfig = git(["config", "core.hooksPath", "ops/.githooks"], root);
|
|
219
|
+
if (hookConfig.status !== 0) {
|
|
220
|
+
throw new Error(hookConfig.stderr || "Could not update git hooks path.");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
registry.registerProject(root);
|
|
224
|
+
return { root, backupBranch, context };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function status(contextOrRoot) {
|
|
228
|
+
const context = config.ensureContext(contextOrRoot);
|
|
229
|
+
console.log("Workspace:");
|
|
230
|
+
console.log(` Layout: ${context.layout}`);
|
|
231
|
+
console.log(` Root: ${context.workspaceRoot}`);
|
|
232
|
+
console.log(` App: ${context.appRoot}`);
|
|
233
|
+
console.log(` Ops: ${context.opsRoot}`);
|
|
234
|
+
if (context.manifestFile) {
|
|
235
|
+
console.log(` Manifest: ${context.manifestFile}`);
|
|
236
|
+
}
|
|
237
|
+
console.log(` Control: ${context.controlFile}`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function cmdStatus(root) {
|
|
241
|
+
status(root);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function cmdMigrate(root, args = []) {
|
|
245
|
+
const allowDirty = args.includes("--allow-dirty");
|
|
246
|
+
const result = migrateWorkspace(root, { allowDirty });
|
|
247
|
+
console.log(`Workspace migrated: ${result.root}`);
|
|
248
|
+
console.log(`Backup branch: ${result.backupBranch}`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
module.exports = {
|
|
252
|
+
OPS_ARTIFACTS,
|
|
253
|
+
buildManifest,
|
|
254
|
+
ensureRootGitignore,
|
|
255
|
+
stripOpsScripts,
|
|
256
|
+
migrateWorkspace,
|
|
257
|
+
status,
|
|
258
|
+
cmdStatus,
|
|
259
|
+
cmdMigrate,
|
|
260
|
+
};
|