dsh-charter 0.3.1 → 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.
- package/CHANGELOG.md +45 -0
- package/CHANGELOG.zh.md +40 -0
- package/README.md +55 -23
- package/README.zh.md +45 -19
- package/docs/README.md +4 -2
- package/docs/README.zh.md +5 -3
- package/docs/assets/charter-graph-0.3.3.png +0 -0
- package/docs/assets/charter-graph-0.3.3.zh.png +0 -0
- package/docs/assets/charter-graph-root-text-200-0.3.2.png +0 -0
- package/docs/assets/charter-pane-0.3.3.png +0 -0
- package/docs/assets/charter-pane-0.3.3.zh.png +0 -0
- package/docs/assets/charter-state-applied-0.3.2.png +0 -0
- package/docs/assets/charter-state-conflict-0.3.2.png +0 -0
- package/docs/assets/charter-state-empty-0.3.2.png +0 -0
- package/docs/assets/charter-state-forced-colors-0.3.2.png +0 -0
- package/docs/assets/charter-state-reduced-motion-0.3.2.png +0 -0
- package/docs/assets/charter-state-staged-0.3.2.png +0 -0
- package/docs/design/charter-dependency-graph-v1.zh.md +5 -4
- package/docs/design/charter-draft-calibration-v1.zh.md +617 -0
- package/docs/design/charter-draft-extraction-v1.zh.md +346 -0
- package/docs/design/charter-gui-v1.zh.md +31 -18
- package/docs/design/compatibility.md +11 -5
- package/docs/design/compatibility.zh.md +10 -5
- package/docs/design/version-roadmap.md +12 -15
- package/docs/design/version-roadmap.zh.md +14 -11
- package/docs/release-notes/0.3.1.md +7 -4
- package/docs/release-notes/0.3.2.md +35 -0
- package/docs/release-notes/0.3.3.md +32 -0
- package/docs/release-notes/README.md +1 -1
- package/docs/releasing.md +6 -4
- package/docs/releasing.zh.md +6 -4
- package/docs/user-guide.md +16 -2
- package/docs/user-guide.zh.md +15 -2
- package/docs/verification.md +73 -48
- package/docs/verification.zh.md +69 -44
- package/lib/client/DependencyGraph.d.ts +2 -0
- package/lib/client/bootstrap-plan.d.ts +9 -1
- package/lib/client/draft-store.d.ts +12 -1
- package/lib/client/locales.d.ts +12 -0
- package/lib/client/pane-scope.d.ts +2 -0
- package/lib/client/store.d.ts +12 -1
- package/lib/client.js +567 -240
- package/lib/core/bootstrap.d.ts +14 -0
- package/lib/core/schemas.d.ts +3 -0
- package/lib/core/structured-bootstrap.d.ts +49 -0
- package/lib/core.js +2 -2
- package/lib/{fork-KSL6sovw.js → fork-h8Gx4AJd.js} +178 -166
- package/lib/host/draft-translation.d.ts +47 -0
- package/lib/host/service.d.ts +19 -1
- package/lib/host/types.d.ts +43 -0
- package/lib/index.js +3 -3
- package/lib/remote/service.d.ts +6 -1
- package/lib/remote/wire.d.ts +91 -2
- package/lib/remote.js +116 -4
- package/lib/{service-BSrE7Kbu.js → service-CPha5Ipx.js} +734 -42
- package/lib/version.d.ts +1 -1
- package/package.json +19 -18
package/lib/core/bootstrap.d.ts
CHANGED
|
@@ -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.
|
package/lib/core/schemas.d.ts
CHANGED
|
@@ -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;
|
package/lib/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { CHARTER_PROMPT_PREFIX, CHARTER_RECORD_SCHEMA_VERSION, CharterError, DEFAULT_CHARTER_LIMITS, MAX_PROPOSAL_BATCHES, MIN_HISTORY_BYTES, MIN_PROMPT_BYTES, MIN_RECORD_BYTES, MutationReplay, RECOVERY_HARD_CEILING, RECOVERY_HEADROOM, RevisionConflict, appendMaintenanceReceipt, applyOps, assertArchiveAdmission, assertRecordAdmission, assertRecordConsistency, assertRecoveryRecordAdmission, assertRecoveryRequestAdmission, assertRestorableArchive, assertSnapshotAdmission, assertStateQuota, bootstrapFromEvents, bootstrapFromSummary, buildRecordArchive, buildSnapshot, buildSnapshotUnchecked, canonicalItems, charterActorSchema, charterBootstrapApplyRequestSchema, charterChangeSchema, charterEditRequestSchema, charterError, charterEvidenceSchema, charterIdentitySchema, charterInitializeRequestSchema, charterItemSchema, charterLifecycleSchema, charterMaintenanceReceiptSchema, charterObjectiveSchema, charterOpSchema, charterReceiptSchema, charterRecordArchiveSchema, charterRecordArchiveSourceSchema, charterRecordSchema, charterRecordV1Schema, charterRestoreRequestSchema, charterReviewSchema, charterSnapshotSchema, charterValiditySchema, charterVerificationSchema, clampCharterLimits, clientRefSchema, clientRefsOf, commitRecord, compareCodeUnits, compareOrderedItems as compareItems, createEmptyRecord, deliverableInputSchema, deliverableItemSchema, deliverableProgressSchema, digestSchema, emptySnapshot, emptyStateDigest, encodePromptText, forkRecord, identifierSchema, inspectUserText, invariantInputSchema, invariantItemSchema, isDeliverable, isExpectedControlError, isInvariant, isRecordOverBudget, isStandingItem, jsonBytes, legacyValidityFor, maintenanceKindSchema, maintenanceRequestDigestOf, maintenanceSemanticCheck, migrateRecordV1ToV2, mutationIdSchema, mutationReceiptSchema, newItemInputSchema, normalizeEditRequest, normalizeUserText, objectiveProposalSchema, payloadDigestOf, proposalBatchSchema, proposalCandidateRefSchema, proposalSourceKindSchema, proposalSourceSchema, recordDigestOf, recordMaintenanceAvailable, recoveryWithinBudget, renderCharterPrompt, renderCharterPrompt as renderPrompt, requestDigestOf, restoredRecord, sha256Json, sha256Text, utf8Bytes, validateArchiveEnvelope, validateState, withPayloadDigest };
|
|
1
|
+
import { $ as clientRefsOf, $t as MIN_PROMPT_BYTES, At as digestSchema, Bt as proposalCandidateRefSchema, C as buildRecordArchive, Ct as charterSnapshotSchema, D as validateArchiveEnvelope, Dt as deliverableInputSchema, E as recordDigestOf, Et as clientRefSchema, F as buildSnapshotUnchecked, Ft as mutationIdSchema, G as compareCodeUnits, Gt as bulletLines, H as encodePromptText, Ht as proposalSourceSchema, I as emptySnapshot, It as mutationReceiptSchema, J as isInvariant, Jt as paragraphLines, K as compareOrderedItems, Kt as cleanLine, L as assertStateQuota, Lt as newItemInputSchema, Mt as invariantInputSchema, N as applyOps, Nt as invariantItemSchema, O as withPayloadDigest, Ot as deliverableItemSchema, P as buildSnapshot, Pt as maintenanceKindSchema, Qt as MIN_HISTORY_BYTES, R as validateState, Rt as objectiveProposalSchema, S as assertRestorableArchive, St as charterReviewSchema, T as payloadDigestOf, Tt as charterVerificationSchema, U as renderCharterPrompt, Ut as bootstrapFromEvents, V as CHARTER_PROMPT_PREFIX, Vt as proposalSourceKindSchema, W as canonicalItems, Wt as bootstrapFromSummary, X as sha256Json, Xt as splitSections, Y as isStandingItem, Yt as sectionKind, Z as sha256Text, Zt as DEFAULT_CHARTER_LIMITS, _ as migrateRecordV1ToV2, _t as charterRecordArchiveSchema, a as appendMaintenanceReceipt, an as recordMaintenanceAvailable, at as charterBootstrapApplyRequestSchema, b as assertArchiveAdmission, bt as charterRecordV1Schema, c as assertRecoveryRecordAdmission, cn as CharterError, ct as charterEvidenceSchema, d as createEmptyRecord, dt as charterItemSchema, en as MIN_RECORD_BYTES, et as inspectUserText, f as emptyStateDigest, ft as charterLifecycleSchema, g as maintenanceRequestDigestOf, gt as charterReceiptSchema, h as legacyValidityFor, ht as charterOpSchema, i as RevisionConflict, in as jsonBytes, it as charterActorSchema, jt as identifierSchema, kt as deliverableProgressSchema, l as assertSnapshotAdmission, ln as charterError, lt as charterIdentitySchema, m as isRecordOverBudget, mt as charterObjectiveSchema, n as MAX_PROPOSAL_BATCHES, nn as RECOVERY_HEADROOM, nt as normalizeUserText, o as assertRecordAdmission, on as recoveryWithinBudget, ot as charterChangeSchema, p as isExpectedControlError, pt as charterMaintenanceReceiptSchema, q as isDeliverable, qt as compactionSummaryEvent, r as MutationReplay, rn as clampCharterLimits, rt as CHARTER_RECORD_SCHEMA_VERSION, s as assertRecordConsistency, sn as utf8Bytes, st as charterEditRequestSchema, t as forkRecord, tn as RECOVERY_HARD_CEILING, tt as normalizeEditRequest, u as commitRecord, ut as charterInitializeRequestSchema, v as requestDigestOf, vt as charterRecordArchiveSourceSchema, w as maintenanceSemanticCheck, wt as charterValiditySchema, x as assertRecoveryRequestAdmission, xt as charterRestoreRequestSchema, y as restoredRecord, yt as charterRecordSchema, zt as proposalBatchSchema } from "./fork-h8Gx4AJd.js";
|
|
2
|
+
export { CHARTER_PROMPT_PREFIX, CHARTER_RECORD_SCHEMA_VERSION, CharterError, DEFAULT_CHARTER_LIMITS, MAX_PROPOSAL_BATCHES, MIN_HISTORY_BYTES, MIN_PROMPT_BYTES, MIN_RECORD_BYTES, MutationReplay, RECOVERY_HARD_CEILING, RECOVERY_HEADROOM, RevisionConflict, appendMaintenanceReceipt, applyOps, assertArchiveAdmission, assertRecordAdmission, assertRecordConsistency, assertRecoveryRecordAdmission, assertRecoveryRequestAdmission, assertRestorableArchive, assertSnapshotAdmission, assertStateQuota, bootstrapFromEvents, bootstrapFromSummary, buildRecordArchive, buildSnapshot, buildSnapshotUnchecked, bulletLines, canonicalItems, charterActorSchema, charterBootstrapApplyRequestSchema, charterChangeSchema, charterEditRequestSchema, charterError, charterEvidenceSchema, charterIdentitySchema, charterInitializeRequestSchema, charterItemSchema, charterLifecycleSchema, charterMaintenanceReceiptSchema, charterObjectiveSchema, charterOpSchema, charterReceiptSchema, charterRecordArchiveSchema, charterRecordArchiveSourceSchema, charterRecordSchema, charterRecordV1Schema, charterRestoreRequestSchema, charterReviewSchema, charterSnapshotSchema, charterValiditySchema, charterVerificationSchema, clampCharterLimits, cleanLine, clientRefSchema, clientRefsOf, commitRecord, compactionSummaryEvent, compareCodeUnits, compareOrderedItems as compareItems, createEmptyRecord, deliverableInputSchema, deliverableItemSchema, deliverableProgressSchema, digestSchema, emptySnapshot, emptyStateDigest, encodePromptText, forkRecord, identifierSchema, inspectUserText, invariantInputSchema, invariantItemSchema, isDeliverable, isExpectedControlError, isInvariant, isRecordOverBudget, isStandingItem, jsonBytes, legacyValidityFor, maintenanceKindSchema, maintenanceRequestDigestOf, maintenanceSemanticCheck, migrateRecordV1ToV2, mutationIdSchema, mutationReceiptSchema, newItemInputSchema, normalizeEditRequest, normalizeUserText, objectiveProposalSchema, paragraphLines, payloadDigestOf, proposalBatchSchema, proposalCandidateRefSchema, proposalSourceKindSchema, proposalSourceSchema, recordDigestOf, recordMaintenanceAvailable, recoveryWithinBudget, renderCharterPrompt, renderCharterPrompt as renderPrompt, requestDigestOf, restoredRecord, sectionKind, sha256Json, sha256Text, splitSections, utf8Bytes, validateArchiveEnvelope, validateState, withPayloadDigest };
|
|
@@ -256,6 +256,22 @@ function bootstrapFromSummary(summary, limits) {
|
|
|
256
256
|
}).flatMap((line) => splitForLimit(line, limits.maxItemBytes)), null, Number.POSITIVE_INFINITY)
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
|
+
/** Parse one compaction summary event into reviewable text plus its bounded source. */
|
|
260
|
+
function compactionSummaryEvent(event) {
|
|
261
|
+
if (event.type !== "compaction/summary") return void 0;
|
|
262
|
+
const parsed = compactionSummaryDataSchema.safeParse(event.data);
|
|
263
|
+
if (!parsed.success) return void 0;
|
|
264
|
+
const text = parsed.data.summary.map((part) => part.text).join("\n").trim();
|
|
265
|
+
if (text.length === 0) return void 0;
|
|
266
|
+
return {
|
|
267
|
+
text,
|
|
268
|
+
source: {
|
|
269
|
+
summarySeq: event.seq,
|
|
270
|
+
at: event.time,
|
|
271
|
+
...parsed.data.shadowedTokenCount === void 0 ? {} : { shadowedTokens: parsed.data.shadowedTokenCount }
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
259
275
|
/**
|
|
260
276
|
* Find the latest non-empty compaction summary and extract a draft from it.
|
|
261
277
|
* Returns undefined when the log has no usable summary.
|
|
@@ -263,176 +279,18 @@ function bootstrapFromSummary(summary, limits) {
|
|
|
263
279
|
function bootstrapFromEvents(events, limits) {
|
|
264
280
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
265
281
|
const event = events[index];
|
|
266
|
-
if (event === void 0
|
|
267
|
-
const parsed =
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
if (text.length === 0) continue;
|
|
271
|
-
const draft = bootstrapFromSummary(text, limits);
|
|
282
|
+
if (event === void 0) continue;
|
|
283
|
+
const parsed = compactionSummaryEvent(event);
|
|
284
|
+
if (parsed === void 0) continue;
|
|
285
|
+
const draft = bootstrapFromSummary(parsed.text, limits);
|
|
272
286
|
if (draft.objective === null && draft.invariants.length === 0 && draft.deliverables.length === 0) continue;
|
|
273
287
|
return {
|
|
274
288
|
draft,
|
|
275
|
-
source:
|
|
276
|
-
summarySeq: event.seq,
|
|
277
|
-
at: event.time,
|
|
278
|
-
...parsed.data.shadowedTokenCount === void 0 ? {} : { shadowedTokens: parsed.data.shadowedTokenCount }
|
|
279
|
-
}
|
|
289
|
+
source: parsed.source
|
|
280
290
|
};
|
|
281
291
|
}
|
|
282
292
|
}
|
|
283
293
|
//#endregion
|
|
284
|
-
//#region .build-ts/core/authorization.js
|
|
285
|
-
/**
|
|
286
|
-
* Apply the actor policy before any storage mutation.
|
|
287
|
-
*
|
|
288
|
-
* `owner` and `user` are human callers. Both may perform ordinary charter
|
|
289
|
-
* edits. Irreversible purge is owner-only. `host` is reserved for internal
|
|
290
|
-
* operations that do not pass through the Remote edit path.
|
|
291
|
-
*/
|
|
292
|
-
function assertEditAuthorized(actor, ops) {
|
|
293
|
-
if (ops.some((op) => op.type === "item.validity.set")) {
|
|
294
|
-
if (actor.kind !== "host") throw charterError("FORBIDDEN", "validator results are written by the Host, not a client edit");
|
|
295
|
-
if (ops.some((op) => op.type !== "item.validity.set")) throw charterError("FORBIDDEN", "validator results cannot share a Change Set with ordinary edits");
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (actor.kind === "host") throw charterError("FORBIDDEN", "host authoring is limited to validator results");
|
|
299
|
-
if (actor.kind === "owner") return;
|
|
300
|
-
if (actor.kind === "user") {
|
|
301
|
-
if (ops.some((op) => op.type === "item.purge" || op.type === "objective.purge")) throw charterError("FORBIDDEN", "purge requires an owner actor");
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (actor.kind === "agent-tool") {
|
|
305
|
-
if (ops.every((op) => op.type === "item.propose")) return;
|
|
306
|
-
throw charterError("FORBIDDEN", "agent-tool may only create pending item proposals");
|
|
307
|
-
}
|
|
308
|
-
throw charterError("FORBIDDEN", `actor ${actor.kind} cannot edit the session charter`);
|
|
309
|
-
}
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region .build-ts/core/digest.js
|
|
312
|
-
function sha256Text(value) {
|
|
313
|
-
return `sha256:${createHash("sha256").update(value, "utf8").digest("hex")}`;
|
|
314
|
-
}
|
|
315
|
-
function sha256Json(value) {
|
|
316
|
-
return sha256Text(JSON.stringify(value));
|
|
317
|
-
}
|
|
318
|
-
//#endregion
|
|
319
|
-
//#region .build-ts/core/items.js
|
|
320
|
-
function compareCodeUnits(left, right) {
|
|
321
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
322
|
-
}
|
|
323
|
-
function compareOrderedItems(left, right) {
|
|
324
|
-
return left.order - right.order || compareCodeUnits(left.id, right.id);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Rebuild one item with the exact schema field order and without explicit
|
|
328
|
-
* `undefined` optional fields. The state digest hashes this shape, so a record
|
|
329
|
-
* parsed from JSON (zod schema order) and a record built in memory must hash
|
|
330
|
-
* identically regardless of property insertion order.
|
|
331
|
-
*/
|
|
332
|
-
function normalizeItemShape(item) {
|
|
333
|
-
const common = {
|
|
334
|
-
id: item.id,
|
|
335
|
-
text: item.text,
|
|
336
|
-
review: item.review,
|
|
337
|
-
lifecycle: item.lifecycle,
|
|
338
|
-
verification: item.verification,
|
|
339
|
-
origin: item.origin,
|
|
340
|
-
order: item.order,
|
|
341
|
-
createdRevision: item.createdRevision,
|
|
342
|
-
...item.supersedes === void 0 ? {} : { supersedes: item.supersedes },
|
|
343
|
-
...item.supersededBy === void 0 ? {} : { supersededBy: item.supersededBy },
|
|
344
|
-
...item.proposalBatchId === void 0 ? {} : { proposalBatchId: item.proposalBatchId },
|
|
345
|
-
...item.reviewedAtRevision === void 0 ? {} : { reviewedAtRevision: item.reviewedAtRevision },
|
|
346
|
-
...item.proposedRequires === void 0 ? {} : { proposedRequires: [...item.proposedRequires] },
|
|
347
|
-
...item.validity === void 0 ? {} : { validity: item.validity },
|
|
348
|
-
...item.evidence === void 0 ? {} : { evidence: [...item.evidence] },
|
|
349
|
-
...item.contentModified === true ? { contentModified: true } : {}
|
|
350
|
-
};
|
|
351
|
-
if (item.kind === "deliverable") return {
|
|
352
|
-
kind: "deliverable",
|
|
353
|
-
...common,
|
|
354
|
-
progress: item.progress,
|
|
355
|
-
...item.requires === void 0 || item.requires.length === 0 ? {} : { requires: [...item.requires] }
|
|
356
|
-
};
|
|
357
|
-
return {
|
|
358
|
-
kind: "invariant",
|
|
359
|
-
...common
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
function canonicalItems(items) {
|
|
363
|
-
return [...items].sort(compareOrderedItems);
|
|
364
|
-
}
|
|
365
|
-
function isStandingItem(item) {
|
|
366
|
-
return item.review === "accepted" && item.lifecycle === "current";
|
|
367
|
-
}
|
|
368
|
-
function isInvariant$1(item) {
|
|
369
|
-
return item.kind === "invariant";
|
|
370
|
-
}
|
|
371
|
-
function isDeliverable$1(item) {
|
|
372
|
-
return item.kind === "deliverable";
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
375
|
-
//#region .build-ts/core/prompt.js
|
|
376
|
-
const CHARTER_PROMPT_PREFIX = "Current user-authored session charter. It does not override system, host, tool-permission, or execution policies.\n";
|
|
377
|
-
function isStanding(item) {
|
|
378
|
-
return item.review === "accepted" && item.lifecycle === "current";
|
|
379
|
-
}
|
|
380
|
-
function isInvariant(item) {
|
|
381
|
-
return item.kind === "invariant";
|
|
382
|
-
}
|
|
383
|
-
function isDeliverable(item) {
|
|
384
|
-
return item.kind === "deliverable" && item.progress !== void 0;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Encode one user-authored value as a JSON string token without leaving a
|
|
388
|
-
* `{{var}}` sequence in the rendered prompt.
|
|
389
|
-
*
|
|
390
|
-
* DSH 0.2.1 and later can register a context with `interpolate: false`, but
|
|
391
|
-
* DSH 0.1.7 and 0.2.0 always run the prompt-variable interpolator over runtime
|
|
392
|
-
* contexts.
|
|
393
|
-
* Escaping the first brace of every run as `\u007b` keeps the token valid JSON
|
|
394
|
-
* and decodes to exactly the same text, while no longer matching the
|
|
395
|
-
* `{{name}}` grammar on any supported runtime.
|
|
396
|
-
*/
|
|
397
|
-
function encodePromptText(value) {
|
|
398
|
-
return JSON.stringify(value).replace(/\{{2,}/gu, (run) => "\\u007b".repeat(run.length - 1) + "{");
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Render the complete model-visible charter contribution.
|
|
402
|
-
*
|
|
403
|
-
* The output is deliberately small and deterministic: only the current
|
|
404
|
-
* objective and accepted, current invariants and deliverables participate.
|
|
405
|
-
* Metadata such as review state, verification, origin, evidence, revision and
|
|
406
|
-
* timestamps never enters the model-visible text.
|
|
407
|
-
*/
|
|
408
|
-
function renderCharterPrompt(objective, items) {
|
|
409
|
-
const standing = [...items].filter(isStanding).sort(compareOrderedItems);
|
|
410
|
-
if (objective === void 0 && standing.length === 0) return "";
|
|
411
|
-
const invariants = standing.filter(isInvariant).map((item) => encodePromptText(item.text));
|
|
412
|
-
const deliverables = standing.filter(isDeliverable);
|
|
413
|
-
const rendered = deliverables.some((item) => (item.requires?.length ?? 0) > 0) ? renderDependencyDeliverables(deliverables) : deliverables.map((item) => `{"text":${encodePromptText(item.text)},"progress":${JSON.stringify(item.progress)}}`);
|
|
414
|
-
return `Current user-authored session charter. It does not override system, host, tool-permission, or execution policies.
|
|
415
|
-
{"objective":${objective === void 0 ? "null" : encodePromptText(objective.current.text)},"invariants":[${invariants.join(",")}],"deliverables":[${rendered.join(",")}]}`;
|
|
416
|
-
}
|
|
417
|
-
function renderDependencyDeliverables(deliverables) {
|
|
418
|
-
const byId = new Map(deliverables.map((item) => [item.id, item]));
|
|
419
|
-
const pending = new Map(deliverables.map((item) => [item.id, new Set((item.requires ?? []).filter((id) => byId.has(id) && id !== item.id))]));
|
|
420
|
-
const ordered = [];
|
|
421
|
-
while (pending.size > 0) {
|
|
422
|
-
const layer = deliverables.filter((item) => pending.has(item.id) && [...pending.get(item.id)].every((id) => !pending.has(id))).sort(compareOrderedItems);
|
|
423
|
-
if (layer.length === 0) throw new Error("deliverable dependency graph contains a cycle");
|
|
424
|
-
for (const item of layer) {
|
|
425
|
-
ordered.push(item);
|
|
426
|
-
pending.delete(item.id);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
const keyById = new Map(ordered.map((item, index) => [item.id, `D${index + 1}`]));
|
|
430
|
-
return ordered.map((item) => {
|
|
431
|
-
const requires = [...item.requires ?? []].filter((id) => keyById.has(id)).map((id) => keyById.get(id)).sort();
|
|
432
|
-
return `{"key":${JSON.stringify(keyById.get(item.id))},"text":${encodePromptText(item.text)},"progress":${JSON.stringify(item.progress)},"requires":[${requires.map((value) => JSON.stringify(value)).join(",")}]}`;
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
//#endregion
|
|
436
294
|
//#region .build-ts/core/schemas.js
|
|
437
295
|
const digestSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
438
296
|
const identifierSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u);
|
|
@@ -624,7 +482,8 @@ const newItemInputSchema = z.discriminatedUnion("kind", [invariantInputSchema, d
|
|
|
624
482
|
const charterOpSchema = z.discriminatedUnion("type", [
|
|
625
483
|
z.object({
|
|
626
484
|
type: z.literal("objective.initialize"),
|
|
627
|
-
text: z.string()
|
|
485
|
+
text: z.string(),
|
|
486
|
+
clientRef: clientRefSchema.optional()
|
|
628
487
|
}).strict(),
|
|
629
488
|
z.object({
|
|
630
489
|
type: z.literal("objective.redirect"),
|
|
@@ -1082,7 +941,8 @@ function normalizeOp(op) {
|
|
|
1082
941
|
switch (op.type) {
|
|
1083
942
|
case "objective.initialize": return {
|
|
1084
943
|
type: op.type,
|
|
1085
|
-
text: normalizeUserText(op.text, "objective")
|
|
944
|
+
text: normalizeUserText(op.text, "objective"),
|
|
945
|
+
...op.clientRef === void 0 ? {} : { clientRef: op.clientRef }
|
|
1086
946
|
};
|
|
1087
947
|
case "objective.redirect": return {
|
|
1088
948
|
type: op.type,
|
|
@@ -1155,6 +1015,158 @@ function clientRefsOf(ops) {
|
|
|
1155
1015
|
return refs;
|
|
1156
1016
|
}
|
|
1157
1017
|
//#endregion
|
|
1018
|
+
//#region .build-ts/core/authorization.js
|
|
1019
|
+
/**
|
|
1020
|
+
* Apply the actor policy before any storage mutation.
|
|
1021
|
+
*
|
|
1022
|
+
* `owner` and `user` are human callers. Both may perform ordinary charter
|
|
1023
|
+
* edits. Irreversible purge is owner-only. `host` is reserved for internal
|
|
1024
|
+
* operations that do not pass through the Remote edit path.
|
|
1025
|
+
*/
|
|
1026
|
+
function assertEditAuthorized(actor, ops) {
|
|
1027
|
+
if (ops.some((op) => op.type === "item.validity.set")) {
|
|
1028
|
+
if (actor.kind !== "host") throw charterError("FORBIDDEN", "validator results are written by the Host, not a client edit");
|
|
1029
|
+
if (ops.some((op) => op.type !== "item.validity.set")) throw charterError("FORBIDDEN", "validator results cannot share a Change Set with ordinary edits");
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
if (actor.kind === "host") throw charterError("FORBIDDEN", "host authoring is limited to validator results");
|
|
1033
|
+
if (actor.kind === "owner") return;
|
|
1034
|
+
if (actor.kind === "user") {
|
|
1035
|
+
if (ops.some((op) => op.type === "item.purge" || op.type === "objective.purge")) throw charterError("FORBIDDEN", "purge requires an owner actor");
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (actor.kind === "agent-tool") {
|
|
1039
|
+
if (ops.every((op) => op.type === "item.propose")) return;
|
|
1040
|
+
throw charterError("FORBIDDEN", "agent-tool may only create pending item proposals");
|
|
1041
|
+
}
|
|
1042
|
+
throw charterError("FORBIDDEN", `actor ${actor.kind} cannot edit the session charter`);
|
|
1043
|
+
}
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region .build-ts/core/digest.js
|
|
1046
|
+
function sha256Text(value) {
|
|
1047
|
+
return `sha256:${createHash("sha256").update(value, "utf8").digest("hex")}`;
|
|
1048
|
+
}
|
|
1049
|
+
function sha256Json(value) {
|
|
1050
|
+
return sha256Text(JSON.stringify(value));
|
|
1051
|
+
}
|
|
1052
|
+
//#endregion
|
|
1053
|
+
//#region .build-ts/core/items.js
|
|
1054
|
+
function compareCodeUnits(left, right) {
|
|
1055
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
1056
|
+
}
|
|
1057
|
+
function compareOrderedItems(left, right) {
|
|
1058
|
+
return left.order - right.order || compareCodeUnits(left.id, right.id);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Rebuild one item with the exact schema field order and without explicit
|
|
1062
|
+
* `undefined` optional fields. The state digest hashes this shape, so a record
|
|
1063
|
+
* parsed from JSON (zod schema order) and a record built in memory must hash
|
|
1064
|
+
* identically regardless of property insertion order.
|
|
1065
|
+
*/
|
|
1066
|
+
function normalizeItemShape(item) {
|
|
1067
|
+
const common = {
|
|
1068
|
+
id: item.id,
|
|
1069
|
+
text: item.text,
|
|
1070
|
+
review: item.review,
|
|
1071
|
+
lifecycle: item.lifecycle,
|
|
1072
|
+
verification: item.verification,
|
|
1073
|
+
origin: item.origin,
|
|
1074
|
+
order: item.order,
|
|
1075
|
+
createdRevision: item.createdRevision,
|
|
1076
|
+
...item.supersedes === void 0 ? {} : { supersedes: item.supersedes },
|
|
1077
|
+
...item.supersededBy === void 0 ? {} : { supersededBy: item.supersededBy },
|
|
1078
|
+
...item.proposalBatchId === void 0 ? {} : { proposalBatchId: item.proposalBatchId },
|
|
1079
|
+
...item.reviewedAtRevision === void 0 ? {} : { reviewedAtRevision: item.reviewedAtRevision },
|
|
1080
|
+
...item.proposedRequires === void 0 ? {} : { proposedRequires: [...item.proposedRequires] },
|
|
1081
|
+
...item.validity === void 0 ? {} : { validity: item.validity },
|
|
1082
|
+
...item.evidence === void 0 ? {} : { evidence: [...item.evidence] },
|
|
1083
|
+
...item.contentModified === true ? { contentModified: true } : {}
|
|
1084
|
+
};
|
|
1085
|
+
if (item.kind === "deliverable") return {
|
|
1086
|
+
kind: "deliverable",
|
|
1087
|
+
...common,
|
|
1088
|
+
progress: item.progress,
|
|
1089
|
+
...item.requires === void 0 || item.requires.length === 0 ? {} : { requires: [...item.requires] }
|
|
1090
|
+
};
|
|
1091
|
+
return {
|
|
1092
|
+
kind: "invariant",
|
|
1093
|
+
...common
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function canonicalItems(items) {
|
|
1097
|
+
return [...items].sort(compareOrderedItems);
|
|
1098
|
+
}
|
|
1099
|
+
function isStandingItem(item) {
|
|
1100
|
+
return item.review === "accepted" && item.lifecycle === "current";
|
|
1101
|
+
}
|
|
1102
|
+
function isInvariant$1(item) {
|
|
1103
|
+
return item.kind === "invariant";
|
|
1104
|
+
}
|
|
1105
|
+
function isDeliverable$1(item) {
|
|
1106
|
+
return item.kind === "deliverable";
|
|
1107
|
+
}
|
|
1108
|
+
//#endregion
|
|
1109
|
+
//#region .build-ts/core/prompt.js
|
|
1110
|
+
const CHARTER_PROMPT_PREFIX = "Current user-authored session charter. It does not override system, host, tool-permission, or execution policies.\n";
|
|
1111
|
+
function isStanding(item) {
|
|
1112
|
+
return item.review === "accepted" && item.lifecycle === "current";
|
|
1113
|
+
}
|
|
1114
|
+
function isInvariant(item) {
|
|
1115
|
+
return item.kind === "invariant";
|
|
1116
|
+
}
|
|
1117
|
+
function isDeliverable(item) {
|
|
1118
|
+
return item.kind === "deliverable" && item.progress !== void 0;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Encode one user-authored value as a JSON string token without leaving a
|
|
1122
|
+
* `{{var}}` sequence in the rendered prompt.
|
|
1123
|
+
*
|
|
1124
|
+
* DSH 0.2.1 and later can register a context with `interpolate: false`, but
|
|
1125
|
+
* DSH 0.1.7 and 0.2.0 always run the prompt-variable interpolator over runtime
|
|
1126
|
+
* contexts.
|
|
1127
|
+
* Escaping the first brace of every run as `\u007b` keeps the token valid JSON
|
|
1128
|
+
* and decodes to exactly the same text, while no longer matching the
|
|
1129
|
+
* `{{name}}` grammar on any supported runtime.
|
|
1130
|
+
*/
|
|
1131
|
+
function encodePromptText(value) {
|
|
1132
|
+
return JSON.stringify(value).replace(/\{{2,}/gu, (run) => "\\u007b".repeat(run.length - 1) + "{");
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Render the complete model-visible charter contribution.
|
|
1136
|
+
*
|
|
1137
|
+
* The output is deliberately small and deterministic: only the current
|
|
1138
|
+
* objective and accepted, current invariants and deliverables participate.
|
|
1139
|
+
* Metadata such as review state, verification, origin, evidence, revision and
|
|
1140
|
+
* timestamps never enters the model-visible text.
|
|
1141
|
+
*/
|
|
1142
|
+
function renderCharterPrompt(objective, items) {
|
|
1143
|
+
const standing = [...items].filter(isStanding).sort(compareOrderedItems);
|
|
1144
|
+
if (objective === void 0 && standing.length === 0) return "";
|
|
1145
|
+
const invariants = standing.filter(isInvariant).map((item) => encodePromptText(item.text));
|
|
1146
|
+
const deliverables = standing.filter(isDeliverable);
|
|
1147
|
+
const rendered = deliverables.some((item) => (item.requires?.length ?? 0) > 0) ? renderDependencyDeliverables(deliverables) : deliverables.map((item) => `{"text":${encodePromptText(item.text)},"progress":${JSON.stringify(item.progress)}}`);
|
|
1148
|
+
return `Current user-authored session charter. It does not override system, host, tool-permission, or execution policies.
|
|
1149
|
+
{"objective":${objective === void 0 ? "null" : encodePromptText(objective.current.text)},"invariants":[${invariants.join(",")}],"deliverables":[${rendered.join(",")}]}`;
|
|
1150
|
+
}
|
|
1151
|
+
function renderDependencyDeliverables(deliverables) {
|
|
1152
|
+
const byId = new Map(deliverables.map((item) => [item.id, item]));
|
|
1153
|
+
const pending = new Map(deliverables.map((item) => [item.id, new Set((item.requires ?? []).filter((id) => byId.has(id) && id !== item.id))]));
|
|
1154
|
+
const ordered = [];
|
|
1155
|
+
while (pending.size > 0) {
|
|
1156
|
+
const layer = deliverables.filter((item) => pending.has(item.id) && [...pending.get(item.id)].every((id) => !pending.has(id))).sort(compareOrderedItems);
|
|
1157
|
+
if (layer.length === 0) throw new Error("deliverable dependency graph contains a cycle");
|
|
1158
|
+
for (const item of layer) {
|
|
1159
|
+
ordered.push(item);
|
|
1160
|
+
pending.delete(item.id);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
const keyById = new Map(ordered.map((item, index) => [item.id, `D${index + 1}`]));
|
|
1164
|
+
return ordered.map((item) => {
|
|
1165
|
+
const requires = [...item.requires ?? []].filter((id) => keyById.has(id)).map((id) => keyById.get(id)).sort();
|
|
1166
|
+
return `{"key":${JSON.stringify(keyById.get(item.id))},"text":${encodePromptText(item.text)},"progress":${JSON.stringify(item.progress)},"requires":[${requires.map((value) => JSON.stringify(value)).join(",")}]}`;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
//#endregion
|
|
1158
1170
|
//#region .build-ts/core/dependencies.js
|
|
1159
1171
|
function standingDeliverables(items) {
|
|
1160
1172
|
return items.filter((item) => isStandingItem(item) && isDeliverable$1(item));
|
|
@@ -2734,4 +2746,4 @@ function forkRecord(input) {
|
|
|
2734
2746
|
return child;
|
|
2735
2747
|
}
|
|
2736
2748
|
//#endregion
|
|
2737
|
-
export {
|
|
2749
|
+
export { clientRefsOf as $, MIN_PROMPT_BYTES as $t, compactionProjectionDigest as A, digestSchema as At, dependencyProjection as B, proposalCandidateRefSchema as Bt, buildRecordArchive as C, charterSnapshotSchema as Ct, validateArchiveEnvelope as D, deliverableInputSchema as Dt, recordDigestOf as E, clientRefSchema as Et, buildSnapshotUnchecked as F, mutationIdSchema as Ft, compareCodeUnits as G, bulletLines as Gt, encodePromptText as H, proposalSourceSchema as Ht, emptySnapshot as I, mutationReceiptSchema as It, isInvariant$1 as J, paragraphLines as Jt, compareOrderedItems as K, cleanLine as Kt, assertStateQuota as L, newItemInputSchema as Lt, verifySourceProjection as M, invariantInputSchema as Mt, applyOps as N, invariantItemSchema as Nt, withPayloadDigest as O, deliverableItemSchema as Ot, buildSnapshot as P, maintenanceKindSchema as Pt, assertEditAuthorized as Q, MIN_HISTORY_BYTES as Qt, validateState as R, objectiveProposalSchema as Rt, assertRestorableArchive as S, charterReviewSchema as St, payloadDigestOf as T, charterVerificationSchema as Tt, renderCharterPrompt as U, bootstrapFromEvents as Ut, CHARTER_PROMPT_PREFIX as V, proposalSourceKindSchema as Vt, canonicalItems as W, bootstrapFromSummary as Wt, sha256Json as X, splitSections as Xt, isStandingItem as Y, sectionKind as Yt, sha256Text as Z, DEFAULT_CHARTER_LIMITS as Zt, migrateRecordV1ToV2 as _, charterRecordArchiveSchema as _t, appendMaintenanceReceipt as a, recordMaintenanceAvailable as an, charterBootstrapApplyRequestSchema as at, assertArchiveAdmission as b, charterRecordV1Schema as bt, assertRecoveryRecordAdmission as c, CharterError as cn, charterEvidenceSchema as ct, createEmptyRecord as d, charterItemSchema as dt, MIN_RECORD_BYTES as en, inspectUserText as et, emptyStateDigest as f, charterLifecycleSchema as ft, maintenanceRequestDigestOf as g, charterReceiptSchema as gt, legacyValidityFor as h, charterOpSchema as ht, RevisionConflict as i, jsonBytes as in, charterActorSchema as it, messageProjectionDigest as j, identifierSchema as jt, agentProjectionDigest as k, deliverableProgressSchema as kt, assertSnapshotAdmission as l, charterError as ln, charterIdentitySchema as lt, isRecordOverBudget as m, charterObjectiveSchema as mt, MAX_PROPOSAL_BATCHES as n, RECOVERY_HEADROOM as nn, normalizeUserText as nt, assertRecordAdmission as o, recoveryWithinBudget as on, charterChangeSchema as ot, isExpectedControlError as p, charterMaintenanceReceiptSchema as pt, isDeliverable$1 as q, compactionSummaryEvent as qt, MutationReplay as r, clampCharterLimits as rn, CHARTER_RECORD_SCHEMA_VERSION as rt, assertRecordConsistency as s, utf8Bytes as sn, charterEditRequestSchema as st, forkRecord as t, RECOVERY_HARD_CEILING as tn, normalizeEditRequest as tt, commitRecord as u, charterInitializeRequestSchema as ut, requestDigestOf as v, charterRecordArchiveSourceSchema as vt, maintenanceSemanticCheck as w, charterValiditySchema as wt, assertRecoveryRequestAdmission as x, charterRestoreRequestSchema as xt, restoredRecord as y, charterRecordSchema as yt, dependencyConflictDiff as z, proposalBatchSchema as zt };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CharterBootstrapDraftItem } from './types.js';
|
|
2
|
+
export interface DraftTranslationModel {
|
|
3
|
+
readonly provider: string;
|
|
4
|
+
readonly model: string;
|
|
5
|
+
}
|
|
6
|
+
/** Minimal structural view of the host LLM service; avoids a hard DSH-version type dependency. */
|
|
7
|
+
export interface DraftLlmRuntime {
|
|
8
|
+
stream(options: {
|
|
9
|
+
readonly provider: string;
|
|
10
|
+
readonly model: string;
|
|
11
|
+
readonly system: string;
|
|
12
|
+
readonly messages: readonly {
|
|
13
|
+
readonly role: 'user';
|
|
14
|
+
readonly content: readonly {
|
|
15
|
+
readonly type: 'text';
|
|
16
|
+
readonly text: string;
|
|
17
|
+
}[];
|
|
18
|
+
}[];
|
|
19
|
+
readonly temperature?: number;
|
|
20
|
+
readonly reasoningEffort?: string;
|
|
21
|
+
readonly maxTokens: number;
|
|
22
|
+
readonly signal: AbortSignal;
|
|
23
|
+
}): AsyncIterable<DraftStreamChunk>;
|
|
24
|
+
}
|
|
25
|
+
interface DraftStreamChunk {
|
|
26
|
+
readonly type: string;
|
|
27
|
+
readonly index?: number;
|
|
28
|
+
readonly text?: string;
|
|
29
|
+
readonly block?: {
|
|
30
|
+
readonly type?: string;
|
|
31
|
+
readonly text?: string;
|
|
32
|
+
};
|
|
33
|
+
readonly reason?: {
|
|
34
|
+
readonly kind?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface DraftTranslationResult {
|
|
38
|
+
readonly items: readonly CharterBootstrapDraftItem[];
|
|
39
|
+
readonly translatedRefs: readonly string[];
|
|
40
|
+
readonly failedRefs: readonly string[];
|
|
41
|
+
readonly provider: string;
|
|
42
|
+
readonly model: string;
|
|
43
|
+
}
|
|
44
|
+
/** Translate active representative candidates with one host-managed LLM call. */
|
|
45
|
+
export declare function translateDraftItems(llm: DraftLlmRuntime, model: DraftTranslationModel, target: 'zh' | 'en', items: readonly CharterBootstrapDraftItem[], signal?: AbortSignal, timeoutMs?: number): Promise<DraftTranslationResult>;
|
|
46
|
+
export declare function targetLanguageOf(value: string | undefined): 'zh' | 'en' | null;
|
|
47
|
+
export {};
|
package/lib/host/service.d.ts
CHANGED
|
@@ -5,10 +5,17 @@ import { type SessionId as SessionIdType } from '@deepseek-ai/dsh-session/types'
|
|
|
5
5
|
import { type CharterLimits } from '../core/limits.js';
|
|
6
6
|
import { type ItemQueryRequest } from '../core/query.js';
|
|
7
7
|
import { type CharterActor } from '../core/schemas.js';
|
|
8
|
-
import type { CharterEditResult, CharterListener, CharterToolView, CharterBootstrapResult, CharterRecordExport, CharterRecordOperationResult, CharterView, CharterSummary, CharterItemQueryResult, CharterProposalQueryResult, CharterChangeQueryResult, CharterArchiveListResult, CharterArchiveReadResult } from './types.js';
|
|
8
|
+
import type { CharterEditResult, CharterListener, CharterToolView, CharterBootstrapResult, CharterBootstrapDraftResult, CharterRecordExport, CharterRecordOperationResult, CharterView, CharterSummary, CharterItemQueryResult, CharterProposalQueryResult, CharterChangeQueryResult, CharterArchiveListResult, CharterArchiveReadResult } from './types.js';
|
|
9
9
|
import type { SessionStartSource as StartSource } from '@deepseek-ai/dsh-agent';
|
|
10
10
|
export interface CharterConfig extends CharterLimits {
|
|
11
11
|
readonly contextOrder: number;
|
|
12
|
+
/** Automatically normalize a review draft to the DSH UI language via the session model. */
|
|
13
|
+
readonly languageFollow: boolean;
|
|
14
|
+
/** Bound one automatic language-normalization call; the draft stays usable on timeout. */
|
|
15
|
+
readonly languageFollowTimeoutMs: number;
|
|
16
|
+
/** Optional dedicated translation route; both fields must be set to override the session model. */
|
|
17
|
+
readonly languageFollowProvider?: string;
|
|
18
|
+
readonly languageFollowModel?: string;
|
|
12
19
|
}
|
|
13
20
|
export declare const DEFAULT_CHARTER_CONFIG: CharterConfig;
|
|
14
21
|
export declare const Config: Schema<CharterConfig>;
|
|
@@ -17,6 +24,8 @@ export declare class CharterService extends Service {
|
|
|
17
24
|
static inject: string[];
|
|
18
25
|
static Config: Schema<CharterConfig>;
|
|
19
26
|
private readonly config;
|
|
27
|
+
private readonly localizedDrafts;
|
|
28
|
+
private readonly translatedItems;
|
|
20
29
|
private sessionsTable;
|
|
21
30
|
private archivesTable;
|
|
22
31
|
private archivesDomain;
|
|
@@ -81,6 +90,14 @@ export declare class CharterService extends Service {
|
|
|
81
90
|
* prompt. The user reviews and applies it through the normal atomic edit.
|
|
82
91
|
*/
|
|
83
92
|
bootstrap(sessionId: SessionIdType): CharterBootstrapResult;
|
|
93
|
+
/** Extract a structured, duplicate-folded draft and follow the requested UI language. */
|
|
94
|
+
bootstrapDraft(sessionId: SessionIdType, requestedLanguage?: string, awaitTranslation?: boolean): Promise<CharterBootstrapDraftResult>;
|
|
95
|
+
/** The validated localized draft used by applyBootstrap for structured refs. */
|
|
96
|
+
private structuredDraftForHandle;
|
|
97
|
+
private translationModel;
|
|
98
|
+
private withTranslatedItem;
|
|
99
|
+
private trimMap;
|
|
100
|
+
private structuredDraftHandle;
|
|
84
101
|
private bootstrapDraftHandle;
|
|
85
102
|
private viewLimits;
|
|
86
103
|
/**
|
|
@@ -108,6 +125,7 @@ export declare class CharterService extends Service {
|
|
|
108
125
|
/** Host-only source for a bootstrap apply; callers cannot provide provenance. */
|
|
109
126
|
bootstrapProposalSource(sessionId: SessionIdType): import('../core/schemas.js').ProposalSource | undefined;
|
|
110
127
|
applyBootstrap(request: unknown, actor?: CharterActor): Promise<CharterEditResult>;
|
|
128
|
+
private applyStructuredBootstrap;
|
|
111
129
|
previewChangeSet(untrustedRequest: unknown, actor?: CharterActor): import('./types.js').CharterChangeSetPreviewResult;
|
|
112
130
|
private dedupeBootstrapRequest;
|
|
113
131
|
private sourceProjectionShared;
|