@ai-agent-forge/plugin-alignment 0.88.5 → 0.88.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-forge.json +1 -1
- package/dist/engine.d.ts +10 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +20 -0
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -28
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +8 -10
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +92 -57
- package/dist/render.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AA+BnC,MAAM,OAAO,GAA2B;IACvC,IAAI,EAAE,QAAI;IACV,UAAU,EAAE,QAAI;IAChB,QAAQ,EAAE,QAAI;IACd,OAAO,EAAE,QAAI;IACb,MAAM,EAAE,QAAI;CACZ,CAAC;AAEF,MAAM,OAAO,GAA2B,EAAE,SAAS,EAAE,QAAI,EAAE,MAAM,EAAE,QAAI,EAAE,MAAM,EAAE,QAAI,EAAE,CAAC;AAExF,SAAS,MAAM,CAAC,IAAY,EAAW;IACtC,OAAO,CACN,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,MAAM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\n * Structural renderResult for the alignment tools (设计 §7.1): collapsed\n * shows the summary header (task / step / progress / page URL), expanded adds\n * per-block details and pending items. No TUI import — the component talks to\n * the structural shape the host serializes (goal/plan/todo-set/workflow\n * precedent, 2026-10-02).\n */\n\nimport { gate } from \"./engine.ts\";\nimport type { AlignmentRecord, AlignmentState } from \"./types.ts\";\n\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\nexport interface AlignmentToolResultView {\n\talignmentId: string;\n\turl?: string;\n\twarning?: string;\n}\n\nconst KIND_CN: Record<string, string> = {\n\tfact: \"取证\",\n\tassumption: \"假设\",\n\tdecision: \"决策\",\n\tmissing: \"待补\",\n\tvisual: \"视觉\",\n};\n\nconst STEP_CN: Record<string, string> = { objective: \"目标\", detail: \"细节\", design: \"设计\" };\n\nfunction isWide(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWide(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\nclass AlignmentResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\nfunction findRecordIn(state: AlignmentState, id: string): AlignmentRecord | undefined {\n\treturn state.alignments.find((record) => record.id === id);\n}\n\nfunction summaryLines(record: AlignmentRecord, url: string | undefined, warning: string | undefined): string[] {\n\tconst snapshot = gate(record);\n\tconst step = record.steps.find((candidate) => candidate.step === record.activeStep);\n\tconst lines = [\n\t\t`alignment: ${record.id} [${record.status}] ${record.title}`,\n\t\t`step: ${STEP_CN[record.activeStep] ?? record.activeStep} · round ${record.roundCount} · ${step?.blocks.length ?? 0} blocks · ${snapshot.unapproved} pending · ${snapshot.openComments} open comments`,\n\t];\n\tif ((record.status === \"aligning\" || record.status === \"finalizing\") && url) lines.push(`page: ${url}`);\n\tif (record.status === \"finalizing\") lines.push(\"final review: awaiting user confirmation on the overview tab\");\n\tif (record.status === \"completed\") lines.push(\"baseline: locked (final review approved)\");\n\tif (warning) lines.push(`warning: ${warning}`);\n\treturn lines;\n}\n\nfunction detailLines(record: AlignmentRecord): string[] {\n\tconst lines: string[] = [];\n\tfor (const step of record.steps) {\n\t\tif (step.blocks.length === 0) continue;\n\t\tlines.push(`${STEP_CN[step.step] ?? step.step} [${step.status}]`);\n\t\tfor (const block of step.blocks) {\n\t\t\tconst flag = block.status === \"approved\" ? \"✓\" : \"·\";\n\t\t\tconst draft =\n\t\t\t\tblock.kind === \"missing\" && (block.draftAnswer ?? \"\").trim() !== \"\"\n\t\t\t\t\t? ` → 已答:${(block.draftAnswer ?? \"\").slice(0, 40)}`\n\t\t\t\t\t: \"\";\n\t\t\tconst modified = block.modifiedInRound !== undefined ? ` (r${block.modifiedInRound} 修改)` : \"\";\n\t\t\tlines.push(\n\t\t\t\t` ${flag} [${KIND_CN[block.kind] ?? block.kind}] ${block.id}: ${block.content.split(\"\\n\")[0]?.slice(0, 72) ?? \"\"}${draft}${modified}`,\n\t\t\t);\n\t\t\tfor (const comment of block.comments) {\n\t\t\t\tconst who = comment.author === \"assistant\" ? \"AI\" : \"你\";\n\t\t\t\tconst state = comment.status === \"open\" ? \"open\" : (comment.resolution?.kind ?? \"resolved\");\n\t\t\t\tlines.push(` ↳ ${who}: ${comment.note.slice(0, 60)} [${state}]`);\n\t\t\t}\n\t\t}\n\t}\n\tconst snapshot = gate(record);\n\tif (record.status === \"aligning\") {\n\t\tlines.push(\n\t\t\t`gate: ${snapshot.unapproved} unapproved · ${snapshot.openComments} open · ${snapshot.pendingAdditions} pending additions${snapshot.allGreen ? \" · ALL GREEN\" : \"\"}`,\n\t\t);\n\t\tif (record.pendingFeedback) {\n\t\t\tlines.push(\n\t\t\t\t`pending additions: ${record.pendingFeedback.additions.map((item) => item.slice(0, 60)).join(\" | \")}`,\n\t\t\t);\n\t\t}\n\t}\n\treturn lines;\n}\n\n/** Structural renderResult shared by alignment_set / alignment_round / alignment_advance. */\nexport function alignmentToolResultRenderer(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): AlignmentResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst view = parsed as { state?: AlignmentState; alignmentId?: string; url?: string; warning?: string };\n\tif (!view.state || !Array.isArray(view.state.alignments) || !view.alignmentId) return undefined;\n\tconst record = findRecordIn(view.state, view.alignmentId);\n\t// Same foreign-payload gate as the state level: a record without the step\n\t// array is not an alignment record this renderer claims.\n\tif (!record || !Array.isArray(record.steps)) return undefined;\n\tconst lines = [...summaryLines(record, view.url, view.warning)];\n\tif (options.expanded) lines.push(...detailLines(record));\n\tif (context.lastComponent instanceof AlignmentResultComponent) {\n\t\tcontext.lastComponent.setText(lines.join(\"\\n\"));\n\t\treturn context.lastComponent;\n\t}\n\treturn new AlignmentResultComponent(lines.join(\"\\n\"), theme);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoDH,MAAM,OAAO,GAA2B;IACvC,IAAI,EAAE,QAAI;IACV,UAAU,EAAE,QAAI;IAChB,QAAQ,EAAE,QAAI;IACd,OAAO,EAAE,QAAI;IACb,MAAM,EAAE,QAAI;CACZ,CAAC;AAEF,MAAM,OAAO,GAA2B,EAAE,SAAS,EAAE,QAAI,EAAE,MAAM,EAAE,QAAI,EAAE,MAAM,EAAE,QAAI,EAAE,CAAC;AAExF,SAAS,MAAM,CAAC,IAAY,EAAW;IACtC,OAAO,CACN,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QAClC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;QA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;AAED,6FAA6F;AAC7F,MAAM,UAAU,2BAA2B,CAC1C,MAAsB,EACtB,OAAgC,EAChC,KAAgB,EAChB,OAA0B,EACa;IACvC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC;IACvE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IACxD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzE,IAAI,OAAO,CAAC,aAAa,YAAY,wBAAwB,EAAE,CAAC;QAC/D,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,OAAO,OAAO,CAAC,aAAa,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;AAAA,CAC7D","sourcesContent":["/**\n * Structural renderResult for the alignment tools (设计 §7.1): consumes the\n * single-record summary the three tools return (设计 §6, v3.7) — collapsed\n * shows the summary header (task / status / step / round / gate counts) plus\n * the page URL and warning, expanded adds the active step's per-block detail\n * lines (✓/· prefix, kind badge, preview, comment count). A payload without\n * alignmentId/gate is foreign and yields undefined (host fallback). No TUI\n * import — the component talks to the structural shape the host serializes\n * (goal/plan/todo-set/workflow precedent, 2026-10-02).\n */\n\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\ninterface SummaryBlockView {\n\tid: string;\n\tkind: string;\n\tstatus: string;\n\tpreview: string;\n\tcommentCount: number;\n\tdraftAnswer?: string;\n}\n\ninterface SummaryStepView {\n\tname: string;\n\tstatus: string;\n\tblocks: SummaryBlockView[];\n}\n\ninterface SummaryView {\n\talignmentId: string;\n\tstatus: string;\n\ttitle: string;\n\tactiveStep: string;\n\tround: number;\n\tunapproved: number;\n\topenComments: number;\n\turl?: string;\n\twarning?: string;\n\tstep?: SummaryStepView;\n}\n\nconst KIND_CN: Record<string, string> = {\n\tfact: \"取证\",\n\tassumption: \"假设\",\n\tdecision: \"决策\",\n\tmissing: \"待补\",\n\tvisual: \"视觉\",\n};\n\nconst STEP_CN: Record<string, string> = { objective: \"目标\", detail: \"细节\", design: \"设计\" };\n\nfunction isWide(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWide(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\nclass AlignmentResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\n/** Shape-gate the tool payload (设计 §6): a summary without the required\n * scalars or the gate object is foreign and claims nothing. */\nfunction parseSummary(parsed: unknown): SummaryView | undefined {\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst view = parsed as Record<string, unknown>;\n\tif (typeof view.alignmentId !== \"string\" || view.alignmentId === \"\") return undefined;\n\tif (typeof view.status !== \"string\" || typeof view.title !== \"string\") return undefined;\n\tif (typeof view.activeStep !== \"string\" || typeof view.round !== \"number\") return undefined;\n\tif (view.gate === null || typeof view.gate !== \"object\" || Array.isArray(view.gate)) return undefined;\n\tconst gateView = view.gate as Record<string, unknown>;\n\tif (typeof gateView.unapproved !== \"number\" || typeof gateView.openComments !== \"number\") return undefined;\n\tconst step = parseStep(view.step);\n\treturn {\n\t\talignmentId: view.alignmentId,\n\t\tstatus: view.status,\n\t\ttitle: view.title,\n\t\tactiveStep: view.activeStep,\n\t\tround: view.round,\n\t\tunapproved: gateView.unapproved,\n\t\topenComments: gateView.openComments,\n\t\t...(typeof view.url === \"string\" ? { url: view.url } : {}),\n\t\t...(typeof view.warning === \"string\" ? { warning: view.warning } : {}),\n\t\t...(step !== undefined ? { step } : {}),\n\t};\n}\n\nfunction parseStep(value: unknown): SummaryStepView | undefined {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst step = value as Record<string, unknown>;\n\tif (typeof step.name !== \"string\" || typeof step.status !== \"string\" || !Array.isArray(step.blocks)) {\n\t\treturn undefined;\n\t}\n\tconst blocks: SummaryBlockView[] = [];\n\tfor (const entry of step.blocks) {\n\t\tif (entry === null || typeof entry !== \"object\") return undefined;\n\t\tconst block = entry as Record<string, unknown>;\n\t\tif (\n\t\t\ttypeof block.id !== \"string\" ||\n\t\t\ttypeof block.kind !== \"string\" ||\n\t\t\ttypeof block.status !== \"string\" ||\n\t\t\ttypeof block.preview !== \"string\" ||\n\t\t\ttypeof block.commentCount !== \"number\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tblocks.push({\n\t\t\tid: block.id,\n\t\t\tkind: block.kind,\n\t\t\tstatus: block.status,\n\t\t\tpreview: block.preview,\n\t\t\tcommentCount: block.commentCount,\n\t\t\t...(typeof block.draftAnswer === \"string\" ? { draftAnswer: block.draftAnswer } : {}),\n\t\t});\n\t}\n\treturn { name: step.name, status: step.status, blocks };\n}\n\nfunction summaryLines(view: SummaryView): string[] {\n\tconst blocks = view.step ? ` · ${view.step.blocks.length} blocks` : \"\";\n\tconst lines = [\n\t\t`alignment: ${view.alignmentId} [${view.status}] ${view.title}`,\n\t\t`step: ${STEP_CN[view.activeStep] ?? view.activeStep} · round ${view.round}${blocks} · ${view.unapproved} pending · ${view.openComments} open comments`,\n\t];\n\tif ((view.status === \"aligning\" || view.status === \"finalizing\") && view.url) lines.push(`page: ${view.url}`);\n\tif (view.status === \"finalizing\") lines.push(\"final review: awaiting user confirmation on the overview tab\");\n\tif (view.status === \"completed\") lines.push(\"baseline: locked (final review approved)\");\n\tif (view.warning) lines.push(`warning: ${view.warning}`);\n\treturn lines;\n}\n\nfunction detailLines(step: SummaryStepView): string[] {\n\tconst lines: string[] = [`${STEP_CN[step.name] ?? step.name} [${step.status}]`];\n\tfor (const block of step.blocks) {\n\t\tconst flag = block.status === \"approved\" ? \"✓\" : \"·\";\n\t\tconst draft =\n\t\t\tblock.kind === \"missing\" && (block.draftAnswer ?? \"\").trim() !== \"\"\n\t\t\t\t? ` → 已答:${(block.draftAnswer ?? \"\").slice(0, 40)}`\n\t\t\t\t: \"\";\n\t\tconst comments = block.commentCount > 0 ? `(${block.commentCount} 批注)` : \"\";\n\t\tlines.push(` ${flag} [${KIND_CN[block.kind] ?? block.kind}] ${block.id}: ${block.preview}${draft}${comments}`);\n\t}\n\treturn lines;\n}\n\n/** Structural renderResult shared by alignment_set / alignment_round / alignment_advance. */\nexport function alignmentToolResultRenderer(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): AlignmentResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst view = parseSummary(parsed);\n\tif (!view) return undefined;\n\tconst lines = summaryLines(view);\n\tif (options.expanded && view.step) lines.push(...detailLines(view.step));\n\tif (context.lastComponent instanceof AlignmentResultComponent) {\n\t\tcontext.lastComponent.setText(lines.join(\"\\n\"));\n\t\treturn context.lastComponent;\n\t}\n\treturn new AlignmentResultComponent(lines.join(\"\\n\"), theme);\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -182,7 +182,7 @@ export interface GateSnapshot {
|
|
|
182
182
|
pending: PendingItem[];
|
|
183
183
|
}
|
|
184
184
|
/** Error codes thrown by the engine; index.ts lets them surface as tool errors verbatim. */
|
|
185
|
-
export type AlignmentErrorCode = "invalid-id" | "active-alignment-exists" | "not-found" | "terminal-state" | "stale-revision" | "stale-state" | "step-not-writable" | "step-not-unlocked" | "block-has-open-comments" | "comment-ownership" | "comment-quote-mismatch" | "gate-not-satisfied" | "confirmed-with-feedback" | "invalid-block" | "invalid-comment" | "invalid-input" | "retreat-target-invalid";
|
|
185
|
+
export type AlignmentErrorCode = "invalid-id" | "active-alignment-exists" | "not-found" | "terminal-state" | "stale-revision" | "stale-state" | "step-not-writable" | "step-not-unlocked" | "block-has-open-comments" | "approved-blocks-conflict" | "comment-ownership" | "comment-quote-mismatch" | "gate-not-satisfied" | "confirmed-with-feedback" | "invalid-block" | "invalid-comment" | "invalid-input" | "retreat-target-invalid";
|
|
186
186
|
export declare class AlignmentError extends Error {
|
|
187
187
|
readonly code: AlignmentErrorCode;
|
|
188
188
|
constructor(code: AlignmentErrorCode, message: string);
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,eAAO,MAAM,UAAU,4CAA6C,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3F,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,WAAW,CAAC;AAE1D,MAAM,MAAM,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CAInE,CAAC","sourcesContent":["/**\n * Data model of the alignment capability plugin\n * (`docs/design/需求对齐插件设计.md` §4). This module declares shapes only —\n * every conversion rule lives in `engine.ts` and every host-facing side effect\n * (entries, events, injection, HTTP) lives in `index.ts` / `http-server.ts`.\n */\n\n/** The three funnel steps, in canonical order. */\nexport const STEP_ORDER = [\"objective\", \"detail\", \"design\"] as const;\n\nexport type AlignmentStepId = (typeof STEP_ORDER)[number];\n\nexport type AlignmentBlockKind = \"fact\" | \"assumption\" | \"decision\" | \"missing\" | \"visual\";\n\nexport type AlignmentCommentAuthor = \"user\" | \"assistant\";\n\nexport type AlignmentCommentResolutionKind = \"answered\" | \"dismissed\" | \"incorporated\";\n\n/** Bidirectional block annotation (设计 §4: author distinguishes the direction). */\nexport interface AlignmentComment {\n\tid: string; // unique within the owning block\n\tauthor: AlignmentCommentAuthor;\n\t/** Exact in-block quote; required for user comments, optional for assistant ones. */\n\tquote?: string;\n\tnote: string;\n\t/** User flag: the objection targets an earlier (upstream) step — retreat candidate. */\n\tescalate?: boolean;\n\tstatus: \"open\" | \"resolved\";\n\tresolution?: {\n\t\tkind: AlignmentCommentResolutionKind;\n\t\ttext?: string;\n\t\tround?: number;\n\t};\n\tcreatedAtRound: number;\n}\n\nexport interface AlignmentBlock {\n\tid: string; // stable within the step\n\tkind: AlignmentBlockKind;\n\tcontent: string;\n\trationale?: string;\n\timpact?: string[];\n\tstatus: \"pending\" | \"approved\";\n\t/** Engine-computed fingerprint (kind+content+rationale+impact); cross-round approval inheritance key. */\n\tcontentHash: string;\n\t/** Round in which the content last changed; drives the \"modified this round\" badge. */\n\tmodifiedInRound?: number;\n\t/** Stored fill-in for a missing block — the user's own words, kept verbatim until the model restructures the block. */\n\tdraftAnswer?: string;\n\tcomments: AlignmentComment[];\n}\n\nexport interface AlignmentStepState {\n\tstep: AlignmentStepId;\n\t/** pending = not unlocked yet (terminal-audit D2); reset = retreated into, confirmations cleared. */\n\tstatus: \"pending\" | \"locked\" | \"active\" | \"reset\";\n\t/** Round count at confirmation time (entry-sequence-like anchor, not wall clock). */\n\tbaselineConfirmedAtRound?: number;\n\tblocks: AlignmentBlock[];\n}\n\nexport interface AlignmentRecord {\n\tid: string;\n\ttitle: string;\n\t/** Soft reference to goal.state (advisory, #10): dangling only warns. */\n\tgoalId?: string;\n\t/**\n\t * Created-as-aligning (no draft state, terminal audit D3). `finalizing`\n\t * (走查 2026-10-03) = all three steps locked, waiting for the final\n\t * review tab confirmation — only that confirmation completes the\n\t * alignment and writes the baseline (方案确认 ≠ 终版确认).\n\t */\n\tstatus: \"aligning\" | \"finalizing\" | \"completed\" | \"cancelled\";\n\t/**\n\t * Monotonic for alignment_set callers; engine-triggered conversions\n\t * (freeze/unlock/retreat/complete) auto-increment it too (workflow\n\t * precedent, terminal audit D4). Carried on round results so the model\n\t * always knows the next acceptable revision.\n\t */\n\trevision: number;\n\t/** Points at the single step with status \"active\"; pending/reset/locked steps are not writable. */\n\tactiveStep: AlignmentStepId;\n\tsteps: AlignmentStepState[]; // fixed three elements in STEP_ORDER\n\t/** Cumulative feedback rounds across all steps. */\n\troundCount: number;\n\t/**\n\t * Additions submitted from the page but not yet structured into blocks by\n\t * the model — the server-side truth of gate condition three (terminal\n\t * audit D7). Cleared by the next alignment_set on the active step.\n\t */\n\tpendingFeedback?: { round: number; additions: string[] };\n\t/**\n\t * Historical version snapshots (走查 2026-10-03): the active-step block\n\t * set archived before each revisoning `alignment_set`. Append-only with\n\t * bounded rolling; the page renders them read-only — only the latest\n\t * version accepts approvals/comments/answers.\n\t */\n\tversions?: AlignmentVersionSnapshot[];\n}\n\nexport interface AlignmentState {\n\talignments: AlignmentRecord[];\n}\n\nexport type AlignmentTransitionEvent =\n\t| \"round.submitted\"\n\t| \"round.delivered\"\n\t| \"step.confirmed\"\n\t| \"step.retreated\"\n\t| \"design.locked\" // 方案锁定、进入终审总览(走查 2026-10-03)\n\t| \"version.rolled-back\" // 步内版本回退(走查 2026-10-03)\n\t| \"alignment.cancelled\"\n\t| \"alignment.completed\";\n\n/** Append-only audit entry: one per user round, confirmation, retreat, cancel, completion. */\nexport interface AlignmentTransitionEntry {\n\talignmentId: string;\n\tstep?: AlignmentStepId; // alignment-level transitions carry no step\n\tevent: AlignmentTransitionEvent;\n\tround?: number;\n\treason: { code: string; detail?: string };\n\t/** Anchors the adjacent alignment.state snapshot. */\n\trevision: number;\n}\n\n/** A user comment submitted from the page (§5 round flow 3). */\nexport interface RoundPostComment {\n\tblockId: string;\n\tquote: string;\n\tnote: string;\n\tescalate?: boolean;\n}\n\n/** A reply to an assistant comment (answer/dismiss are mutually exclusive). */\nexport interface RoundPostCommentReply {\n\tcommentId: string;\n\tblockId: string;\n\tanswer?: string;\n\tdismiss?: boolean;\n}\n\n/** An answer to a missing-block fill-in. */\nexport interface RoundPostAnswer {\n\tblockId: string;\n\tvalue: string;\n}\n\n/** POST /round body (§5 round flow 3; baseRevision is the anti-staleness gate, terminal audit D6). */\nexport interface AlignmentRoundPost {\n\tbaseRevision: number;\n\t/**\n\t * Page-driven action (走查 2026-10-03): default `feedback`; `retreat`\n\t * rolls the task back to an earlier locked step (`targetStep`, downstream\n\t * steps are discarded); `rollback` restores an archived version of the\n\t * active step (`targetRevision`, step-scoped, comments survive).\n\t */\n\taction?: \"feedback\" | \"retreat\" | \"rollback\";\n\ttargetStep?: AlignmentStepId;\n\ttargetRevision?: number;\n\t/** Full approved-block id set of the active step (server mirrors the page). */\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n}\n\n/** Structured feedback injected into the session after a user round (§5 round flow 3). */\nexport interface AlignmentRoundResult {\n\talignmentId: string;\n\tround: number;\n\tstep: AlignmentStepId;\n\trevision: number;\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n\t/** Present when the whole alignment completed with this round (design step confirmed). */\n\tfinalBaseline?: { step: AlignmentStepId; kind: AlignmentBlockKind; id: string; line: string }[];\n\tbaselineFilePath?: string;\n}\n\n/** Why a block still needs attention — drives the page spotlight and `/alignment why`. */\nexport interface PendingItem {\n\tblockId: string;\n\treason: \"unapproved\" | \"missing-empty\" | \"assistant-question-open\";\n}\n\n/** Gate facts (总则 2): three server-checkable conditions plus pending items. */\nexport interface GateSnapshot {\n\tunapproved: number;\n\topenComments: number;\n\tpendingAdditions: number;\n\tallGreen: boolean;\n\tpending: PendingItem[];\n}\n\n/** Error codes thrown by the engine; index.ts lets them surface as tool errors verbatim. */\nexport type AlignmentErrorCode =\n\t| \"invalid-id\"\n\t| \"active-alignment-exists\"\n\t| \"not-found\"\n\t| \"terminal-state\"\n\t| \"stale-revision\"\n\t| \"stale-state\"\n\t| \"step-not-writable\"\n\t| \"step-not-unlocked\"\n\t| \"block-has-open-comments\"\n\t| \"comment-ownership\"\n\t| \"comment-quote-mismatch\"\n\t| \"gate-not-satisfied\"\n\t| \"confirmed-with-feedback\"\n\t| \"invalid-block\"\n\t| \"invalid-comment\"\n\t| \"invalid-input\"\n\t| \"retreat-target-invalid\";\n\nexport class AlignmentError extends Error {\n\treadonly code: AlignmentErrorCode;\n\n\tconstructor(code: AlignmentErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"AlignmentError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Hard bounds (设计 §4 有界性): alignment state enters session entries, keep it bounded. */\n/** Archived pre-revision step block set; the page views these read-only. */\nexport interface AlignmentVersionSnapshot {\n\t/** Revision at archive time — the version's anchor. */\n\trevision: number;\n\t/** Round at archive time. */\n\tround: number;\n\t/** Which step's block set was archived. */\n\tstep: AlignmentStepId;\n\t/** Full archived block set (rendered read-only). */\n\tblocks: AlignmentBlock[];\n\t/** Set when the block set exceeded the per-snapshot size budget. */\n\ttruncated?: true;\n}\n\nexport const ALIGNMENT_LIMITS = {\n\tcontentMaxLength: 8192,\n\trationaleMaxLength: 2048,\n\tnotesPerBlockMax: 50,\n\tnoteMaxLength: 2048,\n\tblocksPerStepMax: 300,\n\t/** Rolling retention for version snapshots (走查 2026-10-03). */\n\tversionsMax: 10,\n\t/** Per-snapshot serialization budget; over this only the anchor is kept. */\n\tversionsSnapshotMaxBytes: 262_144,\n\tadditionMaxLength: 4096,\n\tanswerMaxLength: 4096,\n} as const;\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,eAAO,MAAM,UAAU,4CAA6C,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3F,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,WAAW,CAAC;AAE1D,MAAM,MAAM,8BAA8B,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,CAAC;AAEvF,uFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,sBAAsB,CAAC;IAC/B,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,yFAAuF;IACvF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,UAAU,CAAC,EAAE;QACZ,IAAI,EAAE,8BAA8B,CAAC;QACrC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX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a,GACb,mBAAmB,GACnB,mBAAmB,GACnB,yBAAyB,GACzB,0BAA0B,GAC1B,mBAAmB,GACnB,wBAAwB,GACxB,oBAAoB,GACpB,yBAAyB,GACzB,eAAe,GACf,iBAAiB,GACjB,eAAe,GACf,wBAAwB,CAAC;AAE5B,qBAAa,cAAe,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAElC,YAAY,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAIpD;CACD;AAED,mGAAwF;AACxF,4EAA4E;AAC5E,MAAM,WAAW,wBAAwB;IACxC,yDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,EAAE,eAAe,CAAC;IACtB,oDAAoD;IACpD,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,oEAAoE;IACpE,SAAS,CAAC,EAAE,IAAI,CAAC;CACjB;AAED,eAAO,MAAM,gBAAgB;;;;;;IAM5B,mEAA+D;;IAE/D,4EAA4E;;;;CAInE,CAAC","sourcesContent":["/**\n * Data model of the alignment capability plugin\n * (`docs/design/需求对齐插件设计.md` §4). This module declares shapes only —\n * every conversion rule lives in `engine.ts` and every host-facing side effect\n * (entries, events, injection, HTTP) lives in `index.ts` / `http-server.ts`.\n */\n\n/** The three funnel steps, in canonical order. */\nexport const STEP_ORDER = [\"objective\", \"detail\", \"design\"] as const;\n\nexport type AlignmentStepId = (typeof STEP_ORDER)[number];\n\nexport type AlignmentBlockKind = \"fact\" | \"assumption\" | \"decision\" | \"missing\" | \"visual\";\n\nexport type AlignmentCommentAuthor = \"user\" | \"assistant\";\n\nexport type AlignmentCommentResolutionKind = \"answered\" | \"dismissed\" | \"incorporated\";\n\n/** Bidirectional block annotation (设计 §4: author distinguishes the direction). */\nexport interface AlignmentComment {\n\tid: string; // unique within the owning block\n\tauthor: AlignmentCommentAuthor;\n\t/** Exact in-block quote; required for user comments, optional for assistant ones. */\n\tquote?: string;\n\tnote: string;\n\t/** User flag: the objection targets an earlier (upstream) step — retreat candidate. */\n\tescalate?: boolean;\n\tstatus: \"open\" | \"resolved\";\n\tresolution?: {\n\t\tkind: AlignmentCommentResolutionKind;\n\t\ttext?: string;\n\t\tround?: number;\n\t};\n\tcreatedAtRound: number;\n}\n\nexport interface AlignmentBlock {\n\tid: string; // stable within the step\n\tkind: AlignmentBlockKind;\n\tcontent: string;\n\trationale?: string;\n\timpact?: string[];\n\tstatus: \"pending\" | \"approved\";\n\t/** Engine-computed fingerprint (kind+content+rationale+impact); cross-round approval inheritance key. */\n\tcontentHash: string;\n\t/** Round in which the content last changed; drives the \"modified this round\" badge. */\n\tmodifiedInRound?: number;\n\t/** Stored fill-in for a missing block — the user's own words, kept verbatim until the model restructures the block. */\n\tdraftAnswer?: string;\n\tcomments: AlignmentComment[];\n}\n\nexport interface AlignmentStepState {\n\tstep: AlignmentStepId;\n\t/** pending = not unlocked yet (terminal-audit D2); reset = retreated into, confirmations cleared. */\n\tstatus: \"pending\" | \"locked\" | \"active\" | \"reset\";\n\t/** Round count at confirmation time (entry-sequence-like anchor, not wall clock). */\n\tbaselineConfirmedAtRound?: number;\n\tblocks: AlignmentBlock[];\n}\n\nexport interface AlignmentRecord {\n\tid: string;\n\ttitle: string;\n\t/** Soft reference to goal.state (advisory, #10): dangling only warns. */\n\tgoalId?: string;\n\t/**\n\t * Created-as-aligning (no draft state, terminal audit D3). `finalizing`\n\t * (走查 2026-10-03) = all three steps locked, waiting for the final\n\t * review tab confirmation — only that confirmation completes the\n\t * alignment and writes the baseline (方案确认 ≠ 终版确认).\n\t */\n\tstatus: \"aligning\" | \"finalizing\" | \"completed\" | \"cancelled\";\n\t/**\n\t * Monotonic for alignment_set callers; engine-triggered conversions\n\t * (freeze/unlock/retreat/complete) auto-increment it too (workflow\n\t * precedent, terminal audit D4). Carried on round results so the model\n\t * always knows the next acceptable revision.\n\t */\n\trevision: number;\n\t/** Points at the single step with status \"active\"; pending/reset/locked steps are not writable. */\n\tactiveStep: AlignmentStepId;\n\tsteps: AlignmentStepState[]; // fixed three elements in STEP_ORDER\n\t/** Cumulative feedback rounds across all steps. */\n\troundCount: number;\n\t/**\n\t * Additions submitted from the page but not yet structured into blocks by\n\t * the model — the server-side truth of gate condition three (terminal\n\t * audit D7). Cleared by the next alignment_set on the active step.\n\t */\n\tpendingFeedback?: { round: number; additions: string[] };\n\t/**\n\t * Historical version snapshots (走查 2026-10-03): the active-step block\n\t * set archived before each revisoning `alignment_set`. Append-only with\n\t * bounded rolling; the page renders them read-only — only the latest\n\t * version accepts approvals/comments/answers.\n\t */\n\tversions?: AlignmentVersionSnapshot[];\n}\n\nexport interface AlignmentState {\n\talignments: AlignmentRecord[];\n}\n\nexport type AlignmentTransitionEvent =\n\t| \"round.submitted\"\n\t| \"round.delivered\"\n\t| \"step.confirmed\"\n\t| \"step.retreated\"\n\t| \"design.locked\" // 方案锁定、进入终审总览(走查 2026-10-03)\n\t| \"version.rolled-back\" // 步内版本回退(走查 2026-10-03)\n\t| \"alignment.cancelled\"\n\t| \"alignment.completed\";\n\n/** Append-only audit entry: one per user round, confirmation, retreat, cancel, completion. */\nexport interface AlignmentTransitionEntry {\n\talignmentId: string;\n\tstep?: AlignmentStepId; // alignment-level transitions carry no step\n\tevent: AlignmentTransitionEvent;\n\tround?: number;\n\treason: { code: string; detail?: string };\n\t/** Anchors the adjacent alignment.state snapshot. */\n\trevision: number;\n}\n\n/** A user comment submitted from the page (§5 round flow 3). */\nexport interface RoundPostComment {\n\tblockId: string;\n\tquote: string;\n\tnote: string;\n\tescalate?: boolean;\n}\n\n/** A reply to an assistant comment (answer/dismiss are mutually exclusive). */\nexport interface RoundPostCommentReply {\n\tcommentId: string;\n\tblockId: string;\n\tanswer?: string;\n\tdismiss?: boolean;\n}\n\n/** An answer to a missing-block fill-in. */\nexport interface RoundPostAnswer {\n\tblockId: string;\n\tvalue: string;\n}\n\n/** POST /round body (§5 round flow 3; baseRevision is the anti-staleness gate, terminal audit D6). */\nexport interface AlignmentRoundPost {\n\tbaseRevision: number;\n\t/**\n\t * Page-driven action (走查 2026-10-03): default `feedback`; `retreat`\n\t * rolls the task back to an earlier locked step (`targetStep`, downstream\n\t * steps are discarded); `rollback` restores an archived version of the\n\t * active step (`targetRevision`, step-scoped, comments survive).\n\t */\n\taction?: \"feedback\" | \"retreat\" | \"rollback\";\n\ttargetStep?: AlignmentStepId;\n\ttargetRevision?: number;\n\t/** Full approved-block id set of the active step (server mirrors the page). */\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n}\n\n/** Structured feedback injected into the session after a user round (§5 round flow 3). */\nexport interface AlignmentRoundResult {\n\talignmentId: string;\n\tround: number;\n\tstep: AlignmentStepId;\n\trevision: number;\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n\t/** Present when the whole alignment completed with this round (design step confirmed). */\n\tfinalBaseline?: { step: AlignmentStepId; kind: AlignmentBlockKind; id: string; line: string }[];\n\tbaselineFilePath?: string;\n}\n\n/** Why a block still needs attention — drives the page spotlight and `/alignment why`. */\nexport interface PendingItem {\n\tblockId: string;\n\treason: \"unapproved\" | \"missing-empty\" | \"assistant-question-open\";\n}\n\n/** Gate facts (总则 2): three server-checkable conditions plus pending items. */\nexport interface GateSnapshot {\n\tunapproved: number;\n\topenComments: number;\n\tpendingAdditions: number;\n\tallGreen: boolean;\n\tpending: PendingItem[];\n}\n\n/** Error codes thrown by the engine; index.ts lets them surface as tool errors verbatim. */\nexport type AlignmentErrorCode =\n\t| \"invalid-id\"\n\t| \"active-alignment-exists\"\n\t| \"not-found\"\n\t| \"terminal-state\"\n\t| \"stale-revision\"\n\t| \"stale-state\"\n\t| \"step-not-writable\"\n\t| \"step-not-unlocked\"\n\t| \"block-has-open-comments\"\n\t| \"approved-blocks-conflict\" // v3.7:改写已批准块指纹且未携带 reviseApproved(§5 总则 3)\n\t| \"comment-ownership\"\n\t| \"comment-quote-mismatch\"\n\t| \"gate-not-satisfied\"\n\t| \"confirmed-with-feedback\"\n\t| \"invalid-block\"\n\t| \"invalid-comment\"\n\t| \"invalid-input\"\n\t| \"retreat-target-invalid\";\n\nexport class AlignmentError extends Error {\n\treadonly code: AlignmentErrorCode;\n\n\tconstructor(code: AlignmentErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"AlignmentError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Hard bounds (设计 §4 有界性): alignment state enters session entries, keep it bounded. */\n/** Archived pre-revision step block set; the page views these read-only. */\nexport interface AlignmentVersionSnapshot {\n\t/** Revision at archive time — the version's anchor. */\n\trevision: number;\n\t/** Round at archive time. */\n\tround: number;\n\t/** Which step's block set was archived. */\n\tstep: AlignmentStepId;\n\t/** Full archived block set (rendered read-only). */\n\tblocks: AlignmentBlock[];\n\t/** Set when the block set exceeded the per-snapshot size budget. */\n\ttruncated?: true;\n}\n\nexport const ALIGNMENT_LIMITS = {\n\tcontentMaxLength: 8192,\n\trationaleMaxLength: 2048,\n\tnotesPerBlockMax: 50,\n\tnoteMaxLength: 2048,\n\tblocksPerStepMax: 300,\n\t/** Rolling retention for version snapshots (走查 2026-10-03). */\n\tversionsMax: 10,\n\t/** Per-snapshot serialization budget; over this only the anchor is kept. */\n\tversionsSnapshotMaxBytes: 262_144,\n\tadditionMaxLength: 4096,\n\tanswerMaxLength: 4096,\n} as const;\n"]}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAoNrE,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC/B,IAAI,CAAqB;IAElC,YAAY,IAAwB,EAAE,OAAe,EAAE;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;CACD;AAiBD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,GAAG;IACrB,mEAA+D;IAC/D,WAAW,EAAE,EAAE;IACf,4EAA4E;IAC5E,wBAAwB,EAAE,OAAO;IACjC,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;CACZ,CAAC","sourcesContent":["/**\n * Data model of the alignment capability plugin\n * (`docs/design/需求对齐插件设计.md` §4). This module declares shapes only —\n * every conversion rule lives in `engine.ts` and every host-facing side effect\n * (entries, events, injection, HTTP) lives in `index.ts` / `http-server.ts`.\n */\n\n/** The three funnel steps, in canonical order. */\nexport const STEP_ORDER = [\"objective\", \"detail\", \"design\"] as const;\n\nexport type AlignmentStepId = (typeof STEP_ORDER)[number];\n\nexport type AlignmentBlockKind = \"fact\" | \"assumption\" | \"decision\" | \"missing\" | \"visual\";\n\nexport type AlignmentCommentAuthor = \"user\" | \"assistant\";\n\nexport type AlignmentCommentResolutionKind = \"answered\" | \"dismissed\" | \"incorporated\";\n\n/** Bidirectional block annotation (设计 §4: author distinguishes the direction). */\nexport interface AlignmentComment {\n\tid: string; // unique within the owning block\n\tauthor: AlignmentCommentAuthor;\n\t/** Exact in-block quote; required for user comments, optional for assistant ones. */\n\tquote?: string;\n\tnote: string;\n\t/** User flag: the objection targets an earlier (upstream) step — retreat candidate. */\n\tescalate?: boolean;\n\tstatus: \"open\" | \"resolved\";\n\tresolution?: {\n\t\tkind: AlignmentCommentResolutionKind;\n\t\ttext?: string;\n\t\tround?: number;\n\t};\n\tcreatedAtRound: number;\n}\n\nexport interface AlignmentBlock {\n\tid: string; // stable within the step\n\tkind: AlignmentBlockKind;\n\tcontent: string;\n\trationale?: string;\n\timpact?: string[];\n\tstatus: \"pending\" | \"approved\";\n\t/** Engine-computed fingerprint (kind+content+rationale+impact); cross-round approval inheritance key. */\n\tcontentHash: string;\n\t/** Round in which the content last changed; drives the \"modified this round\" badge. */\n\tmodifiedInRound?: number;\n\t/** Stored fill-in for a missing block — the user's own words, kept verbatim until the model restructures the block. */\n\tdraftAnswer?: string;\n\tcomments: AlignmentComment[];\n}\n\nexport interface AlignmentStepState {\n\tstep: AlignmentStepId;\n\t/** pending = not unlocked yet (terminal-audit D2); reset = retreated into, confirmations cleared. */\n\tstatus: \"pending\" | \"locked\" | \"active\" | \"reset\";\n\t/** Round count at confirmation time (entry-sequence-like anchor, not wall clock). */\n\tbaselineConfirmedAtRound?: number;\n\tblocks: AlignmentBlock[];\n}\n\nexport interface AlignmentRecord {\n\tid: string;\n\ttitle: string;\n\t/** Soft reference to goal.state (advisory, #10): dangling only warns. */\n\tgoalId?: string;\n\t/**\n\t * Created-as-aligning (no draft state, terminal audit D3). `finalizing`\n\t * (走查 2026-10-03) = all three steps locked, waiting for the final\n\t * review tab confirmation — only that confirmation completes the\n\t * alignment and writes the baseline (方案确认 ≠ 终版确认).\n\t */\n\tstatus: \"aligning\" | \"finalizing\" | \"completed\" | \"cancelled\";\n\t/**\n\t * Monotonic for alignment_set callers; engine-triggered conversions\n\t * (freeze/unlock/retreat/complete) auto-increment it too (workflow\n\t * precedent, terminal audit D4). Carried on round results so the model\n\t * always knows the next acceptable revision.\n\t */\n\trevision: number;\n\t/** Points at the single step with status \"active\"; pending/reset/locked steps are not writable. */\n\tactiveStep: AlignmentStepId;\n\tsteps: AlignmentStepState[]; // fixed three elements in STEP_ORDER\n\t/** Cumulative feedback rounds across all steps. */\n\troundCount: number;\n\t/**\n\t * Additions submitted from the page but not yet structured into blocks by\n\t * the model — the server-side truth of gate condition three (terminal\n\t * audit D7). Cleared by the next alignment_set on the active step.\n\t */\n\tpendingFeedback?: { round: number; additions: string[] };\n\t/**\n\t * Historical version snapshots (走查 2026-10-03): the active-step block\n\t * set archived before each revisoning `alignment_set`. Append-only with\n\t * bounded rolling; the page renders them read-only — only the latest\n\t * version accepts approvals/comments/answers.\n\t */\n\tversions?: AlignmentVersionSnapshot[];\n}\n\nexport interface AlignmentState {\n\talignments: AlignmentRecord[];\n}\n\nexport type AlignmentTransitionEvent =\n\t| \"round.submitted\"\n\t| \"round.delivered\"\n\t| \"step.confirmed\"\n\t| \"step.retreated\"\n\t| \"design.locked\" // 方案锁定、进入终审总览(走查 2026-10-03)\n\t| \"version.rolled-back\" // 步内版本回退(走查 2026-10-03)\n\t| \"alignment.cancelled\"\n\t| \"alignment.completed\";\n\n/** Append-only audit entry: one per user round, confirmation, retreat, cancel, completion. */\nexport interface AlignmentTransitionEntry {\n\talignmentId: string;\n\tstep?: AlignmentStepId; // alignment-level transitions carry no step\n\tevent: AlignmentTransitionEvent;\n\tround?: number;\n\treason: { code: string; detail?: string };\n\t/** Anchors the adjacent alignment.state snapshot. */\n\trevision: number;\n}\n\n/** A user comment submitted from the page (§5 round flow 3). */\nexport interface RoundPostComment {\n\tblockId: string;\n\tquote: string;\n\tnote: string;\n\tescalate?: boolean;\n}\n\n/** A reply to an assistant comment (answer/dismiss are mutually exclusive). */\nexport interface RoundPostCommentReply {\n\tcommentId: string;\n\tblockId: string;\n\tanswer?: string;\n\tdismiss?: boolean;\n}\n\n/** An answer to a missing-block fill-in. */\nexport interface RoundPostAnswer {\n\tblockId: string;\n\tvalue: string;\n}\n\n/** POST /round body (§5 round flow 3; baseRevision is the anti-staleness gate, terminal audit D6). */\nexport interface AlignmentRoundPost {\n\tbaseRevision: number;\n\t/**\n\t * Page-driven action (走查 2026-10-03): default `feedback`; `retreat`\n\t * rolls the task back to an earlier locked step (`targetStep`, downstream\n\t * steps are discarded); `rollback` restores an archived version of the\n\t * active step (`targetRevision`, step-scoped, comments survive).\n\t */\n\taction?: \"feedback\" | \"retreat\" | \"rollback\";\n\ttargetStep?: AlignmentStepId;\n\ttargetRevision?: number;\n\t/** Full approved-block id set of the active step (server mirrors the page). */\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n}\n\n/** Structured feedback injected into the session after a user round (§5 round flow 3). */\nexport interface AlignmentRoundResult {\n\talignmentId: string;\n\tround: number;\n\tstep: AlignmentStepId;\n\trevision: number;\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n\t/** Present when the whole alignment completed with this round (design step confirmed). */\n\tfinalBaseline?: { step: AlignmentStepId; kind: AlignmentBlockKind; id: string; line: string }[];\n\tbaselineFilePath?: string;\n}\n\n/** Why a block still needs attention — drives the page spotlight and `/alignment why`. */\nexport interface PendingItem {\n\tblockId: string;\n\treason: \"unapproved\" | \"missing-empty\" | \"assistant-question-open\";\n}\n\n/** Gate facts (总则 2): three server-checkable conditions plus pending items. */\nexport interface GateSnapshot {\n\tunapproved: number;\n\topenComments: number;\n\tpendingAdditions: number;\n\tallGreen: boolean;\n\tpending: PendingItem[];\n}\n\n/** Error codes thrown by the engine; index.ts lets them surface as tool errors verbatim. */\nexport type AlignmentErrorCode =\n\t| \"invalid-id\"\n\t| \"active-alignment-exists\"\n\t| \"not-found\"\n\t| \"terminal-state\"\n\t| \"stale-revision\"\n\t| \"stale-state\"\n\t| \"step-not-writable\"\n\t| \"step-not-unlocked\"\n\t| \"block-has-open-comments\"\n\t| \"comment-ownership\"\n\t| \"comment-quote-mismatch\"\n\t| \"gate-not-satisfied\"\n\t| \"confirmed-with-feedback\"\n\t| \"invalid-block\"\n\t| \"invalid-comment\"\n\t| \"invalid-input\"\n\t| \"retreat-target-invalid\";\n\nexport class AlignmentError extends Error {\n\treadonly code: AlignmentErrorCode;\n\n\tconstructor(code: AlignmentErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"AlignmentError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Hard bounds (设计 §4 有界性): alignment state enters session entries, keep it bounded. */\n/** Archived pre-revision step block set; the page views these read-only. */\nexport interface AlignmentVersionSnapshot {\n\t/** Revision at archive time — the version's anchor. */\n\trevision: number;\n\t/** Round at archive time. */\n\tround: number;\n\t/** Which step's block set was archived. */\n\tstep: AlignmentStepId;\n\t/** Full archived block set (rendered read-only). */\n\tblocks: AlignmentBlock[];\n\t/** Set when the block set exceeded the per-snapshot size budget. */\n\ttruncated?: true;\n}\n\nexport const ALIGNMENT_LIMITS = {\n\tcontentMaxLength: 8192,\n\trationaleMaxLength: 2048,\n\tnotesPerBlockMax: 50,\n\tnoteMaxLength: 2048,\n\tblocksPerStepMax: 300,\n\t/** Rolling retention for version snapshots (走查 2026-10-03). */\n\tversionsMax: 10,\n\t/** Per-snapshot serialization budget; over this only the anchor is kept. */\n\tversionsSnapshotMaxBytes: 262_144,\n\tadditionMaxLength: 4096,\n\tanswerMaxLength: 4096,\n} as const;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAqNrE,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC/B,IAAI,CAAqB;IAElC,YAAY,IAAwB,EAAE,OAAe,EAAE;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;CACD;AAiBD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,GAAG;IACrB,mEAA+D;IAC/D,WAAW,EAAE,EAAE;IACf,4EAA4E;IAC5E,wBAAwB,EAAE,OAAO;IACjC,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;CACZ,CAAC","sourcesContent":["/**\n * Data model of the alignment capability plugin\n * (`docs/design/需求对齐插件设计.md` §4). This module declares shapes only —\n * every conversion rule lives in `engine.ts` and every host-facing side effect\n * (entries, events, injection, HTTP) lives in `index.ts` / `http-server.ts`.\n */\n\n/** The three funnel steps, in canonical order. */\nexport const STEP_ORDER = [\"objective\", \"detail\", \"design\"] as const;\n\nexport type AlignmentStepId = (typeof STEP_ORDER)[number];\n\nexport type AlignmentBlockKind = \"fact\" | \"assumption\" | \"decision\" | \"missing\" | \"visual\";\n\nexport type AlignmentCommentAuthor = \"user\" | \"assistant\";\n\nexport type AlignmentCommentResolutionKind = \"answered\" | \"dismissed\" | \"incorporated\";\n\n/** Bidirectional block annotation (设计 §4: author distinguishes the direction). */\nexport interface AlignmentComment {\n\tid: string; // unique within the owning block\n\tauthor: AlignmentCommentAuthor;\n\t/** Exact in-block quote; required for user comments, optional for assistant ones. */\n\tquote?: string;\n\tnote: string;\n\t/** User flag: the objection targets an earlier (upstream) step — retreat candidate. */\n\tescalate?: boolean;\n\tstatus: \"open\" | \"resolved\";\n\tresolution?: {\n\t\tkind: AlignmentCommentResolutionKind;\n\t\ttext?: string;\n\t\tround?: number;\n\t};\n\tcreatedAtRound: number;\n}\n\nexport interface AlignmentBlock {\n\tid: string; // stable within the step\n\tkind: AlignmentBlockKind;\n\tcontent: string;\n\trationale?: string;\n\timpact?: string[];\n\tstatus: \"pending\" | \"approved\";\n\t/** Engine-computed fingerprint (kind+content+rationale+impact); cross-round approval inheritance key. */\n\tcontentHash: string;\n\t/** Round in which the content last changed; drives the \"modified this round\" badge. */\n\tmodifiedInRound?: number;\n\t/** Stored fill-in for a missing block — the user's own words, kept verbatim until the model restructures the block. */\n\tdraftAnswer?: string;\n\tcomments: AlignmentComment[];\n}\n\nexport interface AlignmentStepState {\n\tstep: AlignmentStepId;\n\t/** pending = not unlocked yet (terminal-audit D2); reset = retreated into, confirmations cleared. */\n\tstatus: \"pending\" | \"locked\" | \"active\" | \"reset\";\n\t/** Round count at confirmation time (entry-sequence-like anchor, not wall clock). */\n\tbaselineConfirmedAtRound?: number;\n\tblocks: AlignmentBlock[];\n}\n\nexport interface AlignmentRecord {\n\tid: string;\n\ttitle: string;\n\t/** Soft reference to goal.state (advisory, #10): dangling only warns. */\n\tgoalId?: string;\n\t/**\n\t * Created-as-aligning (no draft state, terminal audit D3). `finalizing`\n\t * (走查 2026-10-03) = all three steps locked, waiting for the final\n\t * review tab confirmation — only that confirmation completes the\n\t * alignment and writes the baseline (方案确认 ≠ 终版确认).\n\t */\n\tstatus: \"aligning\" | \"finalizing\" | \"completed\" | \"cancelled\";\n\t/**\n\t * Monotonic for alignment_set callers; engine-triggered conversions\n\t * (freeze/unlock/retreat/complete) auto-increment it too (workflow\n\t * precedent, terminal audit D4). Carried on round results so the model\n\t * always knows the next acceptable revision.\n\t */\n\trevision: number;\n\t/** Points at the single step with status \"active\"; pending/reset/locked steps are not writable. */\n\tactiveStep: AlignmentStepId;\n\tsteps: AlignmentStepState[]; // fixed three elements in STEP_ORDER\n\t/** Cumulative feedback rounds across all steps. */\n\troundCount: number;\n\t/**\n\t * Additions submitted from the page but not yet structured into blocks by\n\t * the model — the server-side truth of gate condition three (terminal\n\t * audit D7). Cleared by the next alignment_set on the active step.\n\t */\n\tpendingFeedback?: { round: number; additions: string[] };\n\t/**\n\t * Historical version snapshots (走查 2026-10-03): the active-step block\n\t * set archived before each revisoning `alignment_set`. Append-only with\n\t * bounded rolling; the page renders them read-only — only the latest\n\t * version accepts approvals/comments/answers.\n\t */\n\tversions?: AlignmentVersionSnapshot[];\n}\n\nexport interface AlignmentState {\n\talignments: AlignmentRecord[];\n}\n\nexport type AlignmentTransitionEvent =\n\t| \"round.submitted\"\n\t| \"round.delivered\"\n\t| \"step.confirmed\"\n\t| \"step.retreated\"\n\t| \"design.locked\" // 方案锁定、进入终审总览(走查 2026-10-03)\n\t| \"version.rolled-back\" // 步内版本回退(走查 2026-10-03)\n\t| \"alignment.cancelled\"\n\t| \"alignment.completed\";\n\n/** Append-only audit entry: one per user round, confirmation, retreat, cancel, completion. */\nexport interface AlignmentTransitionEntry {\n\talignmentId: string;\n\tstep?: AlignmentStepId; // alignment-level transitions carry no step\n\tevent: AlignmentTransitionEvent;\n\tround?: number;\n\treason: { code: string; detail?: string };\n\t/** Anchors the adjacent alignment.state snapshot. */\n\trevision: number;\n}\n\n/** A user comment submitted from the page (§5 round flow 3). */\nexport interface RoundPostComment {\n\tblockId: string;\n\tquote: string;\n\tnote: string;\n\tescalate?: boolean;\n}\n\n/** A reply to an assistant comment (answer/dismiss are mutually exclusive). */\nexport interface RoundPostCommentReply {\n\tcommentId: string;\n\tblockId: string;\n\tanswer?: string;\n\tdismiss?: boolean;\n}\n\n/** An answer to a missing-block fill-in. */\nexport interface RoundPostAnswer {\n\tblockId: string;\n\tvalue: string;\n}\n\n/** POST /round body (§5 round flow 3; baseRevision is the anti-staleness gate, terminal audit D6). */\nexport interface AlignmentRoundPost {\n\tbaseRevision: number;\n\t/**\n\t * Page-driven action (走查 2026-10-03): default `feedback`; `retreat`\n\t * rolls the task back to an earlier locked step (`targetStep`, downstream\n\t * steps are discarded); `rollback` restores an archived version of the\n\t * active step (`targetRevision`, step-scoped, comments survive).\n\t */\n\taction?: \"feedback\" | \"retreat\" | \"rollback\";\n\ttargetStep?: AlignmentStepId;\n\ttargetRevision?: number;\n\t/** Full approved-block id set of the active step (server mirrors the page). */\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n}\n\n/** Structured feedback injected into the session after a user round (§5 round flow 3). */\nexport interface AlignmentRoundResult {\n\talignmentId: string;\n\tround: number;\n\tstep: AlignmentStepId;\n\trevision: number;\n\tapprovals: string[];\n\tcomments: RoundPostComment[];\n\tcommentReplies: RoundPostCommentReply[];\n\tanswers: RoundPostAnswer[];\n\tadditions: string[];\n\tstepConfirmed: boolean;\n\t/** Present when the whole alignment completed with this round (design step confirmed). */\n\tfinalBaseline?: { step: AlignmentStepId; kind: AlignmentBlockKind; id: string; line: string }[];\n\tbaselineFilePath?: string;\n}\n\n/** Why a block still needs attention — drives the page spotlight and `/alignment why`. */\nexport interface PendingItem {\n\tblockId: string;\n\treason: \"unapproved\" | \"missing-empty\" | \"assistant-question-open\";\n}\n\n/** Gate facts (总则 2): three server-checkable conditions plus pending items. */\nexport interface GateSnapshot {\n\tunapproved: number;\n\topenComments: number;\n\tpendingAdditions: number;\n\tallGreen: boolean;\n\tpending: PendingItem[];\n}\n\n/** Error codes thrown by the engine; index.ts lets them surface as tool errors verbatim. */\nexport type AlignmentErrorCode =\n\t| \"invalid-id\"\n\t| \"active-alignment-exists\"\n\t| \"not-found\"\n\t| \"terminal-state\"\n\t| \"stale-revision\"\n\t| \"stale-state\"\n\t| \"step-not-writable\"\n\t| \"step-not-unlocked\"\n\t| \"block-has-open-comments\"\n\t| \"approved-blocks-conflict\" // v3.7:改写已批准块指纹且未携带 reviseApproved(§5 总则 3)\n\t| \"comment-ownership\"\n\t| \"comment-quote-mismatch\"\n\t| \"gate-not-satisfied\"\n\t| \"confirmed-with-feedback\"\n\t| \"invalid-block\"\n\t| \"invalid-comment\"\n\t| \"invalid-input\"\n\t| \"retreat-target-invalid\";\n\nexport class AlignmentError extends Error {\n\treadonly code: AlignmentErrorCode;\n\n\tconstructor(code: AlignmentErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"AlignmentError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Hard bounds (设计 §4 有界性): alignment state enters session entries, keep it bounded. */\n/** Archived pre-revision step block set; the page views these read-only. */\nexport interface AlignmentVersionSnapshot {\n\t/** Revision at archive time — the version's anchor. */\n\trevision: number;\n\t/** Round at archive time. */\n\tround: number;\n\t/** Which step's block set was archived. */\n\tstep: AlignmentStepId;\n\t/** Full archived block set (rendered read-only). */\n\tblocks: AlignmentBlock[];\n\t/** Set when the block set exceeded the per-snapshot size budget. */\n\ttruncated?: true;\n}\n\nexport const ALIGNMENT_LIMITS = {\n\tcontentMaxLength: 8192,\n\trationaleMaxLength: 2048,\n\tnotesPerBlockMax: 50,\n\tnoteMaxLength: 2048,\n\tblocksPerStepMax: 300,\n\t/** Rolling retention for version snapshots (走查 2026-10-03). */\n\tversionsMax: 10,\n\t/** Per-snapshot serialization budget; over this only the anchor is kept. */\n\tversionsSnapshotMaxBytes: 262_144,\n\tadditionMaxLength: 4096,\n\tanswerMaxLength: 4096,\n} as const;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-agent-forge/plugin-alignment",
|
|
3
|
-
"version": "0.88.
|
|
3
|
+
"version": "0.88.6",
|
|
4
4
|
"description": "Alignment capability plugin for Agent Forge (three-step requirement alignment funnel with an HTML confirmation page)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"typebox": "1.3.27",
|
|
47
|
-
"@ai-agent-forge/plugin-sdk": "^0.88.
|
|
47
|
+
"@ai-agent-forge/plugin-sdk": "^0.88.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"shx": "0.4.0",
|