@s_s/harmonia 1.3.0 → 1.4.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.
Files changed (172) hide show
  1. package/README.md +140 -392
  2. package/build/cli/setup.d.ts +4 -2
  3. package/build/cli/setup.js +44 -18
  4. package/build/cli/setup.js.map +1 -1
  5. package/build/core/action-registry.d.ts +36 -0
  6. package/build/core/action-registry.js +53 -0
  7. package/build/core/action-registry.js.map +1 -0
  8. package/build/core/artifacts.d.ts +66 -0
  9. package/build/core/artifacts.js +178 -0
  10. package/build/core/artifacts.js.map +1 -0
  11. package/build/core/dispatch.d.ts +6 -2
  12. package/build/core/dispatch.js +12 -7
  13. package/build/core/dispatch.js.map +1 -1
  14. package/build/core/overrides.d.ts +19 -26
  15. package/build/core/overrides.js +32 -98
  16. package/build/core/overrides.js.map +1 -1
  17. package/build/core/plugin.d.ts +86 -0
  18. package/build/core/plugin.js +332 -0
  19. package/build/core/plugin.js.map +1 -0
  20. package/build/core/registry.d.ts +4 -5
  21. package/build/core/registry.js +8 -9
  22. package/build/core/registry.js.map +1 -1
  23. package/build/core/reviews.d.ts +11 -12
  24. package/build/core/reviews.js +18 -21
  25. package/build/core/reviews.js.map +1 -1
  26. package/build/core/schema.d.ts +43 -15
  27. package/build/core/schema.js +124 -20
  28. package/build/core/schema.js.map +1 -1
  29. package/build/core/state.d.ts +26 -27
  30. package/build/core/state.js +36 -90
  31. package/build/core/state.js.map +1 -1
  32. package/build/core/steps.d.ts +13 -14
  33. package/build/core/steps.js +26 -29
  34. package/build/core/steps.js.map +1 -1
  35. package/build/core/tree-utils.d.ts +52 -0
  36. package/build/core/tree-utils.js +226 -0
  37. package/build/core/tree-utils.js.map +1 -0
  38. package/build/core/types.d.ts +389 -118
  39. package/build/core/types.js +15 -1
  40. package/build/core/types.js.map +1 -1
  41. package/build/core/workflow-engine.d.ts +68 -0
  42. package/build/core/workflow-engine.js +821 -0
  43. package/build/core/workflow-engine.js.map +1 -0
  44. package/build/core/workflow-validator.d.ts +22 -0
  45. package/build/core/workflow-validator.js +489 -0
  46. package/build/core/workflow-validator.js.map +1 -0
  47. package/build/index.js +25 -26
  48. package/build/index.js.map +1 -1
  49. package/build/setup/inject.d.ts +4 -4
  50. package/build/setup/inject.js +6 -6
  51. package/build/setup/inject.js.map +1 -1
  52. package/build/setup/templates.d.ts +9 -7
  53. package/build/setup/templates.js +68 -172
  54. package/build/setup/templates.js.map +1 -1
  55. package/build/tools/artifact-approve.d.ts +8 -0
  56. package/build/tools/{approve-doc.js → artifact-approve.js} +24 -16
  57. package/build/tools/artifact-approve.js.map +1 -0
  58. package/build/tools/artifact-schema.d.ts +12 -0
  59. package/build/tools/artifact-schema.js +148 -0
  60. package/build/tools/artifact-schema.js.map +1 -0
  61. package/build/tools/artifact-tools.d.ts +18 -0
  62. package/build/tools/artifact-tools.js +465 -0
  63. package/build/tools/artifact-tools.js.map +1 -0
  64. package/build/tools/{report-dispatch.d.ts → dispatch-report.d.ts} +7 -3
  65. package/build/tools/{report-dispatch.js → dispatch-report.js} +106 -28
  66. package/build/tools/dispatch-report.js.map +1 -0
  67. package/build/tools/engine-helpers.d.ts +41 -0
  68. package/build/tools/engine-helpers.js +182 -0
  69. package/build/tools/engine-helpers.js.map +1 -0
  70. package/build/tools/get-project-status.d.ts +6 -4
  71. package/build/tools/get-project-status.js +265 -248
  72. package/build/tools/get-project-status.js.map +1 -1
  73. package/build/tools/get-role-prompt.d.ts +1 -1
  74. package/build/tools/get-role-prompt.js +7 -41
  75. package/build/tools/get-role-prompt.js.map +1 -1
  76. package/build/tools/iteration-start.d.ts +7 -4
  77. package/build/tools/iteration-start.js +45 -19
  78. package/build/tools/iteration-start.js.map +1 -1
  79. package/build/tools/loop-done.d.ts +11 -0
  80. package/build/tools/loop-done.js +109 -0
  81. package/build/tools/loop-done.js.map +1 -0
  82. package/build/tools/patch-start.d.ts +4 -2
  83. package/build/tools/patch-start.js +36 -11
  84. package/build/tools/patch-start.js.map +1 -1
  85. package/build/tools/project-init.d.ts +5 -5
  86. package/build/tools/project-init.js +41 -10
  87. package/build/tools/project-init.js.map +1 -1
  88. package/build/tools/role-dispatch.d.ts +55 -0
  89. package/build/tools/role-dispatch.js +508 -0
  90. package/build/tools/role-dispatch.js.map +1 -0
  91. package/build/tools/utils.d.ts +6 -0
  92. package/build/tools/utils.js +36 -0
  93. package/build/tools/utils.js.map +1 -1
  94. package/package.json +1 -1
  95. package/{build/hooks/claude-code.js → workflows/dev/hooks/claude.js} +34 -23
  96. package/{build → workflows/dev}/hooks/content.js +27 -18
  97. package/workflows/dev/hooks/index.js +52 -0
  98. package/{build → workflows/dev}/hooks/openclaw.js +31 -20
  99. package/{build → workflows/dev}/hooks/opencode.js +31 -20
  100. package/workflows/dev/roles/architect.md +68 -28
  101. package/workflows/dev/roles/coordinator.md +103 -0
  102. package/workflows/dev/roles/developer.md +5 -5
  103. package/workflows/dev/roles/tester.md +19 -19
  104. package/workflows/dev/schemas/api-contract.json +42 -0
  105. package/workflows/dev/schemas/api-design.json +30 -13
  106. package/workflows/dev/schemas/data-model.json +20 -7
  107. package/workflows/dev/schemas/prd.completeness-check.json +6 -5
  108. package/workflows/dev/schemas/prd.draft.json +13 -5
  109. package/workflows/dev/schemas/prd.final.json +34 -11
  110. package/workflows/dev/schemas/prd.json +29 -11
  111. package/workflows/dev/schemas/prd.requirements.json +6 -5
  112. package/workflows/dev/schemas/prototype.json +6 -2
  113. package/workflows/dev/schemas/task-breakdown.coarse.json +4 -3
  114. package/workflows/dev/schemas/task-breakdown.dependencies.json +5 -4
  115. package/workflows/dev/schemas/task-breakdown.detailed.json +8 -3
  116. package/workflows/dev/schemas/task-breakdown.final.json +8 -3
  117. package/workflows/dev/schemas/task-breakdown.json +8 -3
  118. package/workflows/dev/schemas/tech-design.analysis.json +6 -5
  119. package/workflows/dev/schemas/tech-design.draft.json +14 -5
  120. package/workflows/dev/schemas/tech-design.final.json +39 -13
  121. package/workflows/dev/schemas/tech-design.json +34 -13
  122. package/workflows/dev/schemas/tech-design.research.json +21 -0
  123. package/workflows/dev/schemas/test-plan.json +17 -7
  124. package/workflows/dev/schemas/test-report.json +26 -9
  125. package/workflows/dev/schemas/user-stories.json +7 -3
  126. package/workflows/dev/tools/index.js +23 -0
  127. package/workflows/dev/workflow.json +234 -101
  128. package/build/core/docs.d.ts +0 -36
  129. package/build/core/docs.js +0 -96
  130. package/build/core/docs.js.map +0 -1
  131. package/build/core/workflow.d.ts +0 -33
  132. package/build/core/workflow.js +0 -140
  133. package/build/core/workflow.js.map +0 -1
  134. package/build/hooks/claude-code.d.ts +0 -20
  135. package/build/hooks/claude-code.js.map +0 -1
  136. package/build/hooks/content.d.ts +0 -43
  137. package/build/hooks/content.js.map +0 -1
  138. package/build/hooks/install.d.ts +0 -40
  139. package/build/hooks/install.js +0 -63
  140. package/build/hooks/install.js.map +0 -1
  141. package/build/hooks/openclaw.d.ts +0 -24
  142. package/build/hooks/openclaw.js.map +0 -1
  143. package/build/hooks/opencode.d.ts +0 -29
  144. package/build/hooks/opencode.js.map +0 -1
  145. package/build/tools/approve-doc.d.ts +0 -6
  146. package/build/tools/approve-doc.js.map +0 -1
  147. package/build/tools/dispatch-role.d.ts +0 -16
  148. package/build/tools/dispatch-role.js +0 -266
  149. package/build/tools/dispatch-role.js.map +0 -1
  150. package/build/tools/doc-tools.d.ts +0 -16
  151. package/build/tools/doc-tools.js +0 -425
  152. package/build/tools/doc-tools.js.map +0 -1
  153. package/build/tools/override-tools.d.ts +0 -6
  154. package/build/tools/override-tools.js +0 -129
  155. package/build/tools/override-tools.js.map +0 -1
  156. package/build/tools/report-dispatch.js.map +0 -1
  157. package/build/tools/set-scale.d.ts +0 -6
  158. package/build/tools/set-scale.js +0 -95
  159. package/build/tools/set-scale.js.map +0 -1
  160. package/build/tools/setup-project.d.ts +0 -8
  161. package/build/tools/setup-project.js +0 -116
  162. package/build/tools/setup-project.js.map +0 -1
  163. package/build/tools/update-phase.d.ts +0 -12
  164. package/build/tools/update-phase.js +0 -148
  165. package/build/tools/update-phase.js.map +0 -1
  166. package/workflows/dev/roles/pm.md +0 -99
  167. package/workflows/dev/schemas/deploy.json +0 -20
  168. package/workflows/dev/schemas/fsd.json +0 -25
  169. package/workflows/dev/schemas/project-plan.json +0 -20
  170. package/workflows/dev/schemas/retrospective.json +0 -20
  171. package/workflows/dev/schemas/risk-assessment.json +0 -15
  172. package/workflows/dev/schemas/tech-design.api-contract.json +0 -20
@@ -1,29 +1,37 @@
1
1
  /**
2
- * MCP Tool: doc_approve / review_list
3
- * Approve or reject a document that is pending review.
2
+ * MCP Tool: artifact_approve / review_list
3
+ * Approve or reject an artifact that is pending review.
4
+ *
5
+ * After approval, triggers engine event `artifact_approved` to evaluate gates.
4
6
  */
5
7
  import { z } from 'zod';
6
8
  import { resolveReview, getPendingReviews } from '../core/reviews.js';
7
9
  import { resolveActive, isError } from './utils.js';
8
- export function registerApproveDoc(server) {
9
- server.tool('doc_approve', 'Approve or reject a document pending review. Call this after the user has reviewed the document and confirmed (or requested changes).', {
10
+ import { processWorkflowEvent, formatNextAction } from './engine-helpers.js';
11
+ export function registerApproveArtifact(server, workflowsDir) {
12
+ server.tool('artifact_approve', 'Approve or reject an artifact pending review. Call this after the user has reviewed the artifact and confirmed (or requested changes).', {
10
13
  project_name: z.string().describe('Project name'),
11
- doc_id: z.string().describe('Document ID to approve/reject'),
14
+ artifact_id: z.string().describe('Artifact ID to approve/reject'),
12
15
  approved: z.boolean().describe('true = approved, false = rejected (needs revision)'),
13
16
  comment: z.string().optional().describe('Optional comment — user feedback or reason for rejection'),
14
- }, async ({ project_name, doc_id, approved, comment }) => {
17
+ }, async ({ project_name, artifact_id, approved, comment }) => {
15
18
  try {
16
19
  const ctx = await resolveActive(project_name);
17
20
  if (isError(ctx))
18
21
  return ctx;
19
22
  const status = approved ? 'approved' : 'rejected';
20
- const review = await resolveReview(project_name, ctx.number, doc_id, status, comment);
23
+ await resolveReview(project_name, ctx.number, artifact_id, status, comment, ctx.dir);
21
24
  if (approved) {
25
+ // Trigger engine event: artifact_approved
26
+ const engineResult = await processWorkflowEvent(workflowsDir, project_name, ctx, {
27
+ type: 'artifact_approved',
28
+ artifactId: artifact_id,
29
+ });
22
30
  return {
23
31
  content: [
24
32
  {
25
33
  type: 'text',
26
- text: `Document "${doc_id}" approved. You may proceed with the workflow.`,
34
+ text: `Artifact "${artifact_id}" approved.` + formatNextAction(engineResult.nextAction),
27
35
  },
28
36
  ],
29
37
  };
@@ -34,9 +42,9 @@ export function registerApproveDoc(server) {
34
42
  {
35
43
  type: 'text',
36
44
  text: [
37
- `Document "${doc_id}" rejected.`,
45
+ `Artifact "${artifact_id}" rejected.`,
38
46
  comment ? `User feedback: ${comment}` : '',
39
- `Please revise the document based on the feedback and call doc_write again.`,
47
+ `Please revise the artifact based on the feedback and call artifact_write again.`,
40
48
  ].join('\n'),
41
49
  },
42
50
  ],
@@ -55,32 +63,32 @@ export function registerApproveDoc(server) {
55
63
  };
56
64
  }
57
65
  });
58
- server.tool('review_list', 'List all documents currently pending user review.', {
66
+ server.tool('review_list', 'List all artifacts currently pending user review.', {
59
67
  project_name: z.string().describe('Project name'),
60
68
  }, async ({ project_name }) => {
61
69
  const ctx = await resolveActive(project_name);
62
70
  if (isError(ctx))
63
71
  return ctx;
64
- const pending = await getPendingReviews(project_name, ctx.number);
72
+ const pending = await getPendingReviews(project_name, ctx.number, ctx.dir);
65
73
  if (pending.length === 0) {
66
74
  return {
67
75
  content: [
68
76
  {
69
77
  type: 'text',
70
- text: 'No documents pending review.',
78
+ text: 'No artifacts pending review.',
71
79
  },
72
80
  ],
73
81
  };
74
82
  }
75
- const list = pending.map((r) => `- ${r.docId} (submitted: ${r.submittedAt})`).join('\n');
83
+ const list = pending.map((r) => `- ${r.artifactId} (submitted: ${r.submittedAt})`).join('\n');
76
84
  return {
77
85
  content: [
78
86
  {
79
87
  type: 'text',
80
- text: `Documents pending review:\n${list}`,
88
+ text: `Artifacts pending review:\n${list}`,
81
89
  },
82
90
  ],
83
91
  };
84
92
  });
85
93
  }
86
- //# sourceMappingURL=approve-doc.js.map
94
+ //# sourceMappingURL=artifact-approve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-approve.js","sourceRoot":"","sources":["../../src/tools/artifact-approve.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,MAAM,UAAU,uBAAuB,CAAC,MAAiB,EAAE,YAAoB;IAC3E,MAAM,CAAC,IAAI,CACP,kBAAkB,EAClB,wIAAwI,EACxI;QACI,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC;QACjD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QACjE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;QACpF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0DAA0D,CAAC;KACtG,EACD,KAAK,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QACvD,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,OAAO,CAAC,GAAG,CAAC;gBAAE,OAAO,GAAG,CAAC;YAE7B,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;YAClD,MAAM,aAAa,CA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EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;QACvB,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAI,OAAO,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;QAE7B,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAE3E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,8BAA8B;qBACvC;iBACJ;aACJ,CAAC;QACN,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,UAAU,gBAAgB,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9F,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,8BAA8B,IAAI,EAAE;iBAC7C;aACJ;SACJ,CAAC;IACN,CAAC,CACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * MCP Tool: artifact_schema
3
+ *
4
+ * Query artifact structure requirements and writing guidance before writing.
5
+ * Returns human-readable schema guidance including required sections/fields,
6
+ * content boundaries, format requirements, and step-by-step constraints.
7
+ *
8
+ * Primarily used by coordinator (who is not dispatched and thus doesn't receive
9
+ * Artifact Requirements automatically via role_dispatch).
10
+ */
11
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ export declare function registerArtifactSchema(server: McpServer, workflowsDir: string): void;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * MCP Tool: artifact_schema
3
+ *
4
+ * Query artifact structure requirements and writing guidance before writing.
5
+ * Returns human-readable schema guidance including required sections/fields,
6
+ * content boundaries, format requirements, and step-by-step constraints.
7
+ *
8
+ * Primarily used by coordinator (who is not dispatched and thus doesn't receive
9
+ * Artifact Requirements automatically via role_dispatch).
10
+ */
11
+ import { z } from 'zod';
12
+ import { loadArtifactSchema, formatSchemaGuidance } from '../core/schema.js';
13
+ import { loadWorkflowForContext } from './engine-helpers.js';
14
+ import { resolveActive, isError } from './utils.js';
15
+ export function registerArtifactSchema(server, workflowsDir) {
16
+ server.tool('artifact_schema', 'Query artifact structure requirements and writing guidance. Call this before writing an artifact to understand required sections, content boundaries, and format constraints.', {
17
+ project_name: z.string().describe('Project name'),
18
+ artifact_id: z
19
+ .string()
20
+ .describe('Artifact ID (e.g. prd, user-stories, fsd, prototype, tech-design, task-breakdown, etc.)'),
21
+ step: z
22
+ .string()
23
+ .optional()
24
+ .describe("Step ID (e.g. requirements, draft, final). If specified, returns only that step's schema. If omitted, returns the full artifact schema including all steps."),
25
+ }, async ({ project_name, artifact_id, step }) => {
26
+ try {
27
+ const ctx = await resolveActive(project_name);
28
+ if (isError(ctx))
29
+ return ctx;
30
+ const { wf, state } = await loadWorkflowForContext(workflowsDir, project_name, ctx);
31
+ // Validate artifact_id exists in workflow
32
+ const artifactDef = wf.artifactDefinitions[artifact_id];
33
+ if (!artifactDef) {
34
+ const available = Object.keys(wf.artifactDefinitions).join(', ');
35
+ return {
36
+ content: [
37
+ {
38
+ type: 'text',
39
+ text: `Artifact "${artifact_id}" not found in workflow. Available: ${available}`,
40
+ },
41
+ ],
42
+ isError: true,
43
+ };
44
+ }
45
+ // If a specific step is requested, return only that step's schema
46
+ if (step) {
47
+ // Validate step exists in artifact definition
48
+ if (!artifactDef.steps || !artifactDef.steps.find((s) => s.id === step)) {
49
+ const availableSteps = artifactDef.steps?.map((s) => s.id).join(', ') ?? '(无分步)';
50
+ return {
51
+ content: [
52
+ {
53
+ type: 'text',
54
+ text: `Step "${step}" not found for artifact "${artifact_id}". Available steps: ${availableSteps}`,
55
+ },
56
+ ],
57
+ isError: true,
58
+ };
59
+ }
60
+ const stepSchema = await loadArtifactSchema(workflowsDir, state.workflow, `${artifact_id}.${step}`);
61
+ const stepDefFound = artifactDef.steps.find((s) => s.id === step);
62
+ const lines = [];
63
+ lines.push(`## Step 要求: ${artifact_id}.${step}(${stepDefFound.name})`);
64
+ lines.push('');
65
+ lines.push(`格式: ${stepDefFound.format === 'json' ? 'JSON' : 'Markdown'}`);
66
+ lines.push(`描述: ${stepDefFound.description}`);
67
+ if (stepSchema) {
68
+ if (stepSchema.guidance) {
69
+ lines.push(`内容指引: ${stepSchema.guidance}`);
70
+ }
71
+ if (stepSchema.minLength) {
72
+ lines.push(`最小长度: ${stepSchema.minLength} 字符`);
73
+ }
74
+ if (stepSchema.jsonFields) {
75
+ const reqFields = stepSchema.jsonFields.filter((f) => f.required);
76
+ if (reqFields.length > 0) {
77
+ lines.push('');
78
+ lines.push('### 必需 JSON 字段');
79
+ for (const field of reqFields) {
80
+ let desc = `- ${field.field}`;
81
+ if (field.type)
82
+ desc += ` (${field.type})`;
83
+ if (field.minItems)
84
+ desc += `, ≥${field.minItems} 项`;
85
+ lines.push(desc);
86
+ }
87
+ }
88
+ }
89
+ if (stepSchema.sections) {
90
+ const reqSections = stepSchema.sections.filter((s) => s.required);
91
+ if (reqSections.length > 0) {
92
+ lines.push('');
93
+ lines.push('### 必需章节');
94
+ for (const section of reqSections) {
95
+ const heading = section.heading.replace(/^#+\s*/, '');
96
+ lines.push(`- ${heading}`);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ else {
102
+ lines.push('');
103
+ lines.push('(此 step 无 schema 约束)');
104
+ }
105
+ return {
106
+ content: [{ type: 'text', text: lines.join('\n') }],
107
+ };
108
+ }
109
+ // Full artifact schema
110
+ const schema = await loadArtifactSchema(workflowsDir, state.workflow, artifact_id);
111
+ // Load step schemas if artifact has steps
112
+ let stepSchemas;
113
+ if (artifactDef.steps && artifactDef.steps.length > 0) {
114
+ stepSchemas = [];
115
+ for (const s of artifactDef.steps) {
116
+ const stepSchema = await loadArtifactSchema(workflowsDir, state.workflow, `${artifact_id}.${s.id}`);
117
+ stepSchemas.push({ step: s, schema: stepSchema });
118
+ }
119
+ }
120
+ if (!schema && (!stepSchemas || stepSchemas.every((s) => !s.schema))) {
121
+ return {
122
+ content: [
123
+ {
124
+ type: 'text',
125
+ text: `Artifact "${artifact_id}" 无 schema 定义。`,
126
+ },
127
+ ],
128
+ };
129
+ }
130
+ const guidance = formatSchemaGuidance(artifact_id, artifactDef, schema, stepSchemas);
131
+ return {
132
+ content: [{ type: 'text', text: guidance }],
133
+ };
134
+ }
135
+ catch (err) {
136
+ return {
137
+ content: [
138
+ {
139
+ type: 'text',
140
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
141
+ },
142
+ ],
143
+ isError: true,
144
+ };
145
+ }
146
+ });
147
+ }
148
+ //# sourceMappingURL=artifact-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-schema.js","sourceRoot":"","sources":["../../src/tools/artifact-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,UAAU,sBAAsB,CAAC,MAAiB,EAAE,YAAoB;IAC1E,MAAM,CAAC,IAAI,CACP,iBAAiB,EACjB,+KAA+K,EAC/K;QACI,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC;QACjD,WAAW,EAAE,CAAC;aACT,MAAM,EAAE;aACR,QAAQ,CAAC,yFAAyF,CAAC;QACxG,IAAI,EAAE,CAAC;aACF,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,C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C;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;qBACrE;iBACJ;gBACD,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;IACL,CAAC,CACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * MCP Tools: artifact_write / artifact_read / artifact_list
3
+ * Read and write project artifacts. Output paths are resolved per artifact
4
+ *
5
+ * artifact_write validates content against artifact schemas and checks review
6
+ * configuration. If validation fails, the write is rejected with specific
7
+ * error details. If review is required, the artifact is submitted for
8
+ * user approval.
9
+ *
10
+ * Sequential mode: When an artifact has `steps` defined in workflow.json,
11
+ * artifact_write requires a `step` parameter. Each step is validated
12
+ * independently, and the final step automatically writes the formal
13
+ * artifact and triggers the review flow.
14
+ *
15
+ * After writing, triggers engine event `artifact_written` to evaluate gates.
16
+ */
17
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
18
+ export declare function registerArtifactTools(server: McpServer, workflowsDir: string): void;