dsh-charter 0.3.2 → 0.3.3

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 (47) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/CHANGELOG.zh.md +18 -1
  3. package/README.md +46 -26
  4. package/README.zh.md +37 -21
  5. package/docs/README.md +2 -0
  6. package/docs/README.zh.md +2 -0
  7. package/docs/assets/charter-graph-0.3.3.png +0 -0
  8. package/docs/assets/charter-graph-0.3.3.zh.png +0 -0
  9. package/docs/assets/charter-pane-0.3.3.png +0 -0
  10. package/docs/assets/charter-pane-0.3.3.zh.png +0 -0
  11. package/docs/design/charter-draft-calibration-v1.zh.md +617 -0
  12. package/docs/design/charter-draft-extraction-v1.zh.md +346 -0
  13. package/docs/design/charter-gui-v1.zh.md +2 -2
  14. package/docs/design/compatibility.md +11 -5
  15. package/docs/design/compatibility.zh.md +10 -5
  16. package/docs/design/version-roadmap.md +9 -11
  17. package/docs/design/version-roadmap.zh.md +6 -4
  18. package/docs/release-notes/0.3.2.md +6 -5
  19. package/docs/release-notes/0.3.3.md +32 -0
  20. package/docs/release-notes/README.md +1 -1
  21. package/docs/releasing.md +6 -5
  22. package/docs/releasing.zh.md +6 -5
  23. package/docs/user-guide.md +16 -2
  24. package/docs/user-guide.zh.md +15 -2
  25. package/docs/verification.md +31 -23
  26. package/docs/verification.zh.md +32 -23
  27. package/lib/client/bootstrap-plan.d.ts +9 -1
  28. package/lib/client/draft-store.d.ts +12 -1
  29. package/lib/client/locales.d.ts +11 -0
  30. package/lib/client/pane-scope.d.ts +2 -0
  31. package/lib/client/store.d.ts +12 -1
  32. package/lib/client.js +328 -41
  33. package/lib/core/bootstrap.d.ts +14 -0
  34. package/lib/core/schemas.d.ts +3 -0
  35. package/lib/core/structured-bootstrap.d.ts +49 -0
  36. package/lib/core.js +2 -2
  37. package/lib/{fork-KSL6sovw.js → fork-h8Gx4AJd.js} +178 -166
  38. package/lib/host/draft-translation.d.ts +47 -0
  39. package/lib/host/service.d.ts +19 -1
  40. package/lib/host/types.d.ts +43 -0
  41. package/lib/index.js +3 -3
  42. package/lib/remote/service.d.ts +6 -1
  43. package/lib/remote/wire.d.ts +91 -2
  44. package/lib/remote.js +116 -4
  45. package/lib/{service-BSrE7Kbu.js → service-CPha5Ipx.js} +734 -42
  46. package/lib/version.d.ts +1 -1
  47. package/package.json +19 -18
package/lib/client.js CHANGED
@@ -5830,7 +5830,8 @@ const newItemInputSchema = discriminatedUnion("kind", [object({
5830
5830
  const charterOpSchema = discriminatedUnion("type", [
5831
5831
  object({
5832
5832
  type: literal("objective.initialize"),
5833
- text: string()
5833
+ text: string(),
5834
+ clientRef: clientRefSchema.optional()
5834
5835
  }).strict(),
5835
5836
  object({
5836
5837
  type: literal("objective.redirect"),
@@ -6526,7 +6527,7 @@ const charterItemQueryResultSchema = union([object({
6526
6527
  filterDigest: string()
6527
6528
  }).strict(), itemQueryFailureSchema]);
6528
6529
  const charterProposalQueryRequestSchema = object({
6529
- limit: number().int().positive().max(64).optional(),
6530
+ limit: number().int().positive().max(512).optional(),
6530
6531
  cursor: string().optional(),
6531
6532
  sourceKind: _enum([
6532
6533
  "manual",
@@ -6820,6 +6821,80 @@ const charterBootstrapResultSchema = discriminatedUnion("available", [object({
6820
6821
  ]),
6821
6822
  message: string().optional()
6822
6823
  }).strict()]);
6824
+ const charterBootstrapDraftRequestSchema = object({
6825
+ sessionId: string().min(1).max(256),
6826
+ targetLanguage: _enum(["zh", "en"]).optional(),
6827
+ awaitTranslation: boolean().optional()
6828
+ }).strict();
6829
+ const charterBootstrapDraftMemberSchema = object({
6830
+ ref: clientRefSchema,
6831
+ text: string()
6832
+ }).strict();
6833
+ const charterBootstrapDraftItemSchema = object({
6834
+ ref: clientRefSchema,
6835
+ kind: _enum([
6836
+ "objective",
6837
+ "invariant",
6838
+ "deliverable"
6839
+ ]),
6840
+ text: string(),
6841
+ lang: _enum([
6842
+ "zh",
6843
+ "en",
6844
+ "mixed"
6845
+ ]),
6846
+ oversized: boolean(),
6847
+ truncatedFrom: number().int().positive().optional(),
6848
+ kindConfidence: _enum(["high", "low"]).optional(),
6849
+ foldCount: number().int().min(2).optional(),
6850
+ foldMembers: array(charterBootstrapDraftMemberSchema).max(512).optional()
6851
+ }).strict();
6852
+ const charterBootstrapLanguageSchema = object({
6853
+ requested: _enum(["zh", "en"]).nullable(),
6854
+ status: _enum([
6855
+ "source",
6856
+ "translated",
6857
+ "partial",
6858
+ "pending",
6859
+ "unavailable",
6860
+ "failed",
6861
+ "disabled"
6862
+ ]),
6863
+ reason: string().max(512).optional(),
6864
+ provider: string().max(256).optional(),
6865
+ model: string().max(256).optional()
6866
+ }).strict();
6867
+ const charterBootstrapDraftProposalSchema = object({
6868
+ draftHandle: string().optional(),
6869
+ objective: string().nullable(),
6870
+ invariants: array(string()),
6871
+ deliverables: array(string()),
6872
+ source: object({
6873
+ summarySeq: number().int().nonnegative(),
6874
+ at: number().int().nonnegative(),
6875
+ shadowedTokens: number().int().nonnegative().optional()
6876
+ }).strict(),
6877
+ items: array(charterBootstrapDraftItemSchema),
6878
+ draftLang: _enum([
6879
+ "zh",
6880
+ "en",
6881
+ "mixed"
6882
+ ]),
6883
+ language: charterBootstrapLanguageSchema,
6884
+ extractorVersion: literal(2)
6885
+ }).strict();
6886
+ const charterBootstrapDraftResultSchema = discriminatedUnion("available", [object({
6887
+ available: literal(true),
6888
+ proposal: charterBootstrapDraftProposalSchema
6889
+ }).strict(), object({
6890
+ available: literal(false),
6891
+ reason: _enum([
6892
+ "not-live",
6893
+ "no-summary",
6894
+ "unavailable"
6895
+ ]),
6896
+ message: string().optional()
6897
+ }).strict()]);
6823
6898
  const charterFrameSchema = discriminatedUnion("type", [object({
6824
6899
  type: literal("snapshot"),
6825
6900
  value: charterViewSchema
@@ -6915,6 +6990,28 @@ const charterRemoteContribution = {
6915
6990
  create: () => charterBootstrapResultSchema
6916
6991
  }
6917
6992
  },
6993
+ {
6994
+ id: "dsh-charter#charter/bootstrapDraft",
6995
+ service: "charterRemote",
6996
+ namespace: "charter",
6997
+ method: "bootstrapDraft",
6998
+ invocation: { kind: "direct" },
6999
+ parameters: [{
7000
+ name: "request",
7001
+ wire: "request",
7002
+ source: "json",
7003
+ codec: {
7004
+ mode: "strict",
7005
+ typeSymbol: "dsh-charter/CharterBootstrapDraftRequest",
7006
+ create: () => charterBootstrapDraftRequestSchema
7007
+ }
7008
+ }],
7009
+ result: {
7010
+ mode: "strict",
7011
+ typeSymbol: "dsh-charter/CharterBootstrapDraftResult",
7012
+ create: () => charterBootstrapDraftResultSchema
7013
+ }
7014
+ },
6918
7015
  {
6919
7016
  id: "dsh-charter#charter/edit",
6920
7017
  service: "charterRemote",
@@ -7934,11 +8031,13 @@ function deliverablePromptToken(text, progress) {
7934
8031
  * final verification: if it ever disagrees, the quadratic fallback recomputes
7935
8032
  * the plan, so correctness never depends on the estimate.
7936
8033
  */
7937
- function buildBootstrapPlan(view, objective, items) {
8034
+ function buildBootstrapPlan(view, objective, items, structuredDraft = false) {
7938
8035
  const normalizedObjective = inspectUserText(objective).value;
8036
+ const structured = structuredDraft || items.some((item) => item.clientRef?.startsWith("d-") === true);
7939
8037
  const objectiveOp = view.objective === null && normalizedObjective.length > 0 ? {
7940
8038
  type: "objective.initialize",
7941
- text: normalizedObjective
8039
+ text: normalizedObjective,
8040
+ ...structured ? { clientRef: "d-obj-0" } : {}
7942
8041
  } : null;
7943
8042
  const baseOps = objectiveOp === null ? [] : [objectiveOp];
7944
8043
  const base = projectView(view, baseOps);
@@ -7981,7 +8080,7 @@ function buildBootstrapPlan(view, objective, items) {
7981
8080
  const activeOp = isInvariant ? {
7982
8081
  type: "item.add",
7983
8082
  item: {
7984
- clientRef: `bootstrap-${item.id}`,
8083
+ clientRef: item.clientRef ?? `bootstrap-${item.id}`,
7985
8084
  kind: "invariant",
7986
8085
  text,
7987
8086
  order
@@ -7989,7 +8088,7 @@ function buildBootstrapPlan(view, objective, items) {
7989
8088
  } : {
7990
8089
  type: "item.add",
7991
8090
  item: {
7992
- clientRef: `bootstrap-${item.id}`,
8091
+ clientRef: item.clientRef ?? `bootstrap-${item.id}`,
7993
8092
  kind: "deliverable",
7994
8093
  text,
7995
8094
  order,
@@ -8044,7 +8143,7 @@ function exactBootstrapPlan(view, items, objectiveOp, priorRenders) {
8044
8143
  const activeOp = item.kind === "invariant" ? {
8045
8144
  type: "item.add",
8046
8145
  item: {
8047
- clientRef: `bootstrap-${item.id}`,
8146
+ clientRef: item.clientRef ?? `bootstrap-${item.id}`,
8048
8147
  kind: "invariant",
8049
8148
  text,
8050
8149
  order
@@ -8052,7 +8151,7 @@ function exactBootstrapPlan(view, items, objectiveOp, priorRenders) {
8052
8151
  } : {
8053
8152
  type: "item.add",
8054
8153
  item: {
8055
- clientRef: `bootstrap-${item.id}`,
8154
+ clientRef: item.clientRef ?? `bootstrap-${item.id}`,
8056
8155
  kind: "deliverable",
8057
8156
  text,
8058
8157
  order,
@@ -9096,7 +9195,7 @@ var CharterDraft = class {
9096
9195
  return this.state.bootstrapItems.slice(0, this.state.bootstrapVisibleCount);
9097
9196
  }
9098
9197
  bootstrapPlan(view) {
9099
- return buildBootstrapPlan(view, this.state.bootstrapObjective, this.visibleBootstrapItems());
9198
+ return buildBootstrapPlan(view, this.state.bootstrapObjective, this.visibleBootstrapItems(), this.state.bootstrap?.extractorVersion === 2);
9100
9199
  }
9101
9200
  /** Ask for a draft when the Session is empty and no attempt has been made yet. */
9102
9201
  ensureBootstrap(view, connectionReady) {
@@ -9161,26 +9260,8 @@ var CharterDraft = class {
9161
9260
  return;
9162
9261
  }
9163
9262
  const proposal = outcome.proposal;
9164
- this.update({
9165
- bootstrapPhase: "draft",
9166
- bootstrap: proposal,
9167
- bootstrapBaseRevision: requestedRevision,
9168
- bootstrapObjective: proposal.objective ?? "",
9169
- bootstrapItems: [...proposal.invariants.map((text, index) => ({
9170
- id: `inv-${index}`,
9171
- kind: "invariant",
9172
- text,
9173
- selected: false
9174
- })), ...proposal.deliverables.map((text, index) => ({
9175
- id: `del-${index}`,
9176
- kind: "deliverable",
9177
- text,
9178
- selected: false
9179
- }))],
9180
- bootstrapVisibleCount: 40,
9181
- bootstrapProblem: null,
9182
- ...this.userBusy ? {} : { section: "history" }
9183
- });
9263
+ this.acceptBootstrapProposal(proposal, requestedRevision);
9264
+ if (proposal.language?.status === "pending") this.localizeBootstrapProposal(source, proposal, requestedRevision, current);
9184
9265
  } catch (error) {
9185
9266
  if (!current()) return;
9186
9267
  console.error("charter: bootstrap request failed", error);
@@ -9190,6 +9271,78 @@ var CharterDraft = class {
9190
9271
  });
9191
9272
  }
9192
9273
  }
9274
+ /** Materialize the review draft; shared by the initial and localized responses. */
9275
+ acceptBootstrapProposal(proposal, requestedRevision) {
9276
+ const structuredItems = proposal.draftItems;
9277
+ this.update({
9278
+ bootstrapPhase: "draft",
9279
+ bootstrap: proposal,
9280
+ bootstrapBaseRevision: requestedRevision,
9281
+ bootstrapObjective: proposal.objective ?? "",
9282
+ bootstrapItems: structuredItems === void 0 ? [...proposal.invariants.map((text, index) => ({
9283
+ id: `inv-${index}`,
9284
+ kind: "invariant",
9285
+ text,
9286
+ selected: false
9287
+ })), ...proposal.deliverables.map((text, index) => ({
9288
+ id: `del-${index}`,
9289
+ kind: "deliverable",
9290
+ text,
9291
+ selected: false
9292
+ }))] : structuredItems.filter((item) => item.kind !== "objective").map((item) => ({
9293
+ id: item.ref,
9294
+ clientRef: item.ref,
9295
+ kind: item.kind,
9296
+ text: item.text,
9297
+ selected: false,
9298
+ lang: item.lang,
9299
+ oversized: item.oversized,
9300
+ originalText: item.text,
9301
+ ...item.truncatedFrom === void 0 ? {} : { truncatedFrom: item.truncatedFrom },
9302
+ ...item.foldCount === void 0 ? {} : { foldCount: item.foldCount }
9303
+ })),
9304
+ bootstrapVisibleCount: 40,
9305
+ bootstrapProblem: null,
9306
+ ...proposal.language === void 0 ? {} : { bootstrapLanguage: proposal.language },
9307
+ ...proposal.draftLang === void 0 ? {} : { bootstrapDraftLang: proposal.draftLang },
9308
+ ...this.userBusy ? {} : { section: "history" }
9309
+ });
9310
+ }
9311
+ /**
9312
+ * The first extraction returns source text immediately. Resolve the
9313
+ * deferred model translation in the background and replace the draft only
9314
+ * while it is still pristine, so a fast reviewer never gets an edited draft
9315
+ * overwritten under their hands.
9316
+ */
9317
+ async localizeBootstrapProposal(source, initialProposal, requestedRevision, current) {
9318
+ const localized = await source.localizeBootstrap();
9319
+ if (!current()) return;
9320
+ if (this.state.bootstrapPhase !== "draft" || this.state.bootstrap !== initialProposal) return;
9321
+ if (this.state.bootstrapSaving || this.state.bootstrapNeedsStale || this.state.ops.length > 0) return;
9322
+ if (!(this.state.bootstrapObjective === (initialProposal.objective ?? "") && !this.state.bootstrapItems.some((item) => item.selected))) {
9323
+ this.update({ bootstrapLanguage: {
9324
+ ...initialProposal.language ?? {
9325
+ requested: null,
9326
+ status: "source"
9327
+ },
9328
+ status: "failed",
9329
+ reason: "The draft was edited while translation was running; source text was kept."
9330
+ } });
9331
+ return;
9332
+ }
9333
+ if (localized === void 0 || !localized.available) {
9334
+ this.update({ bootstrapLanguage: {
9335
+ ...initialProposal.language ?? {
9336
+ requested: null,
9337
+ status: "source"
9338
+ },
9339
+ status: "failed",
9340
+ reason: "Language normalization request failed; source text was kept."
9341
+ } });
9342
+ return;
9343
+ }
9344
+ this.acceptBootstrapProposal(localized.proposal, requestedRevision);
9345
+ }
9193
9346
  /** Explicit dismissal: one full cleanup of the draft and any replay evidence. */
9194
9347
  dismissBootstrap() {
9195
9348
  if (unknownAttempt(this.state)?.kind === "bootstrap") return;
@@ -9201,6 +9354,8 @@ var CharterDraft = class {
9201
9354
  bootstrapItems: [],
9202
9355
  bootstrapVisibleCount: 40,
9203
9356
  bootstrapProblem: null,
9357
+ bootstrapLanguage: void 0,
9358
+ bootstrapDraftLang: void 0,
9204
9359
  bootstrapNeedsStale: false,
9205
9360
  bootstrapBaseRevision: null,
9206
9361
  bootstrapSaving: false,
@@ -9647,6 +9802,9 @@ var CharterSessionSource = class {
9647
9802
  /** Attach that has been requested but does not own the stream yet (an earlier dispose is pending). */
9648
9803
  pendingRemote;
9649
9804
  attachGeneration = 0;
9805
+ /** A Host without bootstrapDraft (or one that failed method-level) stays on the legacy path for this source. */
9806
+ structuredBootstrapUnavailable = false;
9807
+ draftTargetLanguage;
9650
9808
  connection = 0;
9651
9809
  connectionListeners = /* @__PURE__ */ new Set();
9652
9810
  watchdog;
@@ -9683,10 +9841,68 @@ var CharterSessionSource = class {
9683
9841
  available: false,
9684
9842
  reason: "unavailable"
9685
9843
  };
9844
+ const base = (() => {
9845
+ try {
9846
+ return this.ctx.locale.getLocale?.().active;
9847
+ } catch {
9848
+ return;
9849
+ }
9850
+ })()?.toLowerCase().split(/[-_]/u)[0];
9851
+ const targetLanguage = base === "zh" || base === "en" ? base : void 0;
9852
+ this.draftTargetLanguage = targetLanguage;
9853
+ const draft = remote.bootstrapDraft;
9854
+ if (!this.structuredBootstrapUnavailable && typeof draft === "function") {
9855
+ let response;
9856
+ try {
9857
+ response = await draft({
9858
+ sessionId: this.sessionId,
9859
+ ...targetLanguage === void 0 ? {} : { targetLanguage },
9860
+ awaitTranslation: false
9861
+ });
9862
+ } catch {
9863
+ this.structuredBootstrapUnavailable = true;
9864
+ response = {
9865
+ ok: false,
9866
+ error: void 0
9867
+ };
9868
+ }
9869
+ if (response.ok) {
9870
+ if (!response.value.available) return response.value;
9871
+ return {
9872
+ available: true,
9873
+ proposal: response.value.proposal
9874
+ };
9875
+ }
9876
+ if (response.error !== void 0) throw response.error;
9877
+ this.structuredBootstrapUnavailable = true;
9878
+ }
9686
9879
  const result = await remote.bootstrap(this.sessionId);
9687
9880
  if (!result.ok) throw result.error;
9688
9881
  return result.value;
9689
9882
  };
9883
+ /**
9884
+ * Resolve the deferred language normalization for the current draft.
9885
+ *
9886
+ * The initial `bootstrap` returns the source draft immediately; the Pane
9887
+ * calls this in the background and replaces the draft only while it is still
9888
+ * pristine. Old Hosts without this method return undefined.
9889
+ */
9890
+ localizeBootstrap = async () => {
9891
+ const remote = this.remote;
9892
+ if (remote === void 0) return void 0;
9893
+ const draft = remote.bootstrapDraft;
9894
+ if (typeof draft !== "function" || this.structuredBootstrapUnavailable) return void 0;
9895
+ try {
9896
+ const response = await draft({
9897
+ sessionId: this.sessionId,
9898
+ ...this.draftTargetLanguage === void 0 ? {} : { targetLanguage: this.draftTargetLanguage },
9899
+ awaitTranslation: true
9900
+ });
9901
+ return response.ok ? response.value : void 0;
9902
+ } catch {
9903
+ return;
9904
+ }
9905
+ };
9690
9906
  edit = async (request) => {
9691
9907
  const remote = this.remote;
9692
9908
  if (remote === void 0) return {
@@ -10440,6 +10656,17 @@ const CHARTER_LOCALE = {
10440
10656
  "bootstrap.notLive": "该会话当前不在这个 Host 进程中运行。在此打开它后才能读取压缩历史。",
10441
10657
  "bootstrap.noSummary": "该会话还没有可用的压缩摘要;完成一次压缩后才会出现草案。",
10442
10658
  "bootstrap.unavailable": "契约存储不可用,暂时无法读取历史草案。",
10659
+ "bootstrap.languageTranslated": "草案已按 {language} 生成。",
10660
+ "bootstrap.languagePending": "后台正在转换为 {language},当前先显示原文草案…",
10661
+ "bootstrap.languagePartial": "部分候选无法转换为 {language},这些条目保留原文。",
10662
+ "bootstrap.languageFallback": "无法把草案转换为 {language},当前显示原文语言。",
10663
+ "bootstrap.languageTag": "{language} 草案",
10664
+ "bootstrap.oversizedHint": "该候选超过条目上限,请先编辑或拆分后再应用。",
10665
+ "bootstrap.truncatedHint": "已从 {bytes} 字节截断;完整原文仍在压缩历史中。",
10666
+ "bootstrap.foldedHint": "已把 {count} 条相似候选折叠到本行。",
10667
+ "locale.zh": "中文",
10668
+ "locale.en": "英文",
10669
+ "locale.mixed": "混合语言",
10443
10670
  "notice.conflict": "契约已从修订 {from} 更新到 {to}。草稿已保留;可将草稿应用到最新修订,或丢弃后查看新版本。",
10444
10671
  "objective.kicker": "目标",
10445
10672
  "objective.originalLabel": "初始目标",
@@ -11011,6 +11238,17 @@ const CHARTER_LOCALE = {
11011
11238
  "bootstrap.notLive": "This Session is not live in this Host process. Open it here to read its compaction history.",
11012
11239
  "bootstrap.noSummary": "No usable compaction summary exists for this Session yet. A draft appears after a compaction.",
11013
11240
  "bootstrap.unavailable": "Charter storage is unavailable, so the history draft cannot be read.",
11241
+ "bootstrap.languageTranslated": "Draft normalized to {language}.",
11242
+ "bootstrap.languagePending": "Showing the source draft while {language} normalization runs in the background…",
11243
+ "bootstrap.languagePartial": "Some candidates could not be normalized to {language}; those kept their source text.",
11244
+ "bootstrap.languageFallback": "Could not normalize the draft to {language}; showing the source language.",
11245
+ "bootstrap.languageTag": "{language} draft",
11246
+ "bootstrap.oversizedHint": "This candidate exceeds the item limit. Edit or split it before applying.",
11247
+ "bootstrap.truncatedHint": "Truncated from {bytes} bytes; the complete source remains in compaction history.",
11248
+ "bootstrap.foldedHint": "{count} similar candidates folded into this row.",
11249
+ "locale.zh": "Chinese",
11250
+ "locale.en": "English",
11251
+ "locale.mixed": "Mixed language",
11014
11252
  "notice.conflict": "The charter advanced from revision {from} to {to}. Your draft is preserved. Apply it to the latest revision, or discard it and review the new version.",
11015
11253
  "objective.kicker": "Objective",
11016
11254
  "objective.originalLabel": "Initial objective",
@@ -11360,7 +11598,7 @@ const CHARTER_LOCALE = {
11360
11598
  * bundle carries the value; `tests/version.spec.ts` fails if it drifts from
11361
11599
  * `package.json`.
11362
11600
  */
11363
- const CHARTER_VERSION = "0.3.2";
11601
+ const CHARTER_VERSION = "0.3.3";
11364
11602
  //#endregion
11365
11603
  //#region .build-ts/core/dependencies.js
11366
11604
  function standingDeliverables(items) {
@@ -14070,7 +14308,7 @@ function WorkspacePage({ scope }) {
14070
14308
  //#endregion
14071
14309
  //#region .build-ts/client/ReviewCenterPage.js
14072
14310
  function ReviewCenterPage({ scope }) {
14073
- const { abandonUnknown, applyBootstrapDraft, applyHintId, area, batchByItem, bootstrap, bootstrapBudgetOver, bootstrapId, bootstrapItems, bootstrapObjective, bootstrapObjectiveOver, bootstrapPhase, bootstrapPlan, bootstrapProblem, bootstrapPromptBytes, bootstrapReplay, bootstrapSaving, bootstrapStorageOver, bootstrapTextIssue, bootstrapVisibleCount, canApplyBootstrap, closedObjectiveProposals, confirmAbandon, draft, editor, inactiveItems, messageBytes, messageCanSave, messageCandidates, messageDraft, messageKind, messageMenuOpen, messageMenuRef, messageOverBudget, messageSeq, messageTextAvailable, ops, pendingItemProposals, pendingObjectiveProposals, proposalReasons, reviewLimit, saving, selectedMessage, setMessageDraft, setMessageKind, setMessageMenuOpen, setMessageSeq, setProposalReasons, setReviewLimit, source, t, unknownBlocked, unknownReplay, view } = scope;
14311
+ const { abandonUnknown, applyBootstrapDraft, applyHintId, area, batchByItem, bootstrap, bootstrapBudgetOver, bootstrapId, bootstrapItems, bootstrapObjective, bootstrapObjectiveOver, bootstrapPhase, bootstrapPlan, bootstrapProblem, bootstrapLanguage, bootstrapDraftLang, bootstrapPromptBytes, bootstrapReplay, bootstrapSaving, bootstrapStorageOver, bootstrapTextIssue, bootstrapVisibleCount, canApplyBootstrap, closedObjectiveProposals, confirmAbandon, draft, editor, inactiveItems, messageBytes, messageCanSave, messageCandidates, messageDraft, messageKind, messageMenuOpen, messageMenuRef, messageOverBudget, messageSeq, messageTextAvailable, ops, pendingItemProposals, pendingObjectiveProposals, proposalReasons, reviewLimit, saving, selectedMessage, setMessageDraft, setMessageKind, setMessageMenuOpen, setMessageSeq, setProposalReasons, setReviewLimit, source, t, unknownBlocked, unknownReplay, view } = scope;
14074
14312
  return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
14075
14313
  area === "review" && source.proposeMessage !== void 0 && (0, react_jsx_runtime.jsxs)("section", {
14076
14314
  className: "charter-card charter-section charter-messageproposal",
@@ -14583,6 +14821,36 @@ function ReviewCenterPage({ scope }) {
14583
14821
  className: "charter-source",
14584
14822
  children: bootstrap.source.shadowedTokens === void 0 ? t("bootstrap.sourcePlain") : t("bootstrap.source", { tokens: bootstrap.source.shadowedTokens })
14585
14823
  }),
14824
+ bootstrapLanguage?.status === "translated" && (0, react_jsx_runtime.jsx)("span", {
14825
+ className: "charter-hint",
14826
+ role: "status",
14827
+ children: t("bootstrap.languageTranslated", { language: bootstrapLanguage.requested === "zh" ? t("locale.zh") : t("locale.en") })
14828
+ }),
14829
+ bootstrapLanguage?.status === "pending" && (0, react_jsx_runtime.jsx)("span", {
14830
+ className: "charter-hint",
14831
+ role: "status",
14832
+ children: t("bootstrap.languagePending", { language: bootstrapLanguage.requested === "zh" ? t("locale.zh") : t("locale.en") })
14833
+ }),
14834
+ bootstrapLanguage?.status === "partial" && (0, react_jsx_runtime.jsxs)("div", {
14835
+ className: "charter-notice charter-notice--warning",
14836
+ role: "status",
14837
+ children: [t("bootstrap.languagePartial", { language: bootstrapLanguage.requested === "zh" ? t("locale.zh") : t("locale.en") }), (0, react_jsx_runtime.jsx)(ErrorDetails, {
14838
+ detail: bootstrapLanguage.reason,
14839
+ t
14840
+ })]
14841
+ }),
14842
+ (bootstrapLanguage?.status === "unavailable" || bootstrapLanguage?.status === "failed" || bootstrapLanguage?.status === "disabled") && (0, react_jsx_runtime.jsxs)("div", {
14843
+ className: "charter-notice charter-notice--warning",
14844
+ role: "status",
14845
+ children: [t("bootstrap.languageFallback", { language: bootstrapLanguage.requested === "zh" ? t("locale.zh") : t("locale.en") }), (0, react_jsx_runtime.jsx)(ErrorDetails, {
14846
+ detail: bootstrapLanguage.reason,
14847
+ t
14848
+ })]
14849
+ }),
14850
+ bootstrapDraftLang !== void 0 && bootstrapLanguage?.status !== "translated" && (0, react_jsx_runtime.jsx)("span", {
14851
+ className: "charter-hint",
14852
+ children: t("bootstrap.languageTag", { language: bootstrapDraftLang === "zh" ? t("locale.zh") : bootstrapDraftLang === "en" ? t("locale.en") : t("locale.mixed") })
14853
+ }),
14586
14854
  (0, react_jsx_runtime.jsxs)("div", {
14587
14855
  className: "charter-bootstrap__summary",
14588
14856
  children: [
@@ -14664,6 +14932,7 @@ function ReviewCenterPage({ scope }) {
14664
14932
  const outcome = bootstrapPlan.outcomes[item.id];
14665
14933
  const checkboxId = `${bootstrapId}-include-${item.id}`;
14666
14934
  const textId = `${bootstrapId}-text-${item.id}`;
14935
+ const oversizedUnedited = item.oversized === true && item.text === item.originalText;
14667
14936
  return (0, react_jsx_runtime.jsxs)("div", {
14668
14937
  className: "charter-bootstrap__item",
14669
14938
  children: [
@@ -14671,8 +14940,9 @@ function ReviewCenterPage({ scope }) {
14671
14940
  id: checkboxId,
14672
14941
  type: "checkbox",
14673
14942
  checked: item.selected,
14674
- disabled: bootstrapSaving || unknownBlocked,
14943
+ disabled: bootstrapSaving || unknownBlocked || oversizedUnedited,
14675
14944
  "aria-label": t("bootstrap.includeAria", { index: index + 1 }),
14945
+ "aria-describedby": `${textId}-meta`,
14676
14946
  onChange: (event) => draft.updateBootstrapItem(item.id, { selected: event.target.checked })
14677
14947
  }),
14678
14948
  (0, react_jsx_runtime.jsx)("label", {
@@ -14700,13 +14970,28 @@ function ReviewCenterPage({ scope }) {
14700
14970
  (0, react_jsx_runtime.jsxs)("span", {
14701
14971
  className: "charter-draftfield__meta",
14702
14972
  id: `${textId}-meta`,
14703
- children: [outcome !== void 0 && (0, react_jsx_runtime.jsx)(StatusTag, {
14704
- tone: outcome === "active" ? "success" : "warning",
14705
- children: outcome === "active" ? t("bootstrap.outcomeActive") : t("bootstrap.outcomePending")
14706
- }), (0, react_jsx_runtime.jsx)("span", {
14707
- className: `charter-budget${bytes > view.limits.maxItemBytes ? " is-over" : ""}`,
14708
- children: bytes > view.limits.maxItemBytes ? t("bootstrap.itemOver", { limit: formatBytes(t, view.limits.maxItemBytes) }) : `${formatBytes(t, bytes)} / ${formatBytes(t, view.limits.maxItemBytes)}`
14709
- })]
14973
+ children: [
14974
+ outcome !== void 0 && (0, react_jsx_runtime.jsx)(StatusTag, {
14975
+ tone: outcome === "active" ? "success" : "warning",
14976
+ children: outcome === "active" ? t("bootstrap.outcomeActive") : t("bootstrap.outcomePending")
14977
+ }),
14978
+ (0, react_jsx_runtime.jsx)("span", {
14979
+ className: `charter-budget${bytes > view.limits.maxItemBytes ? " is-over" : ""}`,
14980
+ children: bytes > view.limits.maxItemBytes ? t("bootstrap.itemOver", { limit: formatBytes(t, view.limits.maxItemBytes) }) : `${formatBytes(t, bytes)} / ${formatBytes(t, view.limits.maxItemBytes)}`
14981
+ }),
14982
+ item.foldCount !== void 0 && item.foldCount > 1 && (0, react_jsx_runtime.jsx)("span", {
14983
+ className: "charter-hint",
14984
+ children: t("bootstrap.foldedHint", { count: item.foldCount })
14985
+ }),
14986
+ item.truncatedFrom !== void 0 && (0, react_jsx_runtime.jsx)("span", {
14987
+ className: "charter-hint",
14988
+ children: t("bootstrap.truncatedHint", { bytes: String(item.truncatedFrom) })
14989
+ }),
14990
+ oversizedUnedited && (0, react_jsx_runtime.jsx)("span", {
14991
+ className: "charter-hint",
14992
+ children: t("bootstrap.oversizedHint")
14993
+ })
14994
+ ]
14710
14995
  })
14711
14996
  ]
14712
14997
  })
@@ -15727,7 +16012,7 @@ function CharterPane({ source, draft, release, t }) {
15727
16012
  const state = (0, react.useSyncExternalStore)(source.subscribe, source.getSnapshot, source.getSnapshot);
15728
16013
  const view = state.view;
15729
16014
  const draftState = (0, react.useSyncExternalStore)(draft.subscribe, draft.getSnapshot, draft.getSnapshot);
15730
- const { section, ops, baseRevision, editor, editorText, editorReason, editorNeedsReason, newInvariant, newDeliverable, feedback, saving, bootstrapSaving, bootstrapPhase, bootstrap, bootstrapObjective, bootstrapItems, bootstrapVisibleCount, bootstrapProblem, bootstrapBaseRevision } = draftState;
16015
+ const { section, ops, baseRevision, editor, editorText, editorReason, editorNeedsReason, newInvariant, newDeliverable, feedback, saving, bootstrapSaving, bootstrapPhase, bootstrap, bootstrapObjective, bootstrapItems, bootstrapVisibleCount, bootstrapProblem, bootstrapLanguage, bootstrapDraftLang, bootstrapBaseRevision } = draftState;
15731
16016
  const [showHistoryItems, setShowHistoryItems] = (0, react.useState)(false);
15732
16017
  const [visibleCounts, setVisibleCounts] = (0, react.useState)({
15733
16018
  invariants: 50,
@@ -15961,7 +16246,7 @@ function CharterPane({ source, draft, release, t }) {
15961
16246
  };
15962
16247
  const bootstrapStale = bootstrapPhase === "draft" && (bootstrapBaseRevision === null || view === null || view.revision !== bootstrapBaseRevision || view.objective !== null || view.items.length > 0);
15963
16248
  const unknownBlocked = draftState.attempt?.status === "unknown";
15964
- const canApplyBootstrap = bootstrap !== null && bootstrapPhase === "draft" && state.status === "ready" && ops.length === 0 && editor === null && !bootstrapSaving && !unknownBlocked && bootstrapPlan.ops.length > 0 && !bootstrapObjectiveOver && !bootstrapItemsOver && !bootstrapBudgetOver && !bootstrapStorageOver && !bootstrapStale && bootstrapTextIssue === void 0;
16249
+ const canApplyBootstrap = bootstrap !== null && bootstrapPhase === "draft" && state.status === "ready" && ops.length === 0 && editor === null && !bootstrapSaving && !unknownBlocked && bootstrapPlan.ops.length > 0 && !bootstrapObjectiveOver && !bootstrapItemsOver && !bootstrapItems.some((item) => item.selected && item.oversized === true && item.text === item.originalText) && !bootstrapBudgetOver && !bootstrapStorageOver && !bootstrapStale && bootstrapTextIssue === void 0;
15965
16250
  const editReplay = editReplayPending(draftState);
15966
16251
  const bootstrapReplay = bootstrapReplayPending(draftState);
15967
16252
  const oldLifecycleUnknown = crossLifecycleUnknown(draftState);
@@ -16615,6 +16900,8 @@ function CharterPane({ source, draft, release, t }) {
16615
16900
  area,
16616
16901
  bootstrapPhase,
16617
16902
  bootstrapProblem,
16903
+ bootstrapLanguage,
16904
+ bootstrapDraftLang,
16618
16905
  counts,
16619
16906
  currentDeliverables,
16620
16907
  currentInvariants,
@@ -21,6 +21,15 @@ export interface BootstrapExtraction {
21
21
  readonly draft: BootstrapDraft;
22
22
  readonly source: BootstrapSource;
23
23
  }
24
+ export interface Section {
25
+ readonly title: string;
26
+ readonly lines: readonly string[];
27
+ }
28
+ export declare function splitSections(text: string): Section[];
29
+ export declare function sectionKind(title: string): 'primary' | 'critical' | 'pending' | 'other';
30
+ export declare function cleanLine(raw: string): string | null;
31
+ export declare function bulletLines(lines: readonly string[]): string[];
32
+ export declare function paragraphLines(lines: readonly string[]): string[];
24
33
  /**
25
34
  * Deterministically extract a draft charter from a compaction summary.
26
35
  *
@@ -28,6 +37,11 @@ export interface BootstrapExtraction {
28
37
  * user to review; it never enters the effective record on its own.
29
38
  */
30
39
  export declare function bootstrapFromSummary(summary: string, limits: Pick<CharterLimits, 'maxObjectiveBytes' | 'maxItemBytes'>): BootstrapDraft;
40
+ /** Parse one compaction summary event into reviewable text plus its bounded source. */
41
+ export declare function compactionSummaryEvent(event: CompactionSummaryEvent): {
42
+ readonly text: string;
43
+ readonly source: BootstrapSource;
44
+ } | undefined;
31
45
  /**
32
46
  * Find the latest non-empty compaction summary and extract a draft from it.
33
47
  * Returns undefined when the log has no usable summary.
@@ -755,6 +755,7 @@ export declare const newItemInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
755
755
  export declare const charterOpSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
756
756
  type: z.ZodLiteral<"objective.initialize">;
757
757
  text: z.ZodString;
758
+ clientRef: z.ZodOptional<z.ZodString>;
758
759
  }, z.core.$strict>, z.ZodObject<{
759
760
  type: z.ZodLiteral<"objective.redirect">;
760
761
  text: z.ZodString;
@@ -978,6 +979,7 @@ export declare const charterEditRequestSchema: z.ZodObject<{
978
979
  ops: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
979
980
  type: z.ZodLiteral<"objective.initialize">;
980
981
  text: z.ZodString;
982
+ clientRef: z.ZodOptional<z.ZodString>;
981
983
  }, z.core.$strict>, z.ZodObject<{
982
984
  type: z.ZodLiteral<"objective.redirect">;
983
985
  text: z.ZodString;
@@ -1203,6 +1205,7 @@ export declare const charterBootstrapApplyRequestSchema: z.ZodObject<{
1203
1205
  ops: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1204
1206
  type: z.ZodLiteral<"objective.initialize">;
1205
1207
  text: z.ZodString;
1208
+ clientRef: z.ZodOptional<z.ZodString>;
1206
1209
  }, z.core.$strict>, z.ZodObject<{
1207
1210
  type: z.ZodLiteral<"objective.redirect">;
1208
1211
  text: z.ZodString;
@@ -0,0 +1,49 @@
1
+ import { type BootstrapSource, type CompactionSummaryEvent } from './bootstrap.js';
2
+ import type { CharterLimits } from './limits.js';
3
+ export type StructuredDraftLanguage = 'zh' | 'en' | 'mixed';
4
+ export interface StructuredDraftMember {
5
+ readonly ref: string;
6
+ readonly text: string;
7
+ }
8
+ export interface StructuredDraftItem {
9
+ readonly ref: string;
10
+ readonly kind: 'objective' | 'invariant' | 'deliverable';
11
+ readonly text: string;
12
+ readonly lang: StructuredDraftLanguage;
13
+ readonly oversized: boolean;
14
+ /** Original UTF-8 byte count when a >4x candidate was explicitly truncated. */
15
+ readonly truncatedFrom?: number;
16
+ readonly kindConfidence?: 'high' | 'low';
17
+ readonly foldCount?: number;
18
+ readonly foldMembers?: readonly StructuredDraftMember[];
19
+ }
20
+ export interface StructuredDraftExtraction {
21
+ readonly objective: string | null;
22
+ readonly invariants: readonly string[];
23
+ readonly deliverables: readonly string[];
24
+ readonly items: readonly StructuredDraftItem[];
25
+ readonly draftLang: StructuredDraftLanguage;
26
+ readonly source: BootstrapSource;
27
+ readonly extractorVersion: 2;
28
+ }
29
+ export declare function detectLanguage(value: string): StructuredDraftLanguage;
30
+ /**
31
+ * Split only at sentence boundaries. A sentence larger than maxItemBytes is
32
+ * kept whole and marked oversized; no word/codepoint fragments are produced.
33
+ * Only a >4x sentence is explicitly truncated, and the metadata keeps the
34
+ * original byte count so the UI can explain the exception.
35
+ */
36
+ export declare function splitComplete(value: string, maxBytes: number): Array<{
37
+ readonly text: string;
38
+ readonly oversized: boolean;
39
+ readonly truncatedFrom?: number;
40
+ }>;
41
+ /** Deterministically extract a structured, language-tagged, duplicate-folded draft. */
42
+ export declare function structuredFromSummary(summary: string, limits: Pick<CharterLimits, 'maxObjectiveBytes' | 'maxItemBytes'>): {
43
+ readonly objective: string | null;
44
+ readonly items: readonly StructuredDraftItem[];
45
+ readonly draftLang: StructuredDraftLanguage;
46
+ };
47
+ /** Find the latest usable compaction summary and extract its structured draft. */
48
+ export declare function structuredFromEvents(events: readonly CompactionSummaryEvent[], limits: Pick<CharterLimits, 'maxObjectiveBytes' | 'maxItemBytes'>): StructuredDraftExtraction | undefined;
49
+ export declare const STRUCTURED_EXTRACTOR_VERSION: 2;