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.
- package/CHANGELOG.md +19 -1
- package/CHANGELOG.zh.md +18 -1
- package/README.md +46 -26
- package/README.zh.md +37 -21
- package/docs/README.md +2 -0
- package/docs/README.zh.md +2 -0
- 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-pane-0.3.3.png +0 -0
- package/docs/assets/charter-pane-0.3.3.zh.png +0 -0
- 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 +2 -2
- package/docs/design/compatibility.md +11 -5
- package/docs/design/compatibility.zh.md +10 -5
- package/docs/design/version-roadmap.md +9 -11
- package/docs/design/version-roadmap.zh.md +6 -4
- package/docs/release-notes/0.3.2.md +6 -5
- package/docs/release-notes/0.3.3.md +32 -0
- package/docs/release-notes/README.md +1 -1
- package/docs/releasing.md +6 -5
- package/docs/releasing.zh.md +6 -5
- package/docs/user-guide.md +16 -2
- package/docs/user-guide.zh.md +15 -2
- package/docs/verification.md +31 -23
- package/docs/verification.zh.md +32 -23
- package/lib/client/bootstrap-plan.d.ts +9 -1
- package/lib/client/draft-store.d.ts +12 -1
- package/lib/client/locales.d.ts +11 -0
- package/lib/client/pane-scope.d.ts +2 -0
- package/lib/client/store.d.ts +12 -1
- package/lib/client.js +328 -41
- 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.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;
|
package/lib/host/types.d.ts
CHANGED
|
@@ -216,6 +216,11 @@ export interface CharterBootstrapProposal {
|
|
|
216
216
|
readonly invariants: string[];
|
|
217
217
|
readonly deliverables: string[];
|
|
218
218
|
readonly source: CharterBootstrapSource;
|
|
219
|
+
/** Structured candidates are present only on the additive `bootstrapDraft` method. */
|
|
220
|
+
readonly draftItems?: readonly CharterBootstrapDraftItem[];
|
|
221
|
+
readonly draftLang?: CharterDraftLanguage;
|
|
222
|
+
readonly language?: CharterBootstrapLanguage;
|
|
223
|
+
readonly extractorVersion?: 2;
|
|
219
224
|
}
|
|
220
225
|
export type CharterBootstrapResult = {
|
|
221
226
|
readonly available: true;
|
|
@@ -225,6 +230,44 @@ export type CharterBootstrapResult = {
|
|
|
225
230
|
readonly reason: 'not-live' | 'no-summary' | 'unavailable';
|
|
226
231
|
readonly message?: string;
|
|
227
232
|
};
|
|
233
|
+
export type CharterDraftLanguage = 'zh' | 'en' | 'mixed';
|
|
234
|
+
export interface CharterBootstrapDraftMember {
|
|
235
|
+
readonly ref: string;
|
|
236
|
+
readonly text: string;
|
|
237
|
+
}
|
|
238
|
+
export interface CharterBootstrapDraftItem {
|
|
239
|
+
readonly ref: string;
|
|
240
|
+
readonly kind: 'objective' | 'invariant' | 'deliverable';
|
|
241
|
+
readonly text: string;
|
|
242
|
+
readonly lang: CharterDraftLanguage;
|
|
243
|
+
readonly oversized: boolean;
|
|
244
|
+
readonly truncatedFrom?: number;
|
|
245
|
+
readonly kindConfidence?: 'high' | 'low';
|
|
246
|
+
readonly foldCount?: number;
|
|
247
|
+
readonly foldMembers?: readonly CharterBootstrapDraftMember[];
|
|
248
|
+
}
|
|
249
|
+
export type CharterLanguageStatus = 'source' | 'translated' | 'partial' | 'pending' | 'unavailable' | 'failed' | 'disabled';
|
|
250
|
+
export interface CharterBootstrapLanguage {
|
|
251
|
+
readonly requested: 'zh' | 'en' | null;
|
|
252
|
+
readonly status: CharterLanguageStatus;
|
|
253
|
+
readonly reason?: string;
|
|
254
|
+
readonly provider?: string;
|
|
255
|
+
readonly model?: string;
|
|
256
|
+
}
|
|
257
|
+
export interface CharterBootstrapDraftProposal extends CharterBootstrapProposal {
|
|
258
|
+
readonly items: readonly CharterBootstrapDraftItem[];
|
|
259
|
+
readonly draftLang: CharterDraftLanguage;
|
|
260
|
+
readonly language: CharterBootstrapLanguage;
|
|
261
|
+
readonly extractorVersion: 2;
|
|
262
|
+
}
|
|
263
|
+
export type CharterBootstrapDraftResult = {
|
|
264
|
+
readonly available: true;
|
|
265
|
+
readonly proposal: CharterBootstrapDraftProposal;
|
|
266
|
+
} | {
|
|
267
|
+
readonly available: false;
|
|
268
|
+
readonly reason: 'not-live' | 'no-summary' | 'unavailable';
|
|
269
|
+
readonly message?: string;
|
|
270
|
+
};
|
|
228
271
|
export interface CharterToolItem {
|
|
229
272
|
/**
|
|
230
273
|
* Always present in the bounded `all` debugging view. In the `standing` view
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { a as CHARTER_DOMAIN_NAME, n as Config, o as CHARTER_DOMAIN_VERSION, r as DEFAULT_CHARTER_CONFIG, s as charterDomainSpec, t as CharterService } from "./service-
|
|
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
|
+
import { a as CHARTER_DOMAIN_NAME, n as Config, o as CHARTER_DOMAIN_VERSION, r as DEFAULT_CHARTER_CONFIG, s as charterDomainSpec, t as CharterService } from "./service-CPha5Ipx.js";
|
|
3
3
|
import "./core.js";
|
|
4
|
-
export { CHARTER_DOMAIN_NAME, CHARTER_DOMAIN_VERSION, CHARTER_PROMPT_PREFIX, CHARTER_RECORD_SCHEMA_VERSION, CharterError, CharterService, CharterService as default, Config, DEFAULT_CHARTER_CONFIG, 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, charterDomainSpec, 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 };
|
|
4
|
+
export { CHARTER_DOMAIN_NAME, CHARTER_DOMAIN_VERSION, CHARTER_PROMPT_PREFIX, CHARTER_RECORD_SCHEMA_VERSION, CharterError, CharterService, CharterService as default, Config, DEFAULT_CHARTER_CONFIG, 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, charterDomainSpec, 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 };
|
package/lib/remote/service.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Context } from '@deepseek-ai/cordis';
|
|
|
2
2
|
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
3
3
|
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
4
4
|
import type { CharterEditRequest, CharterInitializeRequest, CharterRestoreRequest } from '../core/schemas.js';
|
|
5
|
-
import type { CharterBootstrapResult, CharterEditResult, CharterRecordExport, CharterRecordOperationResult, CharterView, CharterSummary, CharterItemQueryResult, CharterProposalQueryResult, CharterChangeQueryResult, CharterChangeSetPreviewResult, CharterValidatorRequest, CharterValidatorRunResult, CharterSourceIntegrityResult, CharterMessageListResult, CharterArchiveListResult, CharterArchiveReadResult } from '../host/types.js';
|
|
5
|
+
import type { CharterBootstrapResult, CharterBootstrapDraftResult, CharterEditResult, CharterRecordExport, CharterRecordOperationResult, CharterView, CharterSummary, CharterItemQueryResult, CharterProposalQueryResult, CharterChangeQueryResult, CharterChangeSetPreviewResult, CharterValidatorRequest, CharterValidatorRunResult, CharterSourceIntegrityResult, CharterMessageListResult, CharterArchiveListResult, CharterArchiveReadResult } from '../host/types.js';
|
|
6
6
|
import type { CharterFrame } from './wire.js';
|
|
7
7
|
export declare class CharterRemoteService extends TypertRemoteService {
|
|
8
8
|
static inject: string[];
|
|
@@ -30,6 +30,11 @@ export declare class CharterRemoteService extends TypertRemoteService {
|
|
|
30
30
|
previewChangeSet(request: CharterEditRequest): Promise<CharterChangeSetPreviewResult>;
|
|
31
31
|
watch(sessionId: SessionId, signal: AbortSignal): AsyncIterable<CharterFrame>;
|
|
32
32
|
bootstrap(sessionId: SessionId): Promise<CharterBootstrapResult>;
|
|
33
|
+
bootstrapDraft(request: {
|
|
34
|
+
readonly sessionId: SessionId;
|
|
35
|
+
readonly targetLanguage?: 'zh' | 'en';
|
|
36
|
+
readonly awaitTranslation?: boolean;
|
|
37
|
+
}): Promise<CharterBootstrapDraftResult>;
|
|
33
38
|
edit(request: CharterEditRequest): Promise<CharterEditResult>;
|
|
34
39
|
applyBootstrap(request: CharterEditRequest): Promise<CharterEditResult>;
|
|
35
40
|
exportRecord(sessionId: SessionId): Promise<CharterRecordExport>;
|