@ai-agent-forge/plugin-alignment 0.88.1

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.
@@ -0,0 +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,CAAC;AAEhF,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,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,UAAU,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,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\";\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"]}
package/dist/types.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Data model of the alignment capability plugin
3
+ * (`docs/design/需求对齐插件设计.md` §4). This module declares shapes only —
4
+ * every conversion rule lives in `engine.ts` and every host-facing side effect
5
+ * (entries, events, injection, HTTP) lives in `index.ts` / `http-server.ts`.
6
+ */
7
+ /** The three funnel steps, in canonical order. */
8
+ export const STEP_ORDER = ["objective", "detail", "design"];
9
+ export class AlignmentError extends Error {
10
+ code;
11
+ constructor(code, message) {
12
+ super(message);
13
+ this.name = "AlignmentError";
14
+ this.code = code;
15
+ }
16
+ }
17
+ export const ALIGNMENT_LIMITS = {
18
+ contentMaxLength: 8192,
19
+ rationaleMaxLength: 2048,
20
+ notesPerBlockMax: 50,
21
+ noteMaxLength: 2048,
22
+ blocksPerStepMax: 300,
23
+ /** Rolling retention for version snapshots (走查 2026-10-03). */
24
+ versionsMax: 10,
25
+ /** Per-snapshot serialization budget; over this only the anchor is kept. */
26
+ versionsSnapshotMaxBytes: 262_144,
27
+ additionMaxLength: 4096,
28
+ answerMaxLength: 4096,
29
+ };
30
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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\";\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"]}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@ai-agent-forge/plugin-alignment",
3
+ "version": "0.88.1",
4
+ "description": "Alignment capability plugin for Agent Forge (three-step requirement alignment funnel with an HTML confirmation page)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "agent-forge.json",
17
+ "plugin.json",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "clean": "shx rm -rf dist",
22
+ "build": "tsgo -p tsconfig.build.json",
23
+ "test": "vitest --run",
24
+ "prepublishOnly": "npm run clean && npm run build"
25
+ },
26
+ "keywords": [
27
+ "agent-forge",
28
+ "plugin",
29
+ "alignment"
30
+ ],
31
+ "author": "Agent Forge contributors",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/agent-forge/agent-forge.git",
36
+ "directory": "plugins/alignment"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/agent-forge/agent-forge/issues"
40
+ },
41
+ "homepage": "https://github.com/agent-forge/agent-forge#readme",
42
+ "engines": {
43
+ "node": ">=22.19.0"
44
+ },
45
+ "dependencies": {
46
+ "typebox": "1.3.27",
47
+ "@ai-agent-forge/plugin-sdk": "^0.88.1"
48
+ },
49
+ "devDependencies": {
50
+ "shx": "0.4.0",
51
+ "vitest": "4.1.11"
52
+ }
53
+ }
package/plugin.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "agent-forge.plugin.alignment",
3
+ "version": "0.88.1",
4
+ "apiVersion": "1-draft",
5
+ "entry": "./dist/entry.js",
6
+ "hostVersion": ">=0.84.4",
7
+ "requiredCapabilities": [
8
+ "session",
9
+ "events",
10
+ "tools"
11
+ ]
12
+ }