@aipper/aiws 0.0.28 → 0.0.30

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 (267) hide show
  1. package/README.md +18 -2
  2. package/bin/aiws.js +2 -2
  3. package/dist/aiws-package.d.ts +4 -0
  4. package/dist/aiws-package.js +11 -0
  5. package/dist/aiws-package.js.map +1 -0
  6. package/dist/aiws-paths.d.ts +48 -0
  7. package/dist/aiws-paths.js +129 -0
  8. package/dist/aiws-paths.js.map +1 -0
  9. package/dist/backup.d.ts +27 -0
  10. package/dist/backup.js +125 -0
  11. package/dist/backup.js.map +1 -0
  12. package/dist/cli.d.ts +1 -0
  13. package/dist/cli.js +773 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/codex-prompts.d.ts +17 -0
  16. package/dist/codex-prompts.js +49 -0
  17. package/dist/codex-prompts.js.map +1 -0
  18. package/dist/codex-skills.d.ts +17 -0
  19. package/dist/codex-skills.js +75 -0
  20. package/dist/codex-skills.js.map +1 -0
  21. package/dist/commands/change-advice.d.ts +25 -0
  22. package/dist/commands/change-advice.js +197 -0
  23. package/dist/commands/change-advice.js.map +1 -0
  24. package/dist/commands/change-evidence-command.d.ts +29 -0
  25. package/dist/commands/change-evidence-command.js +213 -0
  26. package/dist/commands/change-evidence-command.js.map +1 -0
  27. package/dist/commands/change-evidence-entry.d.ts +16 -0
  28. package/dist/commands/change-evidence-entry.js +35 -0
  29. package/dist/commands/change-evidence-entry.js.map +1 -0
  30. package/dist/commands/change-evidence.d.ts +108 -0
  31. package/dist/commands/change-evidence.js +341 -0
  32. package/dist/commands/change-evidence.js.map +1 -0
  33. package/dist/commands/change-finish.d.ts +71 -0
  34. package/dist/commands/change-finish.js +387 -0
  35. package/dist/commands/change-finish.js.map +1 -0
  36. package/dist/commands/change-git-status.d.ts +22 -0
  37. package/dist/commands/change-git-status.js +50 -0
  38. package/dist/commands/change-git-status.js.map +1 -0
  39. package/dist/commands/change-lifecycle-entry.d.ts +29 -0
  40. package/{src → dist}/commands/change-lifecycle-entry.js +21 -28
  41. package/dist/commands/change-lifecycle-entry.js.map +1 -0
  42. package/dist/commands/change-lifecycle.d.ts +56 -0
  43. package/dist/commands/change-lifecycle.js +211 -0
  44. package/dist/commands/change-lifecycle.js.map +1 -0
  45. package/dist/commands/change-metrics-command.d.ts +12 -0
  46. package/dist/commands/change-metrics-command.js +110 -0
  47. package/dist/commands/change-metrics-command.js.map +1 -0
  48. package/dist/commands/change-next-command.d.ts +18 -0
  49. package/dist/commands/change-next-command.js +138 -0
  50. package/dist/commands/change-next-command.js.map +1 -0
  51. package/dist/commands/change-review-gates.d.ts +107 -0
  52. package/dist/commands/change-review-gates.js +329 -0
  53. package/dist/commands/change-review-gates.js.map +1 -0
  54. package/dist/commands/change-scope-gate.d.ts +21 -0
  55. package/dist/commands/change-scope-gate.js +32 -0
  56. package/dist/commands/change-scope-gate.js.map +1 -0
  57. package/dist/commands/change-start.d.ts +30 -0
  58. package/dist/commands/change-start.js +91 -0
  59. package/dist/commands/change-start.js.map +1 -0
  60. package/dist/commands/change-state-command.d.ts +3 -0
  61. package/dist/commands/change-state-command.js +32 -0
  62. package/dist/commands/change-state-command.js.map +1 -0
  63. package/dist/commands/change-status-command.d.ts +13 -0
  64. package/dist/commands/change-status-command.js +126 -0
  65. package/dist/commands/change-status-command.js.map +1 -0
  66. package/dist/commands/change-status-context.d.ts +58 -0
  67. package/dist/commands/change-status-context.js +166 -0
  68. package/dist/commands/change-status-context.js.map +1 -0
  69. package/dist/commands/change-task-stats.d.ts +24 -0
  70. package/dist/commands/change-task-stats.js +66 -0
  71. package/dist/commands/change-task-stats.js.map +1 -0
  72. package/dist/commands/change-validate-entry.d.ts +17 -0
  73. package/dist/commands/change-validate-entry.js +44 -0
  74. package/dist/commands/change-validate-entry.js.map +1 -0
  75. package/dist/commands/change-validate.d.ts +32 -0
  76. package/dist/commands/change-validate.js +128 -0
  77. package/dist/commands/change-validate.js.map +1 -0
  78. package/dist/commands/change.d.ts +322 -0
  79. package/dist/commands/change.js +1731 -0
  80. package/dist/commands/change.js.map +1 -0
  81. package/dist/commands/codex-install-prompts.d.ts +4 -0
  82. package/dist/commands/codex-install-prompts.js +68 -0
  83. package/dist/commands/codex-install-prompts.js.map +1 -0
  84. package/dist/commands/codex-install-skills.d.ts +4 -0
  85. package/dist/commands/codex-install-skills.js +74 -0
  86. package/dist/commands/codex-install-skills.js.map +1 -0
  87. package/dist/commands/codex-status-prompts.d.ts +4 -0
  88. package/dist/commands/codex-status-prompts.js +44 -0
  89. package/dist/commands/codex-status-prompts.js.map +1 -0
  90. package/dist/commands/codex-status-skills.d.ts +4 -0
  91. package/dist/commands/codex-status-skills.js +54 -0
  92. package/dist/commands/codex-status-skills.js.map +1 -0
  93. package/dist/commands/codex-uninstall-prompts.d.ts +4 -0
  94. package/dist/commands/codex-uninstall-prompts.js +51 -0
  95. package/dist/commands/codex-uninstall-prompts.js.map +1 -0
  96. package/dist/commands/codex-uninstall-skills.d.ts +4 -0
  97. package/dist/commands/codex-uninstall-skills.js +59 -0
  98. package/dist/commands/codex-uninstall-skills.js.map +1 -0
  99. package/dist/commands/dashboard.d.ts +222 -0
  100. package/dist/commands/dashboard.js +193 -0
  101. package/dist/commands/dashboard.js.map +1 -0
  102. package/dist/commands/hooks-install.d.ts +4 -0
  103. package/dist/commands/hooks-install.js +90 -0
  104. package/dist/commands/hooks-install.js.map +1 -0
  105. package/dist/commands/hooks-status.d.ts +4 -0
  106. package/dist/commands/hooks-status.js +89 -0
  107. package/dist/commands/hooks-status.js.map +1 -0
  108. package/dist/commands/init.d.ts +4 -0
  109. package/dist/commands/init.js +100 -0
  110. package/dist/commands/init.js.map +1 -0
  111. package/dist/commands/opencode-auto.d.ts +11 -0
  112. package/dist/commands/opencode-auto.js +158 -0
  113. package/dist/commands/opencode-auto.js.map +1 -0
  114. package/dist/commands/opencode-status.d.ts +4 -0
  115. package/dist/commands/opencode-status.js +75 -0
  116. package/dist/commands/opencode-status.js.map +1 -0
  117. package/dist/commands/opencode-supervise.d.ts +24 -0
  118. package/dist/commands/opencode-supervise.js +188 -0
  119. package/dist/commands/opencode-supervise.js.map +1 -0
  120. package/dist/commands/rollback.d.ts +4 -0
  121. package/dist/commands/rollback.js +12 -0
  122. package/dist/commands/rollback.js.map +1 -0
  123. package/dist/commands/update.d.ts +4 -0
  124. package/dist/commands/update.js +212 -0
  125. package/dist/commands/update.js.map +1 -0
  126. package/dist/commands/validate.d.ts +4 -0
  127. package/dist/commands/validate.js +222 -0
  128. package/dist/commands/validate.js.map +1 -0
  129. package/dist/commands/ws-commit.d.ts +5 -0
  130. package/dist/commands/ws-commit.js +39 -0
  131. package/dist/commands/ws-commit.js.map +1 -0
  132. package/dist/commands/ws-deliver.d.ts +5 -0
  133. package/dist/commands/ws-deliver.js +59 -0
  134. package/dist/commands/ws-deliver.js.map +1 -0
  135. package/dist/commands/ws-finish.d.ts +5 -0
  136. package/dist/commands/ws-finish.js +142 -0
  137. package/dist/commands/ws-finish.js.map +1 -0
  138. package/dist/commands/ws-handoff.d.ts +5 -0
  139. package/dist/commands/ws-handoff.js +35 -0
  140. package/dist/commands/ws-handoff.js.map +1 -0
  141. package/dist/commands/ws-migrate.d.ts +5 -0
  142. package/dist/commands/ws-migrate.js +41 -0
  143. package/dist/commands/ws-migrate.js.map +1 -0
  144. package/dist/commands/ws-plan-verify.d.ts +5 -0
  145. package/dist/commands/ws-plan-verify.js +38 -0
  146. package/dist/commands/ws-plan-verify.js.map +1 -0
  147. package/dist/commands/ws-pull.d.ts +5 -0
  148. package/dist/commands/ws-pull.js +26 -0
  149. package/dist/commands/ws-pull.js.map +1 -0
  150. package/dist/commands/ws-push.d.ts +5 -0
  151. package/dist/commands/ws-push.js +68 -0
  152. package/dist/commands/ws-push.js.map +1 -0
  153. package/dist/commands/ws-submodule-setup.d.ts +5 -0
  154. package/dist/commands/ws-submodule-setup.js +55 -0
  155. package/dist/commands/ws-submodule-setup.js.map +1 -0
  156. package/dist/commands/ws-verify-before-complete.d.ts +5 -0
  157. package/dist/commands/ws-verify-before-complete.js +35 -0
  158. package/dist/commands/ws-verify-before-complete.js.map +1 -0
  159. package/dist/dashboard/app.d.ts +1 -0
  160. package/dist/dashboard/app.js +370 -0
  161. package/dist/dashboard/app.js.map +1 -0
  162. package/dist/delegation/cli.d.ts +6 -0
  163. package/dist/delegation/cli.js +14 -0
  164. package/dist/delegation/cli.js.map +1 -0
  165. package/dist/delegation/index.d.ts +35 -0
  166. package/dist/delegation/index.js +118 -0
  167. package/dist/delegation/index.js.map +1 -0
  168. package/dist/errors.d.ts +8 -0
  169. package/dist/errors.js +11 -0
  170. package/dist/errors.js.map +1 -0
  171. package/dist/exec.d.ts +9 -0
  172. package/dist/exec.js +22 -0
  173. package/dist/exec.js.map +1 -0
  174. package/dist/fs.d.ts +9 -0
  175. package/dist/fs.js +62 -0
  176. package/dist/fs.js.map +1 -0
  177. package/dist/governance.d.ts +10 -0
  178. package/dist/governance.js +135 -0
  179. package/dist/governance.js.map +1 -0
  180. package/dist/hash.d.ts +3 -0
  181. package/dist/hash.js +13 -0
  182. package/dist/hash.js.map +1 -0
  183. package/dist/hooks/deploy-claude.d.ts +13 -0
  184. package/dist/hooks/deploy-claude.js +67 -0
  185. package/dist/hooks/deploy-claude.js.map +1 -0
  186. package/dist/journal.d.ts +22 -0
  187. package/dist/journal.js +112 -0
  188. package/dist/journal.js.map +1 -0
  189. package/dist/json-schema-lite.d.ts +22 -0
  190. package/dist/json-schema-lite.js +148 -0
  191. package/dist/json-schema-lite.js.map +1 -0
  192. package/dist/managed-blocks.d.ts +24 -0
  193. package/dist/managed-blocks.js +84 -0
  194. package/dist/managed-blocks.js.map +1 -0
  195. package/dist/manifest.d.ts +24 -0
  196. package/dist/manifest.js +145 -0
  197. package/dist/manifest.js.map +1 -0
  198. package/dist/opencode-env.d.ts +62 -0
  199. package/dist/opencode-env.js +178 -0
  200. package/dist/opencode-env.js.map +1 -0
  201. package/dist/path-utils.d.ts +2 -0
  202. package/dist/path-utils.js +8 -0
  203. package/dist/path-utils.js.map +1 -0
  204. package/dist/spec.d.ts +17 -0
  205. package/dist/spec.js +174 -0
  206. package/dist/spec.js.map +1 -0
  207. package/dist/template.d.ts +20 -0
  208. package/dist/template.js +123 -0
  209. package/dist/template.js.map +1 -0
  210. package/dist/workspace.d.ts +4 -0
  211. package/dist/workspace.js +19 -0
  212. package/dist/workspace.js.map +1 -0
  213. package/package.json +11 -3
  214. package/src/aiws-package.js +0 -15
  215. package/src/backup.js +0 -149
  216. package/src/cli.js +0 -647
  217. package/src/codex-prompts.js +0 -74
  218. package/src/codex-skills.js +0 -111
  219. package/src/commands/change-advice.js +0 -200
  220. package/src/commands/change-evidence-command.js +0 -242
  221. package/src/commands/change-evidence-entry.js +0 -40
  222. package/src/commands/change-evidence.js +0 -340
  223. package/src/commands/change-finish.js +0 -484
  224. package/src/commands/change-git-status.js +0 -53
  225. package/src/commands/change-lifecycle.js +0 -236
  226. package/src/commands/change-metrics-command.js +0 -110
  227. package/src/commands/change-next-command.js +0 -129
  228. package/src/commands/change-review-gates.js +0 -315
  229. package/src/commands/change-scope-gate.js +0 -34
  230. package/src/commands/change-start.js +0 -120
  231. package/src/commands/change-state-command.js +0 -40
  232. package/src/commands/change-status-command.js +0 -134
  233. package/src/commands/change-status-context.js +0 -202
  234. package/src/commands/change-task-stats.js +0 -64
  235. package/src/commands/change-validate-entry.js +0 -45
  236. package/src/commands/change-validate.js +0 -127
  237. package/src/commands/change.js +0 -2087
  238. package/src/commands/codex-install-prompts.js +0 -68
  239. package/src/commands/codex-install-skills.js +0 -74
  240. package/src/commands/codex-status-prompts.js +0 -55
  241. package/src/commands/codex-status-skills.js +0 -63
  242. package/src/commands/codex-uninstall-prompts.js +0 -55
  243. package/src/commands/codex-uninstall-skills.js +0 -62
  244. package/src/commands/dashboard.js +0 -205
  245. package/src/commands/hooks-install.js +0 -92
  246. package/src/commands/hooks-status.js +0 -95
  247. package/src/commands/init.js +0 -93
  248. package/src/commands/opencode-status.js +0 -61
  249. package/src/commands/rollback.js +0 -13
  250. package/src/commands/update.js +0 -133
  251. package/src/commands/validate.js +0 -222
  252. package/src/dashboard/app.js +0 -371
  253. package/src/errors.js +0 -15
  254. package/src/exec.js +0 -34
  255. package/src/fs.js +0 -91
  256. package/src/governance.js +0 -159
  257. package/src/hash.js +0 -25
  258. package/src/json-schema-lite.js +0 -164
  259. package/src/managed-blocks.js +0 -131
  260. package/src/manifest.js +0 -153
  261. package/src/opencode-env.js +0 -76
  262. package/src/path-utils.js +0 -20
  263. package/src/spec.js +0 -195
  264. package/src/template.js +0 -187
  265. package/src/workspace.js +0 -23
  266. /package/{src → dist}/dashboard/index.html +0 -0
  267. /package/{src → dist}/dashboard/style.css +0 -0
package/src/spec.js DELETED
@@ -1,195 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs/promises";
3
- import { createRequire } from "node:module";
4
- import { fileURLToPath } from "node:url";
5
- import { pathExists, readText } from "./fs.js";
6
- import { UserError } from "./errors.js";
7
- import { validateJsonSchemaLite } from "./json-schema-lite.js";
8
-
9
- const specJsonDocCache = new Map();
10
-
11
- /**
12
- * @returns {Promise<{ rootDir: string, version: string }>}
13
- */
14
- export async function loadSpecPackage() {
15
- const require = createRequire(import.meta.url);
16
-
17
- /** @type {string | null} */
18
- let pkgJsonPath = null;
19
- try {
20
- pkgJsonPath = require.resolve("@aipper/aiws-spec/package.json");
21
- } catch {
22
- pkgJsonPath = null;
23
- }
24
-
25
- /** @type {string} */
26
- let rootDir;
27
- if (pkgJsonPath) {
28
- rootDir = path.dirname(pkgJsonPath);
29
- } else {
30
- const here = fileURLToPath(import.meta.url);
31
- rootDir = path.resolve(path.dirname(here), "../../spec");
32
- const fallbackPkg = path.join(rootDir, "package.json");
33
- if (!(await pathExists(fallbackPkg))) {
34
- throw new UserError("Cannot locate @aipper/aiws-spec. Install it or run inside the monorepo.", {
35
- exitCode: 1,
36
- });
37
- }
38
- }
39
-
40
- const pkg = JSON.parse(await readText(path.join(rootDir, "package.json")));
41
- const version = String(pkg.version || "").trim() || "0.0.0";
42
- return { rootDir, version };
43
- }
44
-
45
- /**
46
- * @param {string} templateId
47
- */
48
- export async function loadTemplate(templateId) {
49
- if (!templateId || templateId.includes("..") || templateId.includes("/") || templateId.includes("\\")) {
50
- throw new UserError(`Invalid template id: ${templateId}`);
51
- }
52
-
53
- const spec = await loadSpecPackage();
54
- const templateDir = path.join(spec.rootDir, "templates", templateId);
55
- const manifestPath = path.join(templateDir, "manifest.json");
56
-
57
- try {
58
- await fs.access(manifestPath);
59
- } catch {
60
- throw new UserError(`Template not found: ${templateId}`, {
61
- details: `Missing: ${manifestPath}`,
62
- });
63
- }
64
-
65
- const manifest = JSON.parse(await readText(manifestPath));
66
- return { templateId, templateDir, manifest, specVersion: spec.version };
67
- }
68
-
69
- /**
70
- * @param {string} relPath
71
- */
72
- async function loadSpecJsonDoc(relPath) {
73
- const spec = await loadSpecPackage();
74
- const absPath = path.join(spec.rootDir, relPath);
75
- const cacheKey = `${spec.rootDir}:${relPath}`;
76
- if (specJsonDocCache.has(cacheKey)) {
77
- return { spec, data: specJsonDocCache.get(cacheKey), absPath };
78
- }
79
- const raw = await readText(absPath);
80
- let data;
81
- try {
82
- data = JSON.parse(raw);
83
- } catch (error) {
84
- throw new UserError(`Invalid JSON in spec doc: ${relPath}`, {
85
- details: error instanceof Error ? error.message : String(error),
86
- });
87
- }
88
- specJsonDocCache.set(cacheKey, data);
89
- return { spec, data, absPath };
90
- }
91
-
92
- async function loadValidatedSpecJsonDoc(relPath, schemaRelPath) {
93
- const loaded = await loadSpecJsonDoc(relPath);
94
- const { data: schema } = await loadSpecJsonDoc(schemaRelPath);
95
- validateJsonSchemaLite(loaded.data, schema, { source: loaded.absPath });
96
- return loaded;
97
- }
98
-
99
- export async function loadWorkflowGovernanceRules() {
100
- const relPath = path.join("docs", "workflow-governance-rules.json");
101
- const schemaRelPath = path.join("docs", "workflow-governance-rules.schema.json");
102
- const { spec, data } = await loadValidatedSpecJsonDoc(relPath, schemaRelPath);
103
- const governanceRules = data.governanceRules;
104
- const guidanceRules = data.guidanceRules;
105
- return {
106
- ok: true,
107
- source: "@aipper/aiws-spec/docs/workflow-governance-rules.json",
108
- specVersion: spec.version,
109
- version: Number(data?.version || 1),
110
- description: String(data?.description || ""),
111
- governanceRules,
112
- guidanceRules,
113
- };
114
- }
115
-
116
- export async function loadWorkflowStageContracts() {
117
- const relPath = path.join("docs", "workflow-stage-contracts.json");
118
- const schemaRelPath = path.join("docs", "workflow-stage-contracts.schema.json");
119
- const { spec, data } = await loadValidatedSpecJsonDoc(relPath, schemaRelPath);
120
- const stages = data.stages;
121
- return {
122
- ok: true,
123
- source: "@aipper/aiws-spec/docs/workflow-stage-contracts.json",
124
- specVersion: spec.version,
125
- version: Number(data?.version || 1),
126
- description: String(data?.description || ""),
127
- standardChain: Array.isArray(data?.standardChain) ? data.standardChain : [],
128
- notes: Array.isArray(data?.notes) ? data.notes : [],
129
- stages,
130
- };
131
- }
132
-
133
- export async function loadWorkflowRouterRules() {
134
- const relPath = path.join("docs", "workflow-router-rules.json");
135
- const schemaRelPath = path.join("docs", "workflow-router-rules.schema.json");
136
- const { spec, data } = await loadValidatedSpecJsonDoc(relPath, schemaRelPath);
137
- return {
138
- ok: true,
139
- source: "@aipper/aiws-spec/docs/workflow-router-rules.json",
140
- specVersion: spec.version,
141
- version: Number(data?.version || 1),
142
- title: String(data?.title || ""),
143
- description: String(data?.description || ""),
144
- truthFiles: Array.isArray(data?.truthFiles) ? data.truthFiles : [],
145
- bootstrapEntry: data.bootstrapEntry,
146
- universalSequence: Array.isArray(data?.universalSequence) ? data.universalSequence : [],
147
- routingRules: Array.isArray(data?.routingRules) ? data.routingRules : [],
148
- routeCases: Array.isArray(data?.routeCases) ? data.routeCases : [],
149
- clarificationTriggers: Array.isArray(data?.clarificationTriggers) ? data.clarificationTriggers : [],
150
- universalRules: Array.isArray(data?.universalRules) ? data.universalRules : [],
151
- notes: Array.isArray(data?.notes) ? data.notes : [],
152
- };
153
- }
154
-
155
- export async function loadWorkflowReviewGates() {
156
- const relPath = path.join("docs", "workflow-review-gates.json");
157
- const schemaRelPath = path.join("docs", "workflow-review-gates.schema.json");
158
- const { spec, data } = await loadValidatedSpecJsonDoc(relPath, schemaRelPath);
159
- return {
160
- ok: true,
161
- source: "@aipper/aiws-spec/docs/workflow-review-gates.json",
162
- specVersion: spec.version,
163
- version: Number(data?.version || 1),
164
- title: String(data?.title || ""),
165
- description: String(data?.description || ""),
166
- gates: Array.isArray(data?.gates) ? data.gates : [],
167
- unifiedRules: Array.isArray(data?.unifiedRules) ? data.unifiedRules : [],
168
- evidence: Array.isArray(data?.evidence) ? data.evidence : [],
169
- notes: Array.isArray(data?.notes) ? data.notes : [],
170
- };
171
- }
172
-
173
- export async function loadWorkflowDelegationContracts() {
174
- const relPath = path.join("docs", "workflow-delegation-contracts.json");
175
- const schemaRelPath = path.join("docs", "workflow-delegation-contracts.schema.json");
176
- const { spec, data } = await loadValidatedSpecJsonDoc(relPath, schemaRelPath);
177
- return {
178
- ok: true,
179
- source: "@aipper/aiws-spec/docs/workflow-delegation-contracts.json",
180
- specVersion: spec.version,
181
- version: Number(data?.version || 1),
182
- title: String(data?.title || ""),
183
- description: String(data?.description || ""),
184
- purpose: Array.isArray(data?.purpose) ? data.purpose : [],
185
- truthFiles: Array.isArray(data?.truthFiles) ? data.truthFiles : [],
186
- delegationFlow: Array.isArray(data?.delegationFlow) ? data.delegationFlow : [],
187
- roleTypes: Array.isArray(data?.roleTypes) ? data.roleTypes : [],
188
- artifactTargets: Array.isArray(data?.artifactTargets) ? data.artifactTargets : [],
189
- reviewConvergence: data?.reviewConvergence || {},
190
- fallbackMode: data?.fallbackMode || {},
191
- toolCapabilityMatrix: Array.isArray(data?.toolCapabilityMatrix) ? data.toolCapabilityMatrix : [],
192
- universalRules: Array.isArray(data?.universalRules) ? data.universalRules : [],
193
- notes: Array.isArray(data?.notes) ? data.notes : [],
194
- };
195
- }
package/src/template.js DELETED
@@ -1,187 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs/promises";
3
- import { listFilesRecursive, pathExists, copyFile, readText, writeText, ensureDir } from "./fs.js";
4
- import { normalizeRel, joinRel } from "./path-utils.js";
5
- import { normalizeNewlines } from "./hash.js";
6
- import { extractTemplateBlock, upsertManagedBlock } from "./managed-blocks.js";
7
- import { UserError } from "./errors.js";
8
-
9
- /**
10
- * Extract a leading YAML frontmatter chunk when present.
11
- *
12
- * @param {string} text normalized
13
- * @returns {{ chunk: string, rest: string } | null}
14
- */
15
- function extractLeadingFrontmatter(text) {
16
- const t = normalizeNewlines(text);
17
- if (!t.startsWith("---\n")) return null;
18
- const end = t.indexOf("\n---\n", 4);
19
- if (end === -1) return null;
20
- const closeEnd = end + "\n---\n".length;
21
- return {
22
- chunk: t.slice(0, closeEnd),
23
- rest: t.slice(closeEnd),
24
- };
25
- }
26
-
27
- /**
28
- * Keep command metadata in sync without overwriting managed-block files wholesale.
29
- *
30
- * @param {string} currentText normalized
31
- * @param {string} templateText normalized
32
- * @returns {{ nextText: string, changed: boolean }}
33
- */
34
- function syncLeadingFrontmatter(currentText, templateText) {
35
- const templateFm = extractLeadingFrontmatter(templateText);
36
- if (!templateFm) return { nextText: currentText, changed: false };
37
-
38
- const currentFm = extractLeadingFrontmatter(currentText);
39
- if (!currentFm) {
40
- const nextText = `${templateFm.chunk}${currentText}`;
41
- return { nextText, changed: nextText !== currentText };
42
- }
43
-
44
- const nextText = `${templateFm.chunk}${currentFm.rest}`;
45
- return { nextText, changed: nextText !== currentText };
46
- }
47
-
48
- /**
49
- * Template file candidates for a given manifest/workspace path.
50
- *
51
- * NOTE: npm excludes files named `.gitignore` from published tarballs, even when placed under templates/.
52
- * We store it as `gitignore` in templates and map it back at runtime.
53
- *
54
- * @param {string} relPosix
55
- * @returns {string[]}
56
- */
57
- function templateRelCandidates(relPosix) {
58
- const rel = normalizeRel(relPosix);
59
- if (!rel) return [];
60
- /** @type {string[]} */
61
- const out = [rel];
62
- if (rel === ".gitignore" || rel.endsWith("/.gitignore")) {
63
- out.push(rel.replace(/(^|\/)\.gitignore$/, "$1gitignore"));
64
- }
65
- return Array.from(new Set(out));
66
- }
67
-
68
- /**
69
- * Resolve a template source file path for a given workspace-relative path.
70
- *
71
- * @param {string} templateDir
72
- * @param {string} relPosix
73
- */
74
- async function resolveTemplateSourcePath(templateDir, relPosix) {
75
- for (const cand of templateRelCandidates(relPosix)) {
76
- const abs = templatePath(templateDir, cand);
77
- if (await pathExists(abs)) return abs;
78
- }
79
- return templatePath(templateDir, relPosix);
80
- }
81
-
82
- /**
83
- * Expand manifest paths, supporting patterns ending with `/**`.
84
- *
85
- * @param {string} templateDir
86
- * @param {string[]} entries
87
- */
88
- export async function expandManifestEntries(templateDir, entries) {
89
- /** @type {Set<string>} */
90
- const out = new Set();
91
-
92
- for (const raw of entries) {
93
- const e = normalizeRel(raw);
94
- if (!e) continue;
95
- if (e.includes("**")) {
96
- const idx = e.indexOf("**");
97
- const prefix = e.slice(0, idx).replace(/\/+$/, "");
98
- if (!prefix) continue;
99
- const files = await listFilesRecursive(templateDir, prefix);
100
- for (const f of files) out.add(normalizeRel(f));
101
- continue;
102
- }
103
- out.add(e);
104
- }
105
-
106
- return Array.from(out).sort();
107
- }
108
-
109
- /**
110
- * @param {string} templateDir
111
- * @param {string} relPosix
112
- */
113
- export function templatePath(templateDir, relPosix) {
114
- const rel = normalizeRel(relPosix);
115
- return path.join(templateDir, ...rel.split("/"));
116
- }
117
-
118
- /**
119
- * Copy a template file to workspace, creating parent directories.
120
- *
121
- * @param {{ templateDir: string, workspaceRoot: string, relPosix: string, chmod?: number }} options
122
- */
123
- export async function copyTemplateFileToWorkspace(options) {
124
- const rel = normalizeRel(options.relPosix);
125
- const src = await resolveTemplateSourcePath(options.templateDir, rel);
126
- const dest = joinRel(options.workspaceRoot, rel);
127
- if (!(await pathExists(src))) {
128
- const tried = templateRelCandidates(rel).map((c) => templatePath(options.templateDir, c));
129
- throw new UserError(`Template file missing: ${options.relPosix}`, { details: `Tried:\n- ${tried.join("\n- ")}` });
130
- }
131
- await copyFile(src, dest, typeof options.chmod === "number" ? { chmod: options.chmod } : undefined);
132
- }
133
-
134
- /**
135
- * Upsert one or more managed blocks from template into an existing workspace file.
136
- *
137
- * @param {{ templateDir: string, workspaceRoot: string, fileRel: string, blockIds: string[], insertIfMissing: boolean }} options
138
- * @returns {Promise<{ changed: boolean }>}
139
- */
140
- export async function applyManagedBlocksFromTemplate(options) {
141
- const fileRel = normalizeRel(options.fileRel);
142
- const dest = joinRel(options.workspaceRoot, fileRel);
143
- const src = await resolveTemplateSourcePath(options.templateDir, fileRel);
144
-
145
- if (!(await pathExists(src))) {
146
- const tried = templateRelCandidates(fileRel).map((c) => templatePath(options.templateDir, c));
147
- throw new UserError(`Template file missing: ${fileRel}`, { details: `Tried:\n- ${tried.join("\n- ")}` });
148
- }
149
- const templateText = normalizeNewlines(await readText(src));
150
-
151
- if (!(await pathExists(dest))) {
152
- await ensureDir(path.dirname(dest));
153
- await writeText(dest, templateText);
154
- return { changed: true };
155
- }
156
-
157
- const currentText = normalizeNewlines(await readText(dest));
158
- const syncedFrontmatter = syncLeadingFrontmatter(currentText, templateText);
159
- let nextText = syncedFrontmatter.nextText;
160
- let anyChanged = syncedFrontmatter.changed;
161
-
162
- for (const blockId of options.blockIds) {
163
- const { blockChunk, innerText } = extractTemplateBlock(templateText, blockId);
164
- const res = upsertManagedBlock(nextText, blockId, innerText, {
165
- insertIfMissing: options.insertIfMissing,
166
- templateBlockChunk: blockChunk,
167
- });
168
- nextText = res.nextText;
169
- if (res.changed) anyChanged = true;
170
- }
171
-
172
- if (anyChanged) {
173
- await writeText(dest, nextText);
174
- }
175
- return { changed: anyChanged };
176
- }
177
-
178
- /**
179
- * Ensure workspace has a directory.
180
- *
181
- * @param {string} workspaceRoot
182
- * @param {string} relPosix
183
- */
184
- export async function ensureWorkspaceDir(workspaceRoot, relPosix) {
185
- const abs = joinRel(workspaceRoot, relPosix);
186
- await fs.mkdir(abs, { recursive: true });
187
- }
package/src/workspace.js DELETED
@@ -1,23 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs/promises";
3
- import { pathExists } from "./fs.js";
4
- import { UserError } from "./errors.js";
5
-
6
- /**
7
- * @param {string} targetPath
8
- * @param {{ create?: boolean }=} options
9
- */
10
- export async function resolveWorkspaceRoot(targetPath, options) {
11
- const abs = path.resolve(process.cwd(), targetPath || ".");
12
- if (await pathExists(abs)) {
13
- const st = await fs.stat(abs);
14
- if (!st.isDirectory()) throw new UserError(`Not a directory: ${abs}`);
15
- return abs;
16
- }
17
- if (options?.create) {
18
- await fs.mkdir(abs, { recursive: true });
19
- return abs;
20
- }
21
- throw new UserError(`Path does not exist: ${abs}`);
22
- }
23
-
File without changes
File without changes