@shinnodua/agent-workflows 0.0.0-stage → 0.2.8

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 (190) hide show
  1. package/.agents/agents/backend-developer/agent.md +39 -0
  2. package/.agents/agents/frontend-developer/agent.md +42 -0
  3. package/.agents/agents/project-manager/agent.md +37 -0
  4. package/.agents/agents/tech-lead/agent.md +41 -0
  5. package/.agents/agents/ui-ux-designer/agent.md +41 -0
  6. package/.agents/skills/add-project/SKILL.md +90 -0
  7. package/.agents/skills/add-project/agents/openai.yaml +4 -0
  8. package/.agents/skills/add-project/references/save-protocol.md +90 -0
  9. package/.agents/skills/approve-plan/SKILL.md +86 -0
  10. package/.agents/skills/approve-plan/agents/openai.yaml +4 -0
  11. package/.agents/skills/approve-prd/SKILL.md +59 -0
  12. package/.agents/skills/approve-prd/agents/openai.yaml +4 -0
  13. package/.agents/skills/auto-mode/SKILL.md +103 -0
  14. package/.agents/skills/auto-mode/agents/openai.yaml +4 -0
  15. package/.agents/skills/create-design/SKILL.md +197 -0
  16. package/.agents/skills/create-design/agents/openai.yaml +4 -0
  17. package/.agents/skills/create-diagram/SKILL.md +83 -0
  18. package/.agents/skills/create-diagram/agents/openai.yaml +4 -0
  19. package/.agents/skills/create-plan/SKILL.md +104 -0
  20. package/.agents/skills/create-plan/agents/openai.yaml +4 -0
  21. package/.agents/skills/create-prd/SKILL.md +82 -0
  22. package/.agents/skills/create-prd/agents/openai.yaml +4 -0
  23. package/.agents/skills/griling-plan/SKILL.md +114 -0
  24. package/.agents/skills/griling-plan/agents/openai.yaml +4 -0
  25. package/.agents/skills/griling-prd/SKILL.md +91 -0
  26. package/.agents/skills/griling-prd/agents/openai.yaml +4 -0
  27. package/.agents/skills/package-installation/SKILL.md +67 -0
  28. package/.agents/skills/package-installation/agents/openai.yaml +4 -0
  29. package/.agents/skills/project-setup/SKILL.md +104 -0
  30. package/.agents/skills/project-setup/agents/openai.yaml +3 -0
  31. package/.agents/skills/research/SKILL.md +61 -0
  32. package/.agents/skills/research/agents/openai.yaml +4 -0
  33. package/.agents/skills/sprint-meeting/SKILL.md +230 -0
  34. package/.agents/skills/sprint-meeting/agents/openai.yaml +4 -0
  35. package/.claude/agents/backend-developer.md +7 -0
  36. package/.claude/agents/frontend-developer.md +7 -0
  37. package/.claude/agents/project-manager.md +7 -0
  38. package/.claude/agents/tech-lead.md +7 -0
  39. package/.claude/agents/ui-ux-designer.md +7 -0
  40. package/.claude/skills/add-project/SKILL.md +10 -0
  41. package/.claude/skills/approve-plan/SKILL.md +8 -0
  42. package/.claude/skills/approve-prd/SKILL.md +8 -0
  43. package/.claude/skills/auto-mode/SKILL.md +8 -0
  44. package/.claude/skills/create-design/SKILL.md +8 -0
  45. package/.claude/skills/create-diagram/SKILL.md +8 -0
  46. package/.claude/skills/create-plan/SKILL.md +8 -0
  47. package/.claude/skills/create-prd/SKILL.md +8 -0
  48. package/.claude/skills/griling-plan/SKILL.md +8 -0
  49. package/.claude/skills/griling-prd/SKILL.md +8 -0
  50. package/.claude/skills/package-installation/SKILL.md +8 -0
  51. package/.claude/skills/project-setup/SKILL.md +8 -0
  52. package/.claude/skills/research/SKILL.md +8 -0
  53. package/.claude/skills/sprint-meeting/SKILL.md +8 -0
  54. package/.codex/prompts/add-project.md +3 -0
  55. package/.codex/prompts/approve-plan.md +3 -0
  56. package/.codex/prompts/approve-prd.md +3 -0
  57. package/.codex/prompts/auto-mode.md +3 -0
  58. package/.codex/prompts/create-design.md +3 -0
  59. package/.codex/prompts/create-diagram.md +3 -0
  60. package/.codex/prompts/create-plan.md +3 -0
  61. package/.codex/prompts/create-prd.md +3 -0
  62. package/.codex/prompts/griling-plan.md +3 -0
  63. package/.codex/prompts/griling-prd.md +3 -0
  64. package/.codex/prompts/grilling-plan.md +3 -0
  65. package/.codex/prompts/project-setup.md +3 -0
  66. package/.codex/prompts/research.md +3 -0
  67. package/.codex/prompts/sprint-meeting.md +3 -0
  68. package/.gitmodules.example +9 -0
  69. package/AGENTS.md +84 -0
  70. package/CLAUDE.md +1 -0
  71. package/INSTALL.md +284 -0
  72. package/LICENSE +21 -0
  73. package/README.md +342 -2
  74. package/bin/postinstall.js +57 -0
  75. package/bin/workflows.js +1172 -0
  76. package/bin/workflows.test.mjs +682 -0
  77. package/commands/add-project.md +20 -0
  78. package/commands/approve-plan.md +25 -0
  79. package/commands/approve-prd.md +24 -0
  80. package/commands/auto-mode.md +15 -0
  81. package/commands/create-design.md +20 -0
  82. package/commands/create-diagram.md +16 -0
  83. package/commands/create-plan.md +22 -0
  84. package/commands/create-prd.md +16 -0
  85. package/commands/griling-plan.md +16 -0
  86. package/commands/griling-prd.md +16 -0
  87. package/commands/grilling-plan.md +16 -0
  88. package/commands/project-setup.md +16 -0
  89. package/commands/research.md +16 -0
  90. package/commands/sprint-meeting.md +16 -0
  91. package/dashboard/.agents/skills/coding-conventions/SKILL.md +76 -0
  92. package/dashboard/.agents/skills/coding-conventions/agents/openai.yaml +4 -0
  93. package/dashboard/.agents/skills/design-system-guideline/SKILL.md +51 -0
  94. package/dashboard/.agents/skills/design-system-guideline/agents/openai.yaml +4 -0
  95. package/dashboard/.agents/skills/lint-and-fix/SKILL.md +55 -0
  96. package/dashboard/.agents/skills/lint-and-fix/agents/openai.yaml +4 -0
  97. package/dashboard/.agents/skills/taste-ui/SKILL.md +45 -0
  98. package/dashboard/.agents/skills/taste-ui/agents/openai.yaml +4 -0
  99. package/dashboard/AGENTS.md +43 -0
  100. package/dashboard/bun.lock +352 -0
  101. package/dashboard/index.html +12 -0
  102. package/dashboard/package.json +32 -0
  103. package/dashboard/src/App.tsx +5 -0
  104. package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.module.css +85 -0
  105. package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.tsx +80 -0
  106. package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.module.css +25 -0
  107. package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.tsx +29 -0
  108. package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.module.css +29 -0
  109. package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.tsx +35 -0
  110. package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.module.css +85 -0
  111. package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.tsx +150 -0
  112. package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.module.css +41 -0
  113. package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.tsx +41 -0
  114. package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.module.css +25 -0
  115. package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.tsx +40 -0
  116. package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.module.css +330 -0
  117. package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.tsx +299 -0
  118. package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.module.css +74 -0
  119. package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.tsx +79 -0
  120. package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.module.css +133 -0
  121. package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.tsx +233 -0
  122. package/dashboard/src/features/task-status/components/Sidebar/Sidebar.module.css +53 -0
  123. package/dashboard/src/features/task-status/components/Sidebar/Sidebar.tsx +163 -0
  124. package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.module.css +41 -0
  125. package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.tsx +48 -0
  126. package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.module.css +97 -0
  127. package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.tsx +128 -0
  128. package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.module.css +9 -0
  129. package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.tsx +318 -0
  130. package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.module.css +221 -0
  131. package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.tsx +344 -0
  132. package/dashboard/src/features/task-status/taskStatusConfig.ts +100 -0
  133. package/dashboard/src/features/task-status/utils/actionItems.ts +247 -0
  134. package/dashboard/src/features/task-status/utils/artifactGrouping.ts +328 -0
  135. package/dashboard/src/features/task-status/utils/hardnessScanner.ts +406 -0
  136. package/dashboard/src/features/task-status/utils/lifecycle.ts +73 -0
  137. package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.module.css +11 -0
  138. package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.tsx +104 -0
  139. package/dashboard/src/features/task-status/utils/markdownLinks.ts +83 -0
  140. package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.module.css +74 -0
  141. package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.tsx +326 -0
  142. package/dashboard/src/features/task-status/utils/status.ts +7 -0
  143. package/dashboard/src/features/task-status/utils/test/actionItems.test.ts +134 -0
  144. package/dashboard/src/features/task-status/utils/test/artifactGrouping.test.ts +294 -0
  145. package/dashboard/src/features/task-status/utils/test/hardnessScanner.test.ts +138 -0
  146. package/dashboard/src/features/task-status/utils/test/lifecycle.test.ts +49 -0
  147. package/dashboard/src/features/task-status/utils/test/markdownInline.test.ts +41 -0
  148. package/dashboard/src/features/task-status/utils/test/markdownLinks.test.ts +158 -0
  149. package/dashboard/src/features/task-status/utils/test/workspaceMetadata.test.ts +37 -0
  150. package/dashboard/src/features/task-status/utils/workspaceMetadata.ts +175 -0
  151. package/dashboard/src/main.tsx +16 -0
  152. package/dashboard/src/shared/design-system.css +134 -0
  153. package/dashboard/src/shared/design-system.tsx +84 -0
  154. package/dashboard/src/styles.css +41 -0
  155. package/dashboard/src/types.ts +133 -0
  156. package/dashboard/src/workspace-artifacts.d.ts +9 -0
  157. package/dashboard/tsconfig.json +22 -0
  158. package/dashboard/vite.config.ts +579 -0
  159. package/designs/.gitkeep +1 -0
  160. package/docs/add-project-command-completion.md +117 -0
  161. package/docs/public-npm-registry-completion.md +104 -0
  162. package/docs/workflows.png +0 -0
  163. package/docs/workspace-template-setup.md +229 -0
  164. package/meeting-logs/.gitkeep +1 -0
  165. package/modules/.gitkeep +1 -0
  166. package/package.json +96 -5
  167. package/plans/.gitkeep +1 -0
  168. package/prds/.gitkeep +1 -0
  169. package/project/PROJECT.md +26 -0
  170. package/project/repositories.json +72 -0
  171. package/project/validation.json +9 -0
  172. package/project/workflows.json +20 -0
  173. package/research/.gitkeep +1 -0
  174. package/roles/backend-developer.md +26 -0
  175. package/roles/frontend-developer.md +25 -0
  176. package/roles/project-manager.md +42 -0
  177. package/roles/tech-lead.md +42 -0
  178. package/roles/ui-ux-designer.md +43 -0
  179. package/scripts/add-project.mjs +990 -0
  180. package/scripts/add-project.test.mjs +804 -0
  181. package/scripts/check-staged-security.mjs +97 -0
  182. package/scripts/check-staged-security.test.mjs +68 -0
  183. package/scripts/workspace-integrity.ts +220 -0
  184. package/templates/auto-mode-completion-summary-template.md +78 -0
  185. package/templates/meeting-log-template.md +177 -0
  186. package/templates/plan-template.md +219 -0
  187. package/templates/prd-template.md +106 -0
  188. package/templates/research-template.md +119 -0
  189. package/workflows.md +590 -0
  190. package/workspace.config.json +43 -0
@@ -0,0 +1,1172 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const packageRoot = path.resolve(
11
+ path.dirname(fileURLToPath(import.meta.url)),
12
+ "..",
13
+ );
14
+ const manifestDirectory = ".agent-workflows";
15
+ const manifestPath = path.join(manifestDirectory, "manifest.json");
16
+ const metadataPath = path.join(manifestDirectory, "metadata.json");
17
+ const packageJson = readJson(path.join(packageRoot, "package.json"));
18
+ const packageLocalPath = path.join(
19
+ "node_modules",
20
+ ...packageJson.name.split("/"),
21
+ );
22
+ const roleNames = [
23
+ "project-manager",
24
+ "tech-lead",
25
+ "ui-ux-designer",
26
+ "backend-developer",
27
+ "frontend-developer",
28
+ ];
29
+ const workflowSteps = [
30
+ "research",
31
+ "prd",
32
+ "design",
33
+ "meeting",
34
+ "planning",
35
+ "coding",
36
+ "validation",
37
+ ];
38
+
39
+ const managedPaths = [
40
+ "AGENTS.md",
41
+ "CLAUDE.md",
42
+ "workflows.md",
43
+ ".codex/prompts",
44
+ ".claude/skills",
45
+ ".claude/agents",
46
+ ".agents/agents",
47
+ ".agents/skills",
48
+ "commands",
49
+ "docs/workspace-template-setup.md",
50
+ "roles",
51
+ "templates",
52
+ ];
53
+
54
+ const scaffoldOnlyPaths = [
55
+ "workspace.config.json",
56
+ ".gitmodules.example",
57
+ "project/PROJECT.md",
58
+ "project/repositories.json",
59
+ "project/validation.json",
60
+ "project/workflows.json",
61
+ "prds/.gitkeep",
62
+ "plans/.gitkeep",
63
+ "designs/.gitkeep",
64
+ "research/.gitkeep",
65
+ "meeting-logs/.gitkeep",
66
+ "docs/.gitkeep",
67
+ "modules/.gitkeep",
68
+ ];
69
+
70
+ const [, , command = "help", ...args] = process.argv;
71
+
72
+ try {
73
+ if (command === "init") {
74
+ initWorkspace(resolveRoot(args));
75
+ } else if (command === "update") {
76
+ updateWorkspace(resolveRoot(args));
77
+ } else if (command === "dashboard") {
78
+ startDashboard(resolveRoot(args), args);
79
+ } else if (command === "integrity") {
80
+ runPackagedScript("scripts/workspace-integrity.ts", resolveRoot(args));
81
+ } else if (command === "check") {
82
+ runCheck(resolveRoot(args));
83
+ } else if (command === "auto") {
84
+ autoMode(resolveRoot(args), passthroughArgs(args));
85
+ } else if (command === "agents") {
86
+ const agentArgs = passthroughArgs(args);
87
+ if (agentArgs.length === 1 && agentArgs[0] === "sync") {
88
+ syncAgentModels(resolveRoot(args));
89
+ } else if (agentArgs[0] === "sync") {
90
+ syncAgentModelsCommand(resolveRoot(args), agentArgs.slice(1));
91
+ } else if (agentArgs[0] === "models") {
92
+ listAgentModels(agentArgs.slice(1));
93
+ } else if (agentArgs[0] === "resolve") {
94
+ resolveAgentModelCommand(resolveRoot(args), agentArgs.slice(1));
95
+ } else {
96
+ throw new Error(
97
+ "Usage: workflows agents sync [--format <codex|antigravity>] | models --format <runtime> | resolve <step> <role> --format <runtime> [--json] [--root <path>].",
98
+ );
99
+ }
100
+ } else {
101
+ printHelp();
102
+ }
103
+ } catch (error) {
104
+ console.error(
105
+ `workflows: ${error instanceof Error ? error.message : String(error)}`,
106
+ );
107
+ process.exitCode = 1;
108
+ }
109
+
110
+ function initWorkspace(root) {
111
+ ensureDirectory(root);
112
+ const configExisted = fs.existsSync(path.join(root, "workspace.config.json"));
113
+ const scaffolded = copyPaths(
114
+ root,
115
+ scaffoldOnlyPaths.filter(
116
+ (relativePath) => relativePath !== "workspace.config.json",
117
+ ),
118
+ { overwrite: false },
119
+ );
120
+ const prepared = prepareWorkspaceConfig(root);
121
+ const { models } = readModelConfiguration(root, prepared.config);
122
+ validateAutoModeConfig(prepared.config.autoMode);
123
+ if (prepared.changed) writeWorkspaceConfig(root, prepared.config);
124
+ if (!configExisted) scaffolded.push("workspace.config.json");
125
+ cleanupLegacyAutoMode(root);
126
+ const managed = copyPaths(root, managedPaths, { overwrite: false });
127
+ syncAgentModels(root, models);
128
+ mergePackageScripts(root);
129
+ writeManifest(root);
130
+
131
+ console.log(`Initialized Agent Workflows in ${root}`);
132
+ console.log(
133
+ `Wrote ${managed.length} managed workflow files and scaffolded ${scaffolded.length} project files.`,
134
+ );
135
+ console.log(
136
+ "Next: use /project-setup or $project-setup to configure this project's workflow profile.",
137
+ );
138
+ console.log(
139
+ "Restart or reload any active agent session so it can discover the local custom agent, command, and skill shims.",
140
+ );
141
+ }
142
+
143
+ function updateWorkspace(root) {
144
+ const manifest = loadManifest(root);
145
+ const prepared = prepareWorkspaceConfig(root);
146
+ const { models } = readModelConfiguration(root, prepared.config);
147
+ validateAutoModeConfig(prepared.config.autoMode);
148
+ const paths = [
149
+ ...new Set([...(manifest?.managedPaths ?? []), ...managedPaths]),
150
+ ].filter((relativePath) => relativePath !== "workspace.config.json");
151
+ if (prepared.changed) writeWorkspaceConfig(root, prepared.config);
152
+ cleanupLegacyAutoMode(root);
153
+ const managed = copyPaths(root, paths, { overwrite: true });
154
+ syncAgentModels(root, models);
155
+ writeManifest(root);
156
+
157
+ console.log(`Updated ${managed.length} managed workflow files in ${root}`);
158
+ if (prepared.changed) {
159
+ console.log("Added missing model defaults to workspace.config.json.");
160
+ }
161
+ console.log(
162
+ "Project profile files and existing artifacts were left unchanged.",
163
+ );
164
+ console.log(
165
+ "Restart or reload any active agent session so it can discover refreshed custom agent, command, and skill shims.",
166
+ );
167
+ }
168
+
169
+ function readWorkspaceConfig(root) {
170
+ const configPath = path.join(root, "workspace.config.json");
171
+ try {
172
+ return readJson(configPath);
173
+ } catch (error) {
174
+ throw new Error(
175
+ `workspace.config.json could not be read as JSON: ${error instanceof Error ? error.message : String(error)}`,
176
+ );
177
+ }
178
+ }
179
+
180
+ function prepareWorkspaceConfig(root) {
181
+ const configPath = path.join(root, "workspace.config.json");
182
+ const defaults = readJson(path.join(packageRoot, "workspace.config.json"));
183
+ if (!fs.existsSync(configPath)) {
184
+ const config = structuredClone(defaults);
185
+ config.autoMode = readLegacyAutoMode(root) ?? { enabled: false };
186
+ return { config, changed: true };
187
+ }
188
+ const config = readWorkspaceConfig(root);
189
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
190
+ throw new Error("workspace.config.json must contain a JSON object.");
191
+ }
192
+ let changed = false;
193
+ if (!Object.hasOwn(config, "autoMode")) {
194
+ const legacy = readLegacyAutoMode(root);
195
+ config.autoMode = legacy ?? { enabled: false };
196
+ changed = true;
197
+ }
198
+ validateAutoModeConfig(config.autoMode);
199
+ if (!Object.hasOwn(config, "agentModels")) {
200
+ config.agentModels = { ...defaults.agentModels };
201
+ changed = true;
202
+ } else if (
203
+ config.agentModels &&
204
+ typeof config.agentModels === "object" &&
205
+ !Array.isArray(config.agentModels)
206
+ ) {
207
+ for (const [role, model] of Object.entries(defaults.agentModels)) {
208
+ if (!Object.hasOwn(config.agentModels, role)) {
209
+ config.agentModels[role] = model;
210
+ changed = true;
211
+ }
212
+ }
213
+ }
214
+ if (!Object.hasOwn(config, "workflowModels")) {
215
+ config.workflowModels = structuredClone(defaults.workflowModels);
216
+ changed = true;
217
+ } else if (
218
+ config.workflowModels &&
219
+ typeof config.workflowModels === "object" &&
220
+ !Array.isArray(config.workflowModels)
221
+ ) {
222
+ for (const [step, selections] of Object.entries(defaults.workflowModels)) {
223
+ if (!Object.hasOwn(config.workflowModels, step)) {
224
+ config.workflowModels[step] = structuredClone(selections);
225
+ changed = true;
226
+ }
227
+ }
228
+ }
229
+ return { config, changed };
230
+ }
231
+
232
+ function readLegacyAutoMode(root) {
233
+ const target = path.join(root, metadataPath);
234
+ if (!fs.existsSync(target)) return undefined;
235
+ let metadata;
236
+ try {
237
+ metadata = readJson(target);
238
+ } catch (error) {
239
+ throw new Error(
240
+ `${metadataPath} could not be read during migration: ${error instanceof Error ? error.message : String(error)}`,
241
+ );
242
+ }
243
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
244
+ throw new Error(
245
+ `${metadataPath} must contain a JSON object during migration.`,
246
+ );
247
+ }
248
+ if (!Object.hasOwn(metadata, "autoMode")) return undefined;
249
+ validateAutoModeConfig(metadata.autoMode, metadataPath);
250
+ return structuredClone(metadata.autoMode);
251
+ }
252
+
253
+ function validateAutoModeConfig(autoMode, source = "workspace.config.json") {
254
+ if (
255
+ !autoMode ||
256
+ typeof autoMode !== "object" ||
257
+ Array.isArray(autoMode) ||
258
+ typeof autoMode.enabled !== "boolean" ||
259
+ (autoMode.updatedAt !== undefined && typeof autoMode.updatedAt !== "string")
260
+ ) {
261
+ throw new Error(`${source} has invalid autoMode configuration.`);
262
+ }
263
+ }
264
+
265
+ function cleanupLegacyAutoMode(root) {
266
+ const target = path.join(root, metadataPath);
267
+ if (!fs.existsSync(target)) return;
268
+ let metadata;
269
+ try {
270
+ metadata = readJson(target);
271
+ } catch {
272
+ return;
273
+ }
274
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata))
275
+ return;
276
+ if (!Object.hasOwn(metadata, "autoMode")) return;
277
+ delete metadata.autoMode;
278
+ if (Object.keys(metadata).length === 0) {
279
+ fs.unlinkSync(target);
280
+ return;
281
+ }
282
+ const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
283
+ try {
284
+ fs.writeFileSync(temporary, `${JSON.stringify(metadata, null, "\t")}\n`, {
285
+ flag: "wx",
286
+ });
287
+ fs.renameSync(temporary, target);
288
+ } finally {
289
+ if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
290
+ }
291
+ }
292
+
293
+ function writeWorkspaceConfig(root, config) {
294
+ const target = path.join(root, "workspace.config.json");
295
+ const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
296
+ try {
297
+ fs.writeFileSync(temporary, `${JSON.stringify(config, null, "\t")}\n`, {
298
+ flag: "wx",
299
+ });
300
+ fs.renameSync(temporary, target);
301
+ } finally {
302
+ if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
303
+ }
304
+ }
305
+
306
+ function readModelConfiguration(root, config = readWorkspaceConfig(root)) {
307
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
308
+ throw new Error("workspace.config.json must contain a JSON object.");
309
+ }
310
+ const configured = Object.hasOwn(config, "agentModels")
311
+ ? config.agentModels
312
+ : {};
313
+ if (
314
+ !configured ||
315
+ typeof configured !== "object" ||
316
+ Array.isArray(configured)
317
+ ) {
318
+ throw new Error("workspace.config.json agentModels must be an object.");
319
+ }
320
+ for (const role of Object.keys(configured)) {
321
+ if (!roleNames.includes(role)) {
322
+ throw new Error(
323
+ `workspace.config.json agentModels has unknown role ${JSON.stringify(role)}; expected ${roleNames.join(", ")}.`,
324
+ );
325
+ }
326
+ }
327
+ const models = {};
328
+ for (const role of roleNames) {
329
+ const selection = Object.hasOwn(configured, role)
330
+ ? configured[role]
331
+ : "inherit";
332
+ models[role] = parseModelSelection(selection, `agentModels.${role}`);
333
+ }
334
+ const configuredWorkflow = Object.hasOwn(config, "workflowModels")
335
+ ? config.workflowModels
336
+ : {};
337
+ if (
338
+ !configuredWorkflow ||
339
+ typeof configuredWorkflow !== "object" ||
340
+ Array.isArray(configuredWorkflow)
341
+ ) {
342
+ throw new Error("workspace.config.json workflowModels must be an object.");
343
+ }
344
+ const workflowModels = {};
345
+ for (const [step, selections] of Object.entries(configuredWorkflow)) {
346
+ if (!workflowSteps.includes(step)) {
347
+ throw new Error(
348
+ `workspace.config.json workflowModels has unknown step ${JSON.stringify(step)}; expected ${workflowSteps.join(", ")}.`,
349
+ );
350
+ }
351
+ if (
352
+ !selections ||
353
+ typeof selections !== "object" ||
354
+ Array.isArray(selections)
355
+ ) {
356
+ throw new Error(
357
+ `workspace.config.json workflowModels.${step} must be an object of role selections.`,
358
+ );
359
+ }
360
+ workflowModels[step] = {};
361
+ for (const [role, selection] of Object.entries(selections)) {
362
+ if (role !== "default" && !roleNames.includes(role)) {
363
+ throw new Error(
364
+ `workspace.config.json workflowModels.${step} has unknown role ${JSON.stringify(role)}; expected default or ${roleNames.join(", ")}.`,
365
+ );
366
+ }
367
+ workflowModels[step][role] = parseModelSelection(
368
+ selection,
369
+ `workflowModels.${step}.${role}`,
370
+ );
371
+ }
372
+ }
373
+ return { models, workflowModels };
374
+ }
375
+
376
+ function parseModelSelection(selection, key) {
377
+ if (typeof selection === "string") {
378
+ const model = validateModel(selection, key);
379
+ return { codex: model, antigravity: model, claude: model };
380
+ }
381
+ if (!selection || typeof selection !== "object" || Array.isArray(selection)) {
382
+ throw new Error(
383
+ `workspace.config.json ${key} has invalid model ${JSON.stringify(selection)}; use a model ID or runtime-keyed model values.`,
384
+ );
385
+ }
386
+ const keys = Object.keys(selection);
387
+ const legacyShape =
388
+ keys.length === 2 && keys.includes("agents") && keys.includes("claude");
389
+ if (
390
+ !keys.length ||
391
+ keys.some(
392
+ (runtime) =>
393
+ !["codex", "agents", "antigravity", "claude"].includes(runtime),
394
+ ) ||
395
+ (keys.includes("agents") && !legacyShape)
396
+ ) {
397
+ throw new Error(
398
+ `workspace.config.json ${key} must use codex, antigravity, and/or claude model keys. Legacy objects must contain both agents and claude keys.`,
399
+ );
400
+ }
401
+ if (keys.includes("agents") && keys.includes("codex")) {
402
+ throw new Error(
403
+ `workspace.config.json ${key} cannot contain both agents and codex.`,
404
+ );
405
+ }
406
+ const normalized = {
407
+ codex: "inherit",
408
+ antigravity: "inherit",
409
+ claude: "inherit",
410
+ ...selection,
411
+ };
412
+ if (Object.hasOwn(selection, "agents")) normalized.codex = selection.agents;
413
+ return {
414
+ codex: validateModel(normalized.codex, `${key}.codex`),
415
+ antigravity: validateModel(normalized.antigravity, `${key}.antigravity`),
416
+ claude: validateModel(normalized.claude, `${key}.claude`),
417
+ };
418
+ }
419
+
420
+ function validateModel(model, key) {
421
+ if (
422
+ typeof model !== "string" ||
423
+ !/^[A-Za-z0-9][A-Za-z0-9._/@-]*$/.test(model)
424
+ ) {
425
+ throw new Error(
426
+ `workspace.config.json ${key} has invalid model ${JSON.stringify(model)}; use a nonempty single-line model ID or inherit.`,
427
+ );
428
+ }
429
+ return model;
430
+ }
431
+
432
+ function syncAgentModelsCommand(root, args) {
433
+ let format = "codex";
434
+ for (let index = 0; index < args.length; index += 1) {
435
+ if (args[index] === "--format") {
436
+ format = normalizeAgentRuntime(args[++index]);
437
+ } else {
438
+ throw new Error(
439
+ `Unknown agents sync option ${JSON.stringify(args[index])}.`,
440
+ );
441
+ }
442
+ }
443
+ syncAgentModels(root, readModelConfiguration(root).models, format);
444
+ }
445
+
446
+ function syncAgentModels(
447
+ root,
448
+ models = readModelConfiguration(root).models,
449
+ format = "codex",
450
+ ) {
451
+ if (!["codex", "antigravity"].includes(format)) {
452
+ throw new Error("agents sync --format must be codex or antigravity.");
453
+ }
454
+ const changes = [];
455
+ const effectiveModels = Object.fromEntries(
456
+ roleNames.map((role) => [
457
+ role,
458
+ {
459
+ agents: validateRuntimeModel(
460
+ format,
461
+ models[role][format],
462
+ `base role ${role}`,
463
+ ),
464
+ claude: validateRuntimeModel(
465
+ "claude",
466
+ models[role].claude,
467
+ `base role ${role}`,
468
+ ),
469
+ },
470
+ ]),
471
+ );
472
+ for (const role of roleNames) {
473
+ for (const [format, relativePath] of [
474
+ ["agents", `.agents/agents/${role}/agent.md`],
475
+ ["claude", `.claude/agents/${role}.md`],
476
+ ]) {
477
+ const target = path.join(root, relativePath);
478
+ const source = fs.readFileSync(target, "utf8");
479
+ const frontmatterEnd = source.startsWith("---\n")
480
+ ? source.indexOf("\n---\n", 4)
481
+ : -1;
482
+ const frontmatter = source.slice(0, frontmatterEnd + 1);
483
+ const modelLines = frontmatter.match(/^model:.*$/gm);
484
+ if (frontmatterEnd < 0 || modelLines?.length !== 1) {
485
+ throw new Error(
486
+ `${relativePath} must have exactly one model frontmatter line.`,
487
+ );
488
+ }
489
+ const effective =
490
+ format === "claude"
491
+ ? effectiveModels[role].claude
492
+ : effectiveModels[role].agents;
493
+ const updated =
494
+ frontmatter.replace(/^model:.*$/m, `model: ${effective}`) +
495
+ source.slice(frontmatterEnd + 1);
496
+ changes.push({
497
+ target,
498
+ relativePath,
499
+ updated,
500
+ changed: updated !== source,
501
+ });
502
+ }
503
+ }
504
+ for (const change of changes) {
505
+ if (change.changed) fs.writeFileSync(change.target, change.updated);
506
+ }
507
+ for (const role of roleNames) {
508
+ const configured = models[role];
509
+ const effectiveAgent = effectiveModels[role].agents;
510
+ const roleChanges = changes.filter(
511
+ (change) =>
512
+ change.relativePath.includes(`/${role}/`) ||
513
+ change.relativePath.endsWith(`/${role}.md`),
514
+ );
515
+ console.log(
516
+ `${role}: ${format === "codex" ? "agents" : format}=${effectiveAgent}${effectiveAgent !== configured[format] ? ` (configured ${configured[format]})` : ""}, claude=${effectiveModels[role].claude}${effectiveModels[role].claude !== configured.claude ? ` (configured ${configured.claude})` : ""} (${roleChanges.some((change) => change.changed) ? "updated" : "already up to date"} in both agent formats)`,
517
+ );
518
+ }
519
+ console.log(
520
+ "Base role files are synchronized. Workflow-step overrides apply when a coordinator spawns a new agent; reload the runtime for changed base models.",
521
+ );
522
+ }
523
+
524
+ function resolveAgentModelCommand(root, args) {
525
+ const [step, role, ...options] = args;
526
+ let format;
527
+ let json = false;
528
+ for (let index = 0; index < options.length; index += 1) {
529
+ if (options[index] === "--format") {
530
+ format = options[++index];
531
+ } else if (options[index] === "--json") {
532
+ json = true;
533
+ } else {
534
+ throw new Error(
535
+ `Unknown agents resolve option ${JSON.stringify(options[index])}.`,
536
+ );
537
+ }
538
+ }
539
+ if (!workflowSteps.includes(step)) {
540
+ throw new Error(
541
+ `Unknown workflow step ${JSON.stringify(step)}; expected ${workflowSteps.join(", ")}.`,
542
+ );
543
+ }
544
+ if (!roleNames.includes(role)) {
545
+ throw new Error(
546
+ `Unknown agent role ${JSON.stringify(role)}; expected ${roleNames.join(", ")}.`,
547
+ );
548
+ }
549
+ if (!isAgentRuntime(format)) {
550
+ throw new Error(
551
+ "--format must be codex, antigravity, or claude (agents is a legacy alias for codex).",
552
+ );
553
+ }
554
+ const requestedFormat = format;
555
+ format = normalizeAgentRuntime(format);
556
+ const configuration = readModelConfiguration(root);
557
+ const resolution = resolveAgentModel(configuration, step, role, format);
558
+ const selectedModel = resolution.model;
559
+ resolution.model = validateRuntimeModel(
560
+ format,
561
+ resolution.model,
562
+ `${step} step for ${role}`,
563
+ );
564
+ if (resolution.model !== selectedModel) {
565
+ resolution.source = "invalid model fallback (runtime default)";
566
+ }
567
+ resolution.format = requestedFormat;
568
+ console.log(
569
+ json
570
+ ? JSON.stringify(resolution)
571
+ : `${resolution.model}${resolution.model === "inherit" ? " (runtime default)" : ""} (source: ${resolution.source}; runtime: ${format})`,
572
+ );
573
+ }
574
+
575
+ function readCodexModelCatalog() {
576
+ const result = spawnSync("codex", ["debug", "models"], {
577
+ encoding: "utf8",
578
+ stdio: ["ignore", "pipe", "ignore"],
579
+ });
580
+ if (result.error || result.status !== 0) return null;
581
+ try {
582
+ const catalog = JSON.parse(result.stdout);
583
+ const models = catalog.models
584
+ ?.filter(
585
+ (model) => model.visibility === "list" || model.visibility === "allon",
586
+ )
587
+ .map((model) => model.slug);
588
+ return Array.isArray(models) ? new Set(models) : null;
589
+ } catch {
590
+ return null;
591
+ }
592
+ }
593
+
594
+ function listAgentModels(args) {
595
+ let format;
596
+ let json = false;
597
+ for (let index = 0; index < args.length; index += 1) {
598
+ if (args[index] === "--format") format = args[++index];
599
+ else if (args[index] === "--json") json = true;
600
+ else
601
+ throw new Error(
602
+ `Unknown agents models option ${JSON.stringify(args[index])}.`,
603
+ );
604
+ }
605
+ if (!isAgentRuntime(format)) {
606
+ throw new Error(
607
+ "Usage: workflows agents models --format <codex|antigravity|claude> [--json].",
608
+ );
609
+ }
610
+ format = normalizeAgentRuntime(format);
611
+ if (format === "antigravity") {
612
+ const models = ["inherit", "flash", "pro"];
613
+ console.log(json ? JSON.stringify({ format, models }) : models.join("\n"));
614
+ return;
615
+ }
616
+ if (format === "claude") {
617
+ const note =
618
+ "Claude Code has no local model catalog; use its documented aliases such as sonnet or opus, or a full model ID.";
619
+ console.log(
620
+ json ? JSON.stringify({ format, catalogAvailable: false, note }) : note,
621
+ );
622
+ return;
623
+ }
624
+ const catalog = readCodexModelCatalog();
625
+ if (!catalog)
626
+ throw new Error("Could not read the installed Codex model catalog.");
627
+ const models = [...catalog].sort();
628
+ console.log(json ? JSON.stringify({ format, models }) : models.join("\n"));
629
+ }
630
+
631
+ function validateRuntimeModel(runtime, model, context) {
632
+ if (model === "inherit") return model;
633
+ if (runtime === "antigravity") {
634
+ if (["flash", "pro"].includes(model)) return model;
635
+ console.error(
636
+ `Warning: model ${JSON.stringify(model)} is not a supported Antigravity model tier for ${context}. Supported values are inherit, flash, and pro. Falling back to inherit (runtime default).`,
637
+ );
638
+ return "inherit";
639
+ }
640
+ if (runtime === "claude") {
641
+ console.error(
642
+ `Warning: cannot verify model ${JSON.stringify(model)} for ${context} because Claude Code does not expose a local model catalog; passing it through.`,
643
+ );
644
+ return model;
645
+ }
646
+ const catalog = readCodexModelCatalog();
647
+ if (!catalog) {
648
+ console.error(
649
+ `Warning: cannot verify Codex model ${JSON.stringify(model)} for ${context}; passing it through.`,
650
+ );
651
+ return model;
652
+ }
653
+ if (catalog.has(model)) return model;
654
+ const suggestion = [...catalog]
655
+ .map((candidate) => ({
656
+ candidate,
657
+ distance: editDistance(model, candidate),
658
+ }))
659
+ .sort((a, b) => a.distance - b.distance)[0];
660
+ const hint =
661
+ suggestion &&
662
+ suggestion.distance <= Math.max(2, Math.floor(model.length / 3))
663
+ ? ` Did you mean ${JSON.stringify(suggestion.candidate)}?`
664
+ : "";
665
+ console.error(
666
+ `Warning: model ${JSON.stringify(model)} is not in the installed Codex model catalog for ${context}.${hint} Falling back to inherit (runtime default).`,
667
+ );
668
+ return "inherit";
669
+ }
670
+
671
+ function isAgentRuntime(value) {
672
+ return ["codex", "agents", "antigravity", "claude"].includes(value);
673
+ }
674
+
675
+ function normalizeAgentRuntime(value) {
676
+ if (!isAgentRuntime(value)) {
677
+ throw new Error(
678
+ "Expected codex, antigravity, or claude (agents is a legacy alias for codex).",
679
+ );
680
+ }
681
+ return value === "agents" ? "codex" : value;
682
+ }
683
+
684
+ function editDistance(left, right) {
685
+ const row = Array.from({ length: right.length + 1 }, (_, index) => index);
686
+ for (let i = 1; i <= left.length; i += 1) {
687
+ let diagonal = row[0];
688
+ row[0] = i;
689
+ for (let j = 1; j <= right.length; j += 1) {
690
+ const previous = row[j];
691
+ row[j] = Math.min(
692
+ row[j] + 1,
693
+ row[j - 1] + 1,
694
+ diagonal + (left[i - 1] === right[j - 1] ? 0 : 1),
695
+ );
696
+ diagonal = previous;
697
+ }
698
+ }
699
+ return row[right.length];
700
+ }
701
+
702
+ function resolveAgentModel(configuration, step, role, format) {
703
+ const requestedFormat = format;
704
+ format = normalizeAgentRuntime(format);
705
+ const stepModels = configuration.workflowModels[step] ?? {};
706
+ for (const [source, selection] of [
707
+ [`workflowModels.${step}.${role}`, stepModels[role]],
708
+ [`workflowModels.${step}.default`, stepModels.default],
709
+ [`agentModels.${role}`, configuration.models[role]],
710
+ ]) {
711
+ if (selection) {
712
+ return {
713
+ step,
714
+ role,
715
+ format: requestedFormat,
716
+ model: selection[format],
717
+ source,
718
+ };
719
+ }
720
+ }
721
+ return {
722
+ step,
723
+ role,
724
+ format: requestedFormat,
725
+ model: "inherit",
726
+ source: "runtime default",
727
+ };
728
+ }
729
+
730
+ function startDashboard(root, args) {
731
+ const dashboardArgs = passthroughArgs(args);
732
+ const result = spawnSync(
733
+ "bun",
734
+ [
735
+ "run",
736
+ "--cwd",
737
+ path.join(packageRoot, "dashboard"),
738
+ "dev",
739
+ ...dashboardArgs,
740
+ ],
741
+ {
742
+ env: {
743
+ ...process.env,
744
+ WORKFLOWS_WORKSPACE_ROOT: root,
745
+ },
746
+ stdio: "inherit",
747
+ },
748
+ );
749
+
750
+ process.exit(result.status ?? 1);
751
+ }
752
+
753
+ function runCheck(root) {
754
+ const configPath = path.join(root, "workspace.config.json");
755
+ if (fs.existsSync(configPath)) {
756
+ const config = readWorkspaceConfig(root);
757
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
758
+ throw new Error("workspace.config.json must contain a JSON object.");
759
+ }
760
+ readModelConfiguration(root, config);
761
+ if (Object.hasOwn(config, "autoMode")) {
762
+ validateAutoModeConfig(config.autoMode);
763
+ }
764
+ }
765
+ const commands = [
766
+ // `check --formatter-enabled=false` can be overridden by consumer config.
767
+ [resolvePackageBin("@biomejs/biome"), ["lint", root]],
768
+ ["bun", [path.join(packageRoot, "scripts/workspace-integrity.ts")]],
769
+ ];
770
+
771
+ for (const [binary, commandArgs] of commands) {
772
+ const result = spawnSync(binary, commandArgs, {
773
+ cwd: root,
774
+ env: {
775
+ ...process.env,
776
+ WORKFLOWS_WORKSPACE_ROOT: root,
777
+ },
778
+ stdio: "inherit",
779
+ });
780
+ if (result.status !== 0) {
781
+ process.exit(result.status ?? 1);
782
+ }
783
+ }
784
+ }
785
+
786
+ function runPackagedScript(scriptPath, root) {
787
+ const result = spawnSync("bun", [path.join(packageRoot, scriptPath)], {
788
+ cwd: root,
789
+ env: {
790
+ ...process.env,
791
+ WORKFLOWS_WORKSPACE_ROOT: root,
792
+ },
793
+ stdio: "inherit",
794
+ });
795
+
796
+ process.exit(result.status ?? 1);
797
+ }
798
+
799
+ function autoMode(root, args) {
800
+ const [action = "status", ...extra] = args;
801
+ if (extra.length > 0 || !["on", "off", "toggle", "status"].includes(action)) {
802
+ throw new Error(
803
+ "Usage: workflows auto on|off|toggle|status [--root <path>].",
804
+ );
805
+ }
806
+
807
+ const prepared = prepareWorkspaceConfig(root);
808
+ const config = prepared.config;
809
+ validateAutoModeConfig(config.autoMode);
810
+ const target = path.join(root, "workspace.config.json");
811
+
812
+ if (action !== "status") {
813
+ const enabled =
814
+ action === "toggle" ? !config.autoMode.enabled : action === "on";
815
+ config.autoMode = {
816
+ ...config.autoMode,
817
+ enabled,
818
+ updatedAt: new Date().toISOString(),
819
+ };
820
+ writeWorkspaceConfig(root, config);
821
+ } else if (prepared.changed) {
822
+ writeWorkspaceConfig(root, config);
823
+ }
824
+ cleanupLegacyAutoMode(root);
825
+
826
+ const enabled =
827
+ action === "status" ? config.autoMode.enabled : config.autoMode.enabled;
828
+ console.log(`Auto mode: ${enabled ? "on" : "off"} (${target})`);
829
+ }
830
+
831
+ function copyPaths(root, relativePaths, options) {
832
+ const written = [];
833
+
834
+ for (const relativePath of relativePaths) {
835
+ const source = path.join(packageRoot, relativePath);
836
+ if (!fs.existsSync(source)) {
837
+ continue;
838
+ }
839
+
840
+ if (fs.statSync(source).isDirectory()) {
841
+ for (const filePath of walkFiles(source)) {
842
+ const nestedRelativePath = path.relative(packageRoot, filePath);
843
+ if (writeManagedFile(root, nestedRelativePath, options)) {
844
+ written.push(nestedRelativePath);
845
+ }
846
+ }
847
+ continue;
848
+ }
849
+
850
+ if (writeManagedFile(root, relativePath, options)) {
851
+ written.push(relativePath);
852
+ }
853
+ }
854
+
855
+ return written;
856
+ }
857
+
858
+ function writeManagedFile(root, relativePath, options) {
859
+ const source = path.join(packageRoot, relativePath);
860
+ const target = path.join(root, relativePath);
861
+
862
+ if (!options.overwrite && fs.existsSync(target)) {
863
+ return false;
864
+ }
865
+
866
+ fs.mkdirSync(path.dirname(target), { recursive: true });
867
+ if (shouldWriteReferenceShim(relativePath)) {
868
+ fs.writeFileSync(target, buildReferenceShim(root, relativePath));
869
+ } else {
870
+ fs.copyFileSync(source, target);
871
+ }
872
+ return true;
873
+ }
874
+
875
+ function shouldWriteReferenceShim(relativePath) {
876
+ const normalized = toPosixPath(relativePath);
877
+ if (normalized === "AGENTS.md" || normalized === "workflows.md") return true;
878
+ if (normalized === "docs/workspace-template-setup.md") return true;
879
+ if (normalized.startsWith("commands/") && normalized.endsWith(".md")) {
880
+ return true;
881
+ }
882
+ if (normalized.startsWith(".codex/prompts/") && normalized.endsWith(".md")) {
883
+ return true;
884
+ }
885
+ if (normalized.startsWith(".agents/agents/") && normalized.endsWith(".md")) {
886
+ return true;
887
+ }
888
+ if (
889
+ normalized.startsWith(".agents/skills/") &&
890
+ normalized.endsWith("SKILL.md")
891
+ ) {
892
+ return true;
893
+ }
894
+ if (
895
+ (normalized.startsWith("roles/") || normalized.startsWith("templates/")) &&
896
+ normalized.endsWith(".md")
897
+ ) {
898
+ return true;
899
+ }
900
+ return false;
901
+ }
902
+
903
+ function buildReferenceShim(root, relativePath) {
904
+ const normalized = toPosixPath(relativePath);
905
+ const packageSourceRoot = packageSourceRootReference(root);
906
+ const packagePath = toPosixPath(path.join(packageSourceRoot, normalized));
907
+ const source = fs.readFileSync(path.join(packageRoot, normalized), "utf8");
908
+
909
+ if (
910
+ normalized.startsWith(".agents/skills/") &&
911
+ normalized.endsWith("SKILL.md")
912
+ ) {
913
+ return buildSkillShim(normalized, packagePath, packageSourceRoot, source);
914
+ }
915
+
916
+ if (normalized.startsWith(".codex/prompts/")) {
917
+ return buildPromptShim(normalized, packagePath, packageSourceRoot);
918
+ }
919
+
920
+ if (normalized.startsWith(".agents/agents/")) {
921
+ return buildAgentShim(normalized, packagePath, packageSourceRoot, source);
922
+ }
923
+
924
+ return buildMarkdownShim(normalized, packagePath, packageSourceRoot);
925
+ }
926
+
927
+ function buildSkillShim(relativePath, packagePath, packageSourceRoot, source) {
928
+ const frontmatter = extractFrontmatter(source);
929
+ const title = path.basename(path.dirname(relativePath));
930
+ return `${frontmatter ?? ""}# ${title}
931
+
932
+ This local file is an Agent Workflows discovery shim.
933
+
934
+ Packaged source of truth:
935
+
936
+ \`${packagePath}\`
937
+
938
+ Read the packaged source completely and follow it as this skill's instructions.
939
+ When the packaged source references reusable files such as \`AGENTS.md\`,
940
+ \`workflows.md\`, \`roles/...\`, \`templates/...\`, \`commands/...\`,
941
+ \`.codex/prompts/...\`, \`.agents/agents/...\`, or \`.agents/skills/...\`,
942
+ resolve those paths under
943
+ \`${packageSourceRoot}\` unless the instruction explicitly says to use the
944
+ consuming project's \`project/\`, \`prds/\`, \`plans/\`, \`designs/\`,
945
+ \`research/\`, \`meeting-logs/\`, \`docs/\`, or \`modules/\` paths.
946
+ `;
947
+ }
948
+
949
+ function buildPromptShim(relativePath, packagePath, packageSourceRoot) {
950
+ const commandName = path.basename(relativePath, ".md");
951
+ return `Use the packaged Agent Workflows slash prompt for \`${commandName}\`.
952
+
953
+ Packaged source of truth:
954
+
955
+ \`${packagePath}\`
956
+
957
+ Read the packaged prompt and any skill it delegates to from
958
+ \`${packageSourceRoot}\`, then run it with this request:
959
+
960
+ $ARGUMENTS
961
+ `;
962
+ }
963
+
964
+ function buildAgentShim(relativePath, packagePath, packageSourceRoot, source) {
965
+ const frontmatter = extractFrontmatter(source);
966
+ const title = path.basename(path.dirname(relativePath));
967
+ return `${frontmatter ?? ""}# ${title}
968
+
969
+ This local file is an Agent Workflows custom-agent discovery shim.
970
+
971
+ Packaged source of truth:
972
+
973
+ \`${packagePath}\`
974
+
975
+ Read the packaged custom-agent definition completely and follow it as this
976
+ agent's instructions. When the packaged source references reusable files such as
977
+ \`AGENTS.md\`, \`workflows.md\`, \`roles/...\`, \`templates/...\`,
978
+ \`commands/...\`, \`.codex/prompts/...\`, \`.agents/agents/...\`, or
979
+ \`.agents/skills/...\`, resolve those paths under \`${packageSourceRoot}\`
980
+ unless the instruction explicitly says to use the consuming project's
981
+ \`project/\`, \`prds/\`, \`plans/\`, \`designs/\`, \`research/\`,
982
+ \`meeting-logs/\`, \`docs/\`, or \`modules/\` paths.
983
+ `;
984
+ }
985
+
986
+ function buildMarkdownShim(relativePath, packagePath, packageSourceRoot) {
987
+ const title = path.basename(relativePath, path.extname(relativePath));
988
+ return `# ${title}
989
+
990
+ This local file is an Agent Workflows reference shim.
991
+
992
+ Packaged source of truth:
993
+
994
+ \`${packagePath}\`
995
+
996
+ Read and use the packaged file instead of this shim. When that file references
997
+ other reusable Agent Workflows files, resolve them under \`${packageSourceRoot}\`.
998
+ Project-owned files such as \`project/\`, \`prds/\`, \`plans/\`, \`designs/\`,
999
+ \`research/\`, \`meeting-logs/\`, \`docs/\`, and \`modules/\` remain local to
1000
+ this consuming workspace.
1001
+ `;
1002
+ }
1003
+
1004
+ function extractFrontmatter(source) {
1005
+ if (!source.startsWith("---\n")) return undefined;
1006
+ const endIndex = source.indexOf("\n---", 4);
1007
+ if (endIndex < 0) return undefined;
1008
+ return `${source.slice(0, endIndex + 5).trim()}\n\n`;
1009
+ }
1010
+
1011
+ function packageSourceRootReference(root) {
1012
+ const localPackageRoot = path.join(root, packageLocalPath);
1013
+ if (path.resolve(localPackageRoot) === packageRoot) {
1014
+ return packageLocalPath;
1015
+ }
1016
+
1017
+ const relativePackageRoot = path.relative(root, packageRoot);
1018
+ if (
1019
+ relativePackageRoot &&
1020
+ !relativePackageRoot.startsWith("..") &&
1021
+ !path.isAbsolute(relativePackageRoot)
1022
+ ) {
1023
+ return relativePackageRoot;
1024
+ }
1025
+
1026
+ return packageRoot;
1027
+ }
1028
+
1029
+ function toPosixPath(filePath) {
1030
+ return filePath.split(path.sep).join("/");
1031
+ }
1032
+
1033
+ function mergePackageScripts(root) {
1034
+ const packagePath = path.join(root, "package.json");
1035
+ const packageData = fs.existsSync(packagePath)
1036
+ ? readJson(packagePath)
1037
+ : { private: true };
1038
+ const scripts = {
1039
+ ...(packageData.scripts ?? {}),
1040
+ "workspace:check":
1041
+ packageData.scripts?.["workspace:check"] ?? "workflows check",
1042
+ "workspace:integrity":
1043
+ packageData.scripts?.["workspace:integrity"] ?? "workflows integrity",
1044
+ "dashboard:dev":
1045
+ packageData.scripts?.["dashboard:dev"] ?? "workflows dashboard",
1046
+ "workflows:update":
1047
+ packageData.scripts?.["workflows:update"] ?? "workflows update",
1048
+ };
1049
+
1050
+ fs.writeFileSync(
1051
+ packagePath,
1052
+ `${JSON.stringify({ ...packageData, scripts }, null, "\t")}\n`,
1053
+ );
1054
+ }
1055
+
1056
+ function writeManifest(root) {
1057
+ const manifest = {
1058
+ packageName: packageJson.name,
1059
+ packageVersion: packageJson.version,
1060
+ managedPaths,
1061
+ scaffoldOnlyPaths,
1062
+ updatedAt: new Date().toISOString(),
1063
+ };
1064
+ const target = path.join(root, manifestPath);
1065
+ fs.mkdirSync(path.dirname(target), { recursive: true });
1066
+ fs.writeFileSync(target, `${JSON.stringify(manifest, null, "\t")}\n`);
1067
+ }
1068
+
1069
+ function loadManifest(root) {
1070
+ const target = path.join(root, manifestPath);
1071
+ if (!fs.existsSync(target)) {
1072
+ throw new Error(
1073
+ `No ${manifestPath} found in ${root}. Run workflows init first.`,
1074
+ );
1075
+ }
1076
+
1077
+ return readJson(target);
1078
+ }
1079
+
1080
+ function resolveRoot(args) {
1081
+ const rootFlagIndex = args.findIndex(
1082
+ (arg) => arg === "--root" || arg === "-r",
1083
+ );
1084
+ const rootValue =
1085
+ rootFlagIndex >= 0 ? args[rootFlagIndex + 1] : process.cwd();
1086
+ if (!rootValue || rootValue.startsWith("-")) {
1087
+ throw new Error("--root requires a path.");
1088
+ }
1089
+
1090
+ return path.resolve(rootValue);
1091
+ }
1092
+
1093
+ function passthroughArgs(args) {
1094
+ const result = [];
1095
+ for (let index = 0; index < args.length; index += 1) {
1096
+ const arg = args[index];
1097
+ if (arg === "--root" || arg === "-r") {
1098
+ index += 1;
1099
+ continue;
1100
+ }
1101
+ result.push(arg);
1102
+ }
1103
+ return result;
1104
+ }
1105
+
1106
+ function readJson(filePath) {
1107
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
1108
+ }
1109
+
1110
+ function resolvePackageBin(packageName) {
1111
+ const packagePath = require.resolve(`${packageName}/package.json`);
1112
+ const packageData = readJson(packagePath);
1113
+ const bin =
1114
+ typeof packageData.bin === "string"
1115
+ ? packageData.bin
1116
+ : packageData.bin?.[Object.keys(packageData.bin)[0]];
1117
+ if (!bin) {
1118
+ throw new Error(`${packageName} does not expose a binary.`);
1119
+ }
1120
+
1121
+ return path.join(path.dirname(packagePath), bin);
1122
+ }
1123
+
1124
+ function ensureDirectory(directory) {
1125
+ fs.mkdirSync(directory, { recursive: true });
1126
+ }
1127
+
1128
+ function walkFiles(directory) {
1129
+ const entries = fs.readdirSync(directory, { withFileTypes: true });
1130
+ const files = [];
1131
+
1132
+ for (const entry of entries) {
1133
+ const entryPath = path.join(directory, entry.name);
1134
+ if (entry.isDirectory()) {
1135
+ files.push(...walkFiles(entryPath));
1136
+ } else if (entry.isFile()) {
1137
+ files.push(entryPath);
1138
+ }
1139
+ }
1140
+
1141
+ return files;
1142
+ }
1143
+
1144
+ function printHelp() {
1145
+ console.log(`Agent Workflows
1146
+
1147
+ Usage:
1148
+ workflows init [--root <path>]
1149
+ workflows update [--root <path>]
1150
+ workflows dashboard [--root <path>] [-- --vite-arg]
1151
+ workflows integrity [--root <path>]
1152
+ workflows check [--root <path>]
1153
+ workflows auto on|off|toggle|status [--root <path>]
1154
+ workflows agents sync [--root <path>]
1155
+ workflows agents sync [--format <codex|antigravity>] [--root <path>]
1156
+ workflows agents models --format <codex|antigravity|claude> [--json]
1157
+ workflows agents resolve <step> <role> --format <codex|antigravity|claude> [--json] [--root <path>]
1158
+
1159
+ Commands:
1160
+ init Write local workflow shims into a developer project and create a manifest.
1161
+ update Refresh workflow-owned shims and add missing model defaults to older configs.
1162
+ dashboard Start the packaged dashboard against the developer project.
1163
+ integrity Run the packaged workspace integrity check against the project.
1164
+ check Run package-provided workspace checks against the project.
1165
+ auto Persist or inspect workspace auto mode (default: off).
1166
+ agents Sync base role models or resolve workflow-step overrides.
1167
+
1168
+ Agent command and skill loading:
1169
+ Run workflows init once after global install, or bunx workflows init for a project-local install.
1170
+ Run workflows update after package upgrades. Set AGENT_WORKFLOWS_AUTO_UPDATE=1 during installation to opt in to an automatic refresh.
1171
+ Restart or reload active agent sessions after either command so they discover refreshed shims.`);
1172
+ }