dsh-charter 0.2.0 → 0.2.2
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 +61 -1
- package/CHANGELOG.zh.md +51 -1
- package/CONTRIBUTING.md +12 -2
- package/CONTRIBUTING.zh.md +9 -2
- package/README.md +50 -20
- package/README.zh.md +39 -17
- package/docs/README.md +7 -3
- package/docs/README.zh.md +5 -3
- package/docs/assets/charter-pane.zh.png +0 -0
- package/docs/design/charter-dependency-graph-v1.zh.md +1101 -0
- package/docs/design/charter-design-v1.md +7 -3
- package/docs/design/charter-design-v1.zh.md +14 -1
- package/docs/design/charter-workspace-v2.zh.md +20 -3
- package/docs/design/version-roadmap.md +9 -9
- package/docs/design/version-roadmap.zh.md +18 -14
- package/docs/release-notes/0.2.0.md +7 -7
- package/docs/release-notes/0.2.1.md +58 -0
- package/docs/release-notes/0.2.2.md +60 -0
- package/docs/release-notes/README.md +1 -2
- package/docs/releasing.md +12 -7
- package/docs/releasing.zh.md +10 -7
- package/docs/user-guide.md +48 -22
- package/docs/user-guide.zh.md +43 -18
- package/docs/verification.md +40 -28
- package/docs/verification.zh.md +31 -24
- package/lib/client/DependencyGraph.d.ts +19 -0
- package/lib/client/locales.d.ts +97 -19
- package/lib/client/relation-graph.d.ts +135 -0
- package/lib/client/store.d.ts +5 -0
- package/lib/client.js +2552 -496
- package/lib/core/change-set.d.ts +7 -0
- package/lib/core/dependencies.d.ts +29 -0
- package/lib/core.js +1 -1
- package/lib/{fork-D5HVDV1i.js → fork-KSL6sovw.js} +70 -1
- package/lib/host/domain.d.ts +50 -0
- package/lib/host/service.d.ts +18 -1
- package/lib/host/types.d.ts +37 -1
- package/lib/index.js +2 -2
- package/lib/remote/service.d.ts +8 -1
- package/lib/remote/wire.d.ts +161 -3
- package/lib/remote.js +155 -4
- package/lib/{service-C3A59BG5.js → service-MsIACddZ.js} +186 -5
- package/lib/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/remote.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as peerPrincipalRequired, i as resolveActor, l as remoteMethod } from "./service-
|
|
1
|
+
import { $ as charterItemSchema, Et as objectiveProposalSchema, J as charterChangeSchema, K as charterActorSchema, Ot as proposalCandidateRefSchema, Q as charterInitializeRequestSchema, Y as charterEditRequestSchema, at as charterRecordArchiveSchema, lt as charterRestoreRequestSchema, nn as CharterError, nt as charterObjectiveSchema, q as charterBootstrapApplyRequestSchema } from "./fork-KSL6sovw.js";
|
|
2
|
+
import { c as peerPrincipalRequired, i as resolveActor, l as remoteMethod } from "./service-MsIACddZ.js";
|
|
3
3
|
import "@deepseek-ai/cordis";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
@@ -164,6 +164,8 @@ let CharterRemoteService = (() => {
|
|
|
164
164
|
let _sourceIntegrity_decorators;
|
|
165
165
|
let _runValidators_decorators;
|
|
166
166
|
let _queryMessages_decorators;
|
|
167
|
+
let _listArchives_decorators;
|
|
168
|
+
let _readArchive_decorators;
|
|
167
169
|
let _proposeMessage_decorators;
|
|
168
170
|
let _previewChangeSet_decorators;
|
|
169
171
|
let _watch_decorators;
|
|
@@ -184,6 +186,8 @@ let CharterRemoteService = (() => {
|
|
|
184
186
|
_sourceIntegrity_decorators = [remoteMethod({ resources: { session: (sessionId) => sessionId } })];
|
|
185
187
|
_runValidators_decorators = [remoteMethod({ resources: { session: (request) => request.sessionId } })];
|
|
186
188
|
_queryMessages_decorators = [remoteMethod({ resources: { session: (sessionId) => sessionId } })];
|
|
189
|
+
_listArchives_decorators = [remoteMethod({ resources: { session: (request) => request.sessionId } })];
|
|
190
|
+
_readArchive_decorators = [remoteMethod({ resources: { session: (request) => request.sessionId } })];
|
|
187
191
|
_proposeMessage_decorators = [remoteMethod({ resources: { session: (request) => request.sessionId } })];
|
|
188
192
|
_previewChangeSet_decorators = [remoteMethod({ resources: { session: (request) => request.sessionId } })];
|
|
189
193
|
_watch_decorators = [remoteMethod({
|
|
@@ -237,6 +241,28 @@ let CharterRemoteService = (() => {
|
|
|
237
241
|
},
|
|
238
242
|
metadata: _metadata
|
|
239
243
|
}, null, _instanceExtraInitializers);
|
|
244
|
+
__esDecorate(this, null, _listArchives_decorators, {
|
|
245
|
+
kind: "method",
|
|
246
|
+
name: "listArchives",
|
|
247
|
+
static: false,
|
|
248
|
+
private: false,
|
|
249
|
+
access: {
|
|
250
|
+
has: (obj) => "listArchives" in obj,
|
|
251
|
+
get: (obj) => obj.listArchives
|
|
252
|
+
},
|
|
253
|
+
metadata: _metadata
|
|
254
|
+
}, null, _instanceExtraInitializers);
|
|
255
|
+
__esDecorate(this, null, _readArchive_decorators, {
|
|
256
|
+
kind: "method",
|
|
257
|
+
name: "readArchive",
|
|
258
|
+
static: false,
|
|
259
|
+
private: false,
|
|
260
|
+
access: {
|
|
261
|
+
has: (obj) => "readArchive" in obj,
|
|
262
|
+
get: (obj) => obj.readArchive
|
|
263
|
+
},
|
|
264
|
+
metadata: _metadata
|
|
265
|
+
}, null, _instanceExtraInitializers);
|
|
240
266
|
__esDecorate(this, null, _proposeMessage_decorators, {
|
|
241
267
|
kind: "method",
|
|
242
268
|
name: "proposeMessage",
|
|
@@ -434,6 +460,34 @@ let CharterRemoteService = (() => {
|
|
|
434
460
|
queryMessages(sessionId) {
|
|
435
461
|
return Promise.resolve(this.ctx.charter.messageCandidates(sessionId));
|
|
436
462
|
}
|
|
463
|
+
listArchives(request) {
|
|
464
|
+
let actor;
|
|
465
|
+
try {
|
|
466
|
+
actor = resolveRemoteActor(this.ctx);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (error instanceof CharterError) return Promise.resolve({
|
|
469
|
+
ok: false,
|
|
470
|
+
code: error.code,
|
|
471
|
+
message: error.message
|
|
472
|
+
});
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
return Promise.resolve(this.ctx.charter.listArchives(request.sessionId, actor));
|
|
476
|
+
}
|
|
477
|
+
readArchive(request) {
|
|
478
|
+
let actor;
|
|
479
|
+
try {
|
|
480
|
+
actor = resolveRemoteActor(this.ctx);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
if (error instanceof CharterError) return Promise.resolve({
|
|
483
|
+
ok: false,
|
|
484
|
+
code: error.code,
|
|
485
|
+
message: error.message
|
|
486
|
+
});
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
return Promise.resolve(this.ctx.charter.readArchive(request.sessionId, request.key, actor));
|
|
490
|
+
}
|
|
437
491
|
proposeMessage(request) {
|
|
438
492
|
let actor;
|
|
439
493
|
try {
|
|
@@ -987,6 +1041,8 @@ const charterMessageListSchema = z.discriminatedUnion("ok", [z.object({
|
|
|
987
1041
|
seq: z.number().int().nonnegative(),
|
|
988
1042
|
role: z.literal("user"),
|
|
989
1043
|
excerpt: z.string(),
|
|
1044
|
+
text: z.string().optional(),
|
|
1045
|
+
truncated: z.boolean().optional(),
|
|
990
1046
|
length: z.number().int().nonnegative()
|
|
991
1047
|
}).strict())
|
|
992
1048
|
}).strict(), z.object({
|
|
@@ -998,9 +1054,40 @@ const charterMessageProposeRequestSchema = z.object({
|
|
|
998
1054
|
sessionId: z.string().min(1),
|
|
999
1055
|
seq: z.number().int().nonnegative().optional(),
|
|
1000
1056
|
kind: z.enum(["invariant", "deliverable"]).optional(),
|
|
1057
|
+
text: z.string().max(65536).optional(),
|
|
1001
1058
|
start: z.number().int().nonnegative().optional(),
|
|
1002
1059
|
end: z.number().int().nonnegative().optional()
|
|
1003
1060
|
}).strict();
|
|
1061
|
+
const charterArchiveEntrySchema = z.object({
|
|
1062
|
+
key: z.string().min(1),
|
|
1063
|
+
revision: z.number().int().nonnegative(),
|
|
1064
|
+
archivedAt: z.number().int().nonnegative(),
|
|
1065
|
+
payloadDigest: z.string(),
|
|
1066
|
+
recordDigest: z.string(),
|
|
1067
|
+
lifecycle: z.string().nullable()
|
|
1068
|
+
}).strict();
|
|
1069
|
+
const charterArchiveListRequestSchema = z.object({ sessionId: z.string().min(1) }).strict();
|
|
1070
|
+
const charterArchiveReadRequestSchema = z.object({
|
|
1071
|
+
sessionId: z.string().min(1),
|
|
1072
|
+
key: z.string().min(1)
|
|
1073
|
+
}).strict();
|
|
1074
|
+
const charterArchiveListResultSchema = z.discriminatedUnion("ok", [z.object({
|
|
1075
|
+
ok: z.literal(true),
|
|
1076
|
+
archives: z.array(charterArchiveEntrySchema),
|
|
1077
|
+
limit: z.number().int().positive()
|
|
1078
|
+
}).strict(), z.object({
|
|
1079
|
+
ok: z.literal(false),
|
|
1080
|
+
code: charterErrorCodeSchema,
|
|
1081
|
+
message: z.string()
|
|
1082
|
+
}).strict()]);
|
|
1083
|
+
const charterArchiveReadResultSchema = z.discriminatedUnion("ok", [z.object({
|
|
1084
|
+
ok: z.literal(true),
|
|
1085
|
+
archive: charterRecordArchiveSchema
|
|
1086
|
+
}).strict(), z.object({
|
|
1087
|
+
ok: z.literal(false),
|
|
1088
|
+
code: charterErrorCodeSchema,
|
|
1089
|
+
message: z.string()
|
|
1090
|
+
}).strict()]);
|
|
1004
1091
|
const charterSourceIntegrityResultSchema = z.discriminatedUnion("ok", [z.object({
|
|
1005
1092
|
ok: z.literal(true),
|
|
1006
1093
|
revision: z.number().int().nonnegative(),
|
|
@@ -1054,6 +1141,22 @@ const charterValidatorRunResultSchema = z.discriminatedUnion("ok", [z.object({
|
|
|
1054
1141
|
code: charterErrorCodeSchema,
|
|
1055
1142
|
message: z.string()
|
|
1056
1143
|
}).strict()]);
|
|
1144
|
+
const charterDependencyConflictRefSchema = z.object({
|
|
1145
|
+
itemId: z.string(),
|
|
1146
|
+
before: z.enum([
|
|
1147
|
+
"satisfied",
|
|
1148
|
+
"waiting",
|
|
1149
|
+
"dependency-conflict",
|
|
1150
|
+
"absent"
|
|
1151
|
+
]),
|
|
1152
|
+
after: z.enum([
|
|
1153
|
+
"satisfied",
|
|
1154
|
+
"waiting",
|
|
1155
|
+
"dependency-conflict"
|
|
1156
|
+
]),
|
|
1157
|
+
beforeConflicts: z.number().int().nonnegative(),
|
|
1158
|
+
afterConflicts: z.number().int().nonnegative()
|
|
1159
|
+
}).strict();
|
|
1057
1160
|
const charterChangeSetPreviewResultSchema = z.discriminatedUnion("ok", [z.object({
|
|
1058
1161
|
ok: z.literal(true),
|
|
1059
1162
|
previewDigest: z.string(),
|
|
@@ -1071,7 +1174,11 @@ const charterChangeSetPreviewResultSchema = z.discriminatedUnion("ok", [z.object
|
|
|
1071
1174
|
}).strict(),
|
|
1072
1175
|
changes: z.array(charterChangeSchema),
|
|
1073
1176
|
promptChanged: z.boolean(),
|
|
1074
|
-
metadataOnly: z.boolean()
|
|
1177
|
+
metadataOnly: z.boolean(),
|
|
1178
|
+
dependencyConflicts: z.object({
|
|
1179
|
+
added: z.array(charterDependencyConflictRefSchema),
|
|
1180
|
+
worsened: z.array(charterDependencyConflictRefSchema)
|
|
1181
|
+
}).strict().optional()
|
|
1075
1182
|
}).strict(), z.object({
|
|
1076
1183
|
ok: z.literal(false),
|
|
1077
1184
|
code: charterErrorCodeSchema,
|
|
@@ -1335,6 +1442,50 @@ const charterRemoteContribution = {
|
|
|
1335
1442
|
create: () => charterMessageListSchema
|
|
1336
1443
|
}
|
|
1337
1444
|
},
|
|
1445
|
+
{
|
|
1446
|
+
id: "dsh-charter#charter/listArchives",
|
|
1447
|
+
service: "charterRemote",
|
|
1448
|
+
namespace: "charter",
|
|
1449
|
+
method: "listArchives",
|
|
1450
|
+
invocation: { kind: "direct" },
|
|
1451
|
+
parameters: [{
|
|
1452
|
+
name: "request",
|
|
1453
|
+
wire: "request",
|
|
1454
|
+
source: "json",
|
|
1455
|
+
codec: {
|
|
1456
|
+
mode: "strict",
|
|
1457
|
+
typeSymbol: "dsh-charter/CharterArchiveListRequest",
|
|
1458
|
+
create: () => charterArchiveListRequestSchema
|
|
1459
|
+
}
|
|
1460
|
+
}],
|
|
1461
|
+
result: {
|
|
1462
|
+
mode: "strict",
|
|
1463
|
+
typeSymbol: "dsh-charter/CharterArchiveListResult",
|
|
1464
|
+
create: () => charterArchiveListResultSchema
|
|
1465
|
+
}
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
id: "dsh-charter#charter/readArchive",
|
|
1469
|
+
service: "charterRemote",
|
|
1470
|
+
namespace: "charter",
|
|
1471
|
+
method: "readArchive",
|
|
1472
|
+
invocation: { kind: "direct" },
|
|
1473
|
+
parameters: [{
|
|
1474
|
+
name: "request",
|
|
1475
|
+
wire: "request",
|
|
1476
|
+
source: "json",
|
|
1477
|
+
codec: {
|
|
1478
|
+
mode: "strict",
|
|
1479
|
+
typeSymbol: "dsh-charter/CharterArchiveReadRequest",
|
|
1480
|
+
create: () => charterArchiveReadRequestSchema
|
|
1481
|
+
}
|
|
1482
|
+
}],
|
|
1483
|
+
result: {
|
|
1484
|
+
mode: "strict",
|
|
1485
|
+
typeSymbol: "dsh-charter/CharterArchiveReadResult",
|
|
1486
|
+
create: () => charterArchiveReadResultSchema
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1338
1489
|
{
|
|
1339
1490
|
id: "dsh-charter#charter/proposeMessage",
|
|
1340
1491
|
service: "charterRemote",
|
|
@@ -1567,4 +1718,4 @@ const charterRemoteContribution = {
|
|
|
1567
1718
|
]
|
|
1568
1719
|
};
|
|
1569
1720
|
//#endregion
|
|
1570
|
-
export { CharterRemoteService, CharterRemoteService as default, charterBootstrapApplyRequestSchema, charterBootstrapProposalSchema, charterBootstrapResultSchema, charterChangeQueryRequestSchema, charterChangeQueryResultSchema, charterChangeSetPreviewResultSchema, charterEditRequestSchema, charterEditResultSchema, charterErrorCodeSchema, charterFrameSchema, charterInitializeRequestWireSchema, charterItemQueryRequestSchema, charterItemQueryResultSchema, charterMessageListSchema, charterMessageProposeRequestSchema, charterProposalQueryRequestSchema, charterProposalQueryResultSchema, charterRecordExportSchema, charterRecordOperationResultSchema, charterRecordStateSchema, charterRemoteContribution, charterRestoreRequestWireSchema, charterSourceIntegrityResultSchema, charterSummaryFrameSchema, charterSummarySchema, charterValidatorRunRequestSchema, charterValidatorRunResultSchema, charterViewCapabilitiesSchema, charterViewSchema };
|
|
1721
|
+
export { CharterRemoteService, CharterRemoteService as default, charterArchiveEntrySchema, charterArchiveListRequestSchema, charterArchiveListResultSchema, charterArchiveReadRequestSchema, charterArchiveReadResultSchema, charterBootstrapApplyRequestSchema, charterBootstrapProposalSchema, charterBootstrapResultSchema, charterChangeQueryRequestSchema, charterChangeQueryResultSchema, charterChangeSetPreviewResultSchema, charterEditRequestSchema, charterEditResultSchema, charterErrorCodeSchema, charterFrameSchema, charterInitializeRequestWireSchema, charterItemQueryRequestSchema, charterItemQueryResultSchema, charterMessageListSchema, charterMessageProposeRequestSchema, charterProposalQueryRequestSchema, charterProposalQueryResultSchema, charterRecordExportSchema, charterRecordOperationResultSchema, charterRecordStateSchema, charterRemoteContribution, charterRestoreRequestWireSchema, charterSourceIntegrityResultSchema, charterSummaryFrameSchema, charterSummarySchema, charterValidatorRunRequestSchema, charterValidatorRunResultSchema, charterViewCapabilitiesSchema, charterViewSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as compactionProjectionDigest, B as
|
|
1
|
+
import { $t as recordMaintenanceAvailable, A as compactionProjectionDigest, B as dependencyProjection, Bt as sha256Json, C as buildRecordArchive, D as validateArchiveEnvelope, E as recordDigestOf, Gt as DEFAULT_CHARTER_LIMITS, Ht as assertEditAuthorized, It as compareOrderedItems, M as verifySourceProjection, N as applyOps, Q as charterInitializeRequestSchema, S as assertRestorableArchive, U as normalizeEditRequest, Ut as bootstrapFromEvents, V as clientRefsOf, Vt as sha256Text, Z as charterIdentitySchema, Zt as clampCharterLimits, _ as migrateRecordV1ToV2, a as appendMaintenanceReceipt, at as charterRecordArchiveSchema, b as assertArchiveAdmission, c as assertRecoveryRecordAdmission, ct as charterRecordV1Schema, d as createEmptyRecord, g as maintenanceRequestDigestOf, h as legacyValidityFor, i as RevisionConflict, j as messageProjectionDigest, k as agentProjectionDigest, lt as charterRestoreRequestSchema, m as isRecordOverBudget, nn as CharterError, q as charterBootstrapApplyRequestSchema, r as MutationReplay, rn as charterError, s as assertRecordConsistency, st as charterRecordSchema, t as forkRecord, u as commitRecord, v as requestDigestOf, x as assertRecoveryRequestAdmission, y as restoredRecord, z as dependencyConflictDiff, zt as isStandingItem } from "./fork-KSL6sovw.js";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { Service } from "@deepseek-ai/cordis";
|
|
4
4
|
import Schema from "@deepseek-ai/schemastery";
|
|
@@ -147,6 +147,7 @@ function planChangeSet(input) {
|
|
|
147
147
|
const after = side(applied.snapshot);
|
|
148
148
|
const promptChanged = applied.snapshot.promptText !== input.snapshot.promptText;
|
|
149
149
|
const metadataOnly = applied.changes.every((change) => change.type === "item.accepted" || change.type === "item.rejected" || change.type === "item.archived" || change.type === "item.restored" || change.type === "item.superseded" || change.type === "item.purged" || change.type === "item.verification.changed") && !promptChanged;
|
|
150
|
+
const dependencyConflicts = dependencyConflictDiff(input.snapshot.items, applied.snapshot.items);
|
|
150
151
|
const summaryDigest = sha256Json({
|
|
151
152
|
version: 1,
|
|
152
153
|
baseRevision: input.snapshot.revision,
|
|
@@ -169,7 +170,8 @@ function planChangeSet(input) {
|
|
|
169
170
|
changes: [...applied.changes],
|
|
170
171
|
summaryDigest,
|
|
171
172
|
promptChanged,
|
|
172
|
-
metadataOnly
|
|
173
|
+
metadataOnly,
|
|
174
|
+
dependencyConflicts
|
|
173
175
|
};
|
|
174
176
|
}
|
|
175
177
|
/** Digest of the reviewed request, bound to the authoritative snapshot. */
|
|
@@ -477,6 +479,23 @@ const charterDomainSpec = defineDomain({
|
|
|
477
479
|
layout: "per-record",
|
|
478
480
|
tables: { sessions: domainTable(z.unknown()) }
|
|
479
481
|
});
|
|
482
|
+
const CHARTER_ARCHIVES_DOMAIN_NAME = "dsh_charter_archives_v1";
|
|
483
|
+
const CHARTER_ARCHIVES_TABLE = "archives";
|
|
484
|
+
const charterArchivesDomainSpec = defineDomain({
|
|
485
|
+
name: CHARTER_ARCHIVES_DOMAIN_NAME,
|
|
486
|
+
version: 1,
|
|
487
|
+
layout: "per-record",
|
|
488
|
+
tables: { archives: domainTable(z.object({
|
|
489
|
+
key: z.string().min(1),
|
|
490
|
+
sessionId: z.string().min(1).max(256),
|
|
491
|
+
revision: z.number().int().nonnegative(),
|
|
492
|
+
archivedAt: z.number().int().nonnegative(),
|
|
493
|
+
archive: charterRecordArchiveSchema
|
|
494
|
+
}).strict()) }
|
|
495
|
+
});
|
|
496
|
+
function archiveCacheKey(sessionId, revision) {
|
|
497
|
+
return `${sessionId}--r${revision}`;
|
|
498
|
+
}
|
|
480
499
|
//#endregion
|
|
481
500
|
//#region .build-ts/host/tool.js
|
|
482
501
|
function defineCharterReadTool(charter) {
|
|
@@ -742,6 +761,10 @@ var CharterService = class extends Service {
|
|
|
742
761
|
static Config = Config;
|
|
743
762
|
config;
|
|
744
763
|
sessionsTable;
|
|
764
|
+
archivesTable;
|
|
765
|
+
archivesDomain;
|
|
766
|
+
/** Captures awaiting their durable put; visible to list/read immediately. */
|
|
767
|
+
pendingArchives = /* @__PURE__ */ new Map();
|
|
745
768
|
globalFailure;
|
|
746
769
|
admissionOpen = true;
|
|
747
770
|
unavailable = /* @__PURE__ */ new Map();
|
|
@@ -1008,6 +1031,13 @@ var CharterService = class extends Service {
|
|
|
1008
1031
|
const domain = await this.ctx.storageDomain.open(charterDomainSpec);
|
|
1009
1032
|
const rawTable = domain.table(CHARTER_SESSIONS_TABLE);
|
|
1010
1033
|
this.sessionsTable = rawTable;
|
|
1034
|
+
try {
|
|
1035
|
+
const archives = await this.ctx.storageDomain.open(charterArchivesDomainSpec);
|
|
1036
|
+
this.archivesDomain = archives;
|
|
1037
|
+
this.archivesTable = archives.table(CHARTER_ARCHIVES_TABLE);
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
this.ctx.logger.warn(`charter: archive cache is unavailable: ${describeError(error)}`);
|
|
1040
|
+
}
|
|
1011
1041
|
for (const [id, stored] of rawTable.entries()) {
|
|
1012
1042
|
let parsed = charterRecordSchema.safeParse(stored);
|
|
1013
1043
|
if (!parsed.success) {
|
|
@@ -1047,7 +1077,11 @@ var CharterService = class extends Service {
|
|
|
1047
1077
|
}
|
|
1048
1078
|
this.mutationQueues.clear();
|
|
1049
1079
|
for (const sessionId of [...this.listeners.keys()]) this.closeListeners(sessionId);
|
|
1080
|
+
const archivesDomain = this.archivesDomain;
|
|
1081
|
+
this.archivesTable = void 0;
|
|
1082
|
+
this.archivesDomain = void 0;
|
|
1050
1083
|
await domain.close();
|
|
1084
|
+
await archivesDomain?.close();
|
|
1051
1085
|
this.sessionsTable = void 0;
|
|
1052
1086
|
}, "charter.domain");
|
|
1053
1087
|
} catch (error) {
|
|
@@ -1139,6 +1173,7 @@ var CharterService = class extends Service {
|
|
|
1139
1173
|
this.recordStates.set(session.id, inspection.state);
|
|
1140
1174
|
if (inspection.state.kind === "healthy") this.unavailable.delete(session.id);
|
|
1141
1175
|
this.publish(session.id);
|
|
1176
|
+
if (inspection.state.kind === "healthy" && inspection.record !== void 0) this.captureArchive(session, inspection.record);
|
|
1142
1177
|
if (inspection.state.kind !== "healthy") return;
|
|
1143
1178
|
}
|
|
1144
1179
|
if (session.header.parentSession !== void 0) {
|
|
@@ -1215,6 +1250,7 @@ var CharterService = class extends Service {
|
|
|
1215
1250
|
recordDigest: recordDigestOf(record)
|
|
1216
1251
|
});
|
|
1217
1252
|
this.publish(session.id);
|
|
1253
|
+
this.captureArchive(session, record);
|
|
1218
1254
|
});
|
|
1219
1255
|
} catch (error) {
|
|
1220
1256
|
if (putMayHaveLanded && !(error instanceof DomainError && (error.code === "closed" || error.code === "missing-key"))) {
|
|
@@ -2105,7 +2141,8 @@ var CharterService = class extends Service {
|
|
|
2105
2141
|
after: planned.after,
|
|
2106
2142
|
changes: [...planned.changes],
|
|
2107
2143
|
promptChanged: planned.promptChanged,
|
|
2108
|
-
metadataOnly: planned.metadataOnly
|
|
2144
|
+
metadataOnly: planned.metadataOnly,
|
|
2145
|
+
dependencyConflicts: planned.dependencyConflicts
|
|
2109
2146
|
};
|
|
2110
2147
|
} catch (error) {
|
|
2111
2148
|
return {
|
|
@@ -2315,10 +2352,14 @@ var CharterService = class extends Service {
|
|
|
2315
2352
|
if (data.source?.kind !== "user") continue;
|
|
2316
2353
|
const text = (data.content ?? []).filter((block) => block.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
|
|
2317
2354
|
if (text.length === 0) continue;
|
|
2355
|
+
const messageProjectionLimit = 8192;
|
|
2356
|
+
const clipped = text.length > messageProjectionLimit;
|
|
2318
2357
|
messages.push({
|
|
2319
2358
|
seq: event.seq,
|
|
2320
2359
|
role: "user",
|
|
2321
2360
|
excerpt: text.length > 160 ? `${text.slice(0, 157)}...` : text,
|
|
2361
|
+
text: clipped ? text.slice(0, messageProjectionLimit) : text,
|
|
2362
|
+
...clipped ? { truncated: true } : {},
|
|
2322
2363
|
length: text.length
|
|
2323
2364
|
});
|
|
2324
2365
|
}
|
|
@@ -2350,15 +2391,24 @@ var CharterService = class extends Service {
|
|
|
2350
2391
|
const start = options.start ?? 0;
|
|
2351
2392
|
const end = options.end ?? selected.text.length;
|
|
2352
2393
|
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start || end > selected.text.length) return unavailableResult("INVALID_ARGUMENT", "message selection is outside the selected message");
|
|
2353
|
-
const
|
|
2394
|
+
const selectedText = selected.text.slice(start, end).trim();
|
|
2395
|
+
const override = options.text === void 0 ? void 0 : options.text.trim();
|
|
2396
|
+
const text = override ?? selectedText;
|
|
2354
2397
|
if (text.length === 0) return unavailableResult("INVALID_ARGUMENT", "message selection is empty");
|
|
2398
|
+
const edited = override !== void 0 && override !== selectedText;
|
|
2355
2399
|
const view = this.view(session);
|
|
2356
2400
|
if (view.status !== "ready") return unavailableResult("UNAVAILABLE", "Charter is not editable in its current state");
|
|
2357
2401
|
const selection = start === 0 && end === selected.text.length ? void 0 : {
|
|
2358
2402
|
start: selected.leading + start,
|
|
2359
2403
|
end: selected.leading + end
|
|
2360
2404
|
};
|
|
2361
|
-
const
|
|
2405
|
+
const manualActor = actor.kind === "owner" ? "owner" : actor.kind === "user" ? "user" : void 0;
|
|
2406
|
+
if (edited && manualActor === void 0) return unavailableResult("FORBIDDEN", "Only the owner or a user may create an edited proposal");
|
|
2407
|
+
const source = edited ? {
|
|
2408
|
+
kind: "manual",
|
|
2409
|
+
actor: manualActor,
|
|
2410
|
+
at: Date.now()
|
|
2411
|
+
} : {
|
|
2362
2412
|
kind: "message",
|
|
2363
2413
|
sessionId: session.id,
|
|
2364
2414
|
sessionCreatedAt: identityOf(session).createdAt,
|
|
@@ -2585,6 +2635,7 @@ var CharterService = class extends Service {
|
|
|
2585
2635
|
recordDigest: recordDigestOf(table.get(session.id))
|
|
2586
2636
|
});
|
|
2587
2637
|
this.publish(session.id);
|
|
2638
|
+
this.captureArchive(session, next);
|
|
2588
2639
|
return {
|
|
2589
2640
|
ok: true,
|
|
2590
2641
|
replayed: false,
|
|
@@ -2682,6 +2733,133 @@ var CharterService = class extends Service {
|
|
|
2682
2733
|
};
|
|
2683
2734
|
}
|
|
2684
2735
|
/** Export the complete raw record for one Session (owner-only). */
|
|
2736
|
+
/**
|
|
2737
|
+
* Bounded cache policy: at most five snapshots per Session and at most
|
|
2738
|
+
* `CHARTER_ARCHIVE_TOTAL_LIMIT` across all Sessions. Oldest snapshots are
|
|
2739
|
+
* evicted first; this is a derivative cache, never the authoritative record.
|
|
2740
|
+
*/
|
|
2741
|
+
async pruneArchiveCache() {
|
|
2742
|
+
const table = this.archivesTable;
|
|
2743
|
+
if (table === void 0) return;
|
|
2744
|
+
const ordered = [...new Map([...[...table.entries()], ...[...this.pendingArchives.entries()]]).entries()].sort((left, right) => right[1].archivedAt - left[1].archivedAt || right[1].revision - left[1].revision);
|
|
2745
|
+
const perSession = /* @__PURE__ */ new Map();
|
|
2746
|
+
let total = 0;
|
|
2747
|
+
for (const [key, entry] of ordered) {
|
|
2748
|
+
const count = perSession.get(entry.sessionId) ?? 0;
|
|
2749
|
+
if (count >= 5 || total >= 25) {
|
|
2750
|
+
if (this.pendingArchives.get(key) === entry) this.pendingArchives.delete(key);
|
|
2751
|
+
else await table.delete(key);
|
|
2752
|
+
continue;
|
|
2753
|
+
}
|
|
2754
|
+
perSession.set(entry.sessionId, count + 1);
|
|
2755
|
+
total += 1;
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Best-effort bounded archive cache. It stores the exact record envelope at
|
|
2760
|
+
* each successful revision so recovery does not depend on a downloaded file.
|
|
2761
|
+
*/
|
|
2762
|
+
async captureArchive(session, record) {
|
|
2763
|
+
const table = this.archivesTable;
|
|
2764
|
+
if (table === void 0) return;
|
|
2765
|
+
if (!this.recordMaintenanceCapability().recordMaintenance) return;
|
|
2766
|
+
try {
|
|
2767
|
+
const archive = buildRecordArchive({
|
|
2768
|
+
sessionId: session.id,
|
|
2769
|
+
lifecycle: lifecycleFingerprint(identityOf(session)),
|
|
2770
|
+
health: "healthy",
|
|
2771
|
+
revision: record.current.revision,
|
|
2772
|
+
record,
|
|
2773
|
+
exportedAt: Date.now()
|
|
2774
|
+
});
|
|
2775
|
+
assertArchiveAdmission(archive, this.config);
|
|
2776
|
+
const key = archiveCacheKey(session.id, record.current.revision);
|
|
2777
|
+
const entry = {
|
|
2778
|
+
key,
|
|
2779
|
+
sessionId: session.id,
|
|
2780
|
+
revision: record.current.revision,
|
|
2781
|
+
archivedAt: archive.exportedAt,
|
|
2782
|
+
archive
|
|
2783
|
+
};
|
|
2784
|
+
this.pendingArchives.set(key, entry);
|
|
2785
|
+
try {
|
|
2786
|
+
await this.pruneArchiveCache();
|
|
2787
|
+
if (this.pendingArchives.get(key) !== entry) return;
|
|
2788
|
+
await table.put(key, entry);
|
|
2789
|
+
await this.pruneArchiveCache();
|
|
2790
|
+
} finally {
|
|
2791
|
+
this.pendingArchives.delete(key);
|
|
2792
|
+
}
|
|
2793
|
+
} catch (error) {
|
|
2794
|
+
this.ctx.logger.warn(`charter: could not cache archive for ${session.id}: ${describeError(error)}`);
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
listArchives(sessionId, actor) {
|
|
2798
|
+
const gate = this.maintenanceGate(actor);
|
|
2799
|
+
if (!gate.ok) return {
|
|
2800
|
+
ok: false,
|
|
2801
|
+
code: gate.code,
|
|
2802
|
+
message: gate.message
|
|
2803
|
+
};
|
|
2804
|
+
if (this.ctx.sessions.get(sessionId) === void 0) return {
|
|
2805
|
+
ok: false,
|
|
2806
|
+
code: "NOT_FOUND",
|
|
2807
|
+
message: "The Session is not live"
|
|
2808
|
+
};
|
|
2809
|
+
const table = this.archivesTable;
|
|
2810
|
+
if (table === void 0) return {
|
|
2811
|
+
ok: false,
|
|
2812
|
+
code: "UNAVAILABLE",
|
|
2813
|
+
message: "The archive cache is unavailable"
|
|
2814
|
+
};
|
|
2815
|
+
const prefix = `${sessionId}--r`;
|
|
2816
|
+
return {
|
|
2817
|
+
ok: true,
|
|
2818
|
+
archives: [...new Map([...[...table.entries()].filter(([key]) => key.startsWith(prefix)), ...[...this.pendingArchives.entries()].filter(([key]) => key.startsWith(prefix))]).values()].map((entry) => ({
|
|
2819
|
+
key: entry.key,
|
|
2820
|
+
revision: entry.revision,
|
|
2821
|
+
archivedAt: entry.archivedAt,
|
|
2822
|
+
payloadDigest: entry.archive.payloadDigest,
|
|
2823
|
+
recordDigest: entry.archive.source.recordDigest,
|
|
2824
|
+
lifecycle: entry.archive.source.lifecycle
|
|
2825
|
+
})).sort((left, right) => right.archivedAt - left.archivedAt || right.revision - left.revision).slice(0, 5),
|
|
2826
|
+
limit: 5
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
readArchive(sessionId, key, actor) {
|
|
2830
|
+
const gate = this.maintenanceGate(actor);
|
|
2831
|
+
if (!gate.ok) return {
|
|
2832
|
+
ok: false,
|
|
2833
|
+
code: gate.code,
|
|
2834
|
+
message: gate.message
|
|
2835
|
+
};
|
|
2836
|
+
if (this.ctx.sessions.get(sessionId) === void 0) return {
|
|
2837
|
+
ok: false,
|
|
2838
|
+
code: "NOT_FOUND",
|
|
2839
|
+
message: "The Session is not live"
|
|
2840
|
+
};
|
|
2841
|
+
const table = this.archivesTable;
|
|
2842
|
+
if (table === void 0) return {
|
|
2843
|
+
ok: false,
|
|
2844
|
+
code: "UNAVAILABLE",
|
|
2845
|
+
message: "The archive cache is unavailable"
|
|
2846
|
+
};
|
|
2847
|
+
if (!key.startsWith(`${sessionId}--r`)) return {
|
|
2848
|
+
ok: false,
|
|
2849
|
+
code: "NOT_FOUND",
|
|
2850
|
+
message: "The archive does not belong to this Session"
|
|
2851
|
+
};
|
|
2852
|
+
const entry = table.get(key) ?? this.pendingArchives.get(key);
|
|
2853
|
+
if (entry === void 0) return {
|
|
2854
|
+
ok: false,
|
|
2855
|
+
code: "NOT_FOUND",
|
|
2856
|
+
message: "The archive is no longer cached"
|
|
2857
|
+
};
|
|
2858
|
+
return {
|
|
2859
|
+
ok: true,
|
|
2860
|
+
archive: entry.archive
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2685
2863
|
exportRecord(sessionId, actor = { kind: "owner" }) {
|
|
2686
2864
|
const gate = this.maintenanceGate(actor);
|
|
2687
2865
|
if (!gate.ok) return {
|
|
@@ -2733,6 +2911,7 @@ var CharterService = class extends Service {
|
|
|
2733
2911
|
};
|
|
2734
2912
|
throw error;
|
|
2735
2913
|
}
|
|
2914
|
+
if (inspection.state.kind === "healthy" && inspection.record !== void 0) this.captureArchive(session, inspection.record);
|
|
2736
2915
|
return {
|
|
2737
2916
|
ok: true,
|
|
2738
2917
|
filename: `dsh-charter-${String(sessionId).replace(/[^A-Za-z0-9._-]+/gu, "-")}-r${inspection.record?.current.revision ?? 0}-${Date.now()}.json`,
|
|
@@ -2844,6 +3023,7 @@ var CharterService = class extends Service {
|
|
|
2844
3023
|
recordDigest: recordDigestOf(next)
|
|
2845
3024
|
});
|
|
2846
3025
|
this.publish(session.id);
|
|
3026
|
+
await this.captureArchive(session, next);
|
|
2847
3027
|
return this.maintenanceResult(session, false);
|
|
2848
3028
|
} catch (error) {
|
|
2849
3029
|
if (error instanceof CharterError) return {
|
|
@@ -3052,6 +3232,7 @@ var CharterService = class extends Service {
|
|
|
3052
3232
|
recordDigest: recordDigestOf(next)
|
|
3053
3233
|
});
|
|
3054
3234
|
this.publish(session.id);
|
|
3235
|
+
await this.captureArchive(session, next);
|
|
3055
3236
|
return this.maintenanceResult(session, false);
|
|
3056
3237
|
} catch (error) {
|
|
3057
3238
|
if (error instanceof CharterError) return {
|
package/lib/version.d.ts
CHANGED