dsh-manage-session 0.3.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import z from "@deepseek-ai/schemastery";
1
2
  //#region node_modules/cosmokit/lib/index.d.ts
2
3
  type Dict<T = any, K extends string | symbol = string> = { [key in K]: T; };
3
4
  type Promisify<T> = Promise<T extends Promise<infer S> ? S : T>;
@@ -734,7 +735,7 @@ interface GateAttribution {
734
735
  }
735
736
  /** 一个 gate 的结果。 */
736
737
  interface GateResult {
737
- id: 'generation' | 'log-integrity' | 'projection-cache' | 'lossless-json' | 'cold-read';
738
+ id: 'generation' | 'log-integrity' | 'projection-cache' | 'lossless-json' | 'cold-read' | 'source-kind';
738
739
  level: GateLevel;
739
740
  evidence: string;
740
741
  attribution?: GateAttribution;
@@ -883,6 +884,8 @@ interface StewardHistoryRow {
883
884
  bytes: number;
884
885
  /** 投影缓存占用字节数。 */
885
886
  cacheBytes: number;
887
+ /** 署名转换备份(`*.pre-sourcemigrate-<ts>`)占用字节数——`bytes` 的子集,单列防误读为日志体积。 */
888
+ backupBytes: number;
886
889
  }
887
890
  /** 列表结果。 */
888
891
  interface StewardHistoryListResult {
@@ -944,13 +947,30 @@ interface StewardSessionUsage {
944
947
  sessionId: string;
945
948
  /** 转录目录绝对路径(不存在时缺省)。 */
946
949
  dir?: string;
947
- /** 转录目录占用字节数。 */
950
+ /** 转录目录占用字节数(**含**署名转换备份;备份单列在 `backupBytes`)。 */
948
951
  bytes: number;
952
+ /**
953
+ * 署名转换备份(`*.pre-sourcemigrate-<ts>`,见 `SOURCE_MIGRATE_BACKUP_SUFFIX`)
954
+ * 占用字节数 —— 是 `bytes` 的子集,单列出来免得被当作日志体积误读。
955
+ */
956
+ backupBytes: number;
957
+ /** 备份文件个数。 */
958
+ backupCount: number;
949
959
  /** 投影缓存文件绝对路径(不存在时缺省)。 */
950
960
  cacheFile?: string;
951
961
  /** 投影缓存占用字节数。 */
952
962
  cacheBytes: number;
953
963
  }
964
+ /** 是否署名转换备份文件(`*.pre-sourcemigrate-<ts>`)。 */
965
+ declare function isSourceMigrateBackupName(name: string): boolean;
966
+ /**
967
+ * 列出一个转录目录里的署名转换备份(只扫顶层:备份与日志同目录落盘)。
968
+ * @returns 备份绝对路径与合计字节数;目录不存在时为空。
969
+ */
970
+ declare function backupFilesIn(dir: string): {
971
+ files: string[];
972
+ bytes: number;
973
+ };
954
974
  /** 转录根目录(`<dshHome>/sessions`)。 */
955
975
  declare function sessionsRootFor(dshHome: string): string;
956
976
  /**
@@ -996,8 +1016,10 @@ interface StewardHistoryPurgeResult {
996
1016
  ok: boolean;
997
1017
  /** 成功清理的会话数。 */
998
1018
  purged?: number;
999
- /** 释放的字节数(转录 + 投影缓存)。 */
1019
+ /** 释放的字节数(转录 + 投影缓存;含随目录删除的署名转换备份)。 */
1000
1020
  freedBytes?: number;
1021
+ /** 一并删除的署名转换备份(`*.pre-sourcemigrate-<ts>`)个数。 */
1022
+ backupsRemoved?: number;
1001
1023
  /** 逐条失败原因;不阻断其余条目。 */
1002
1024
  failures?: {
1003
1025
  sessionId: string;
@@ -1022,6 +1044,88 @@ interface StewardPurgeOptions {
1022
1044
  */
1023
1045
  declare function purgeHistory(payload: unknown, log?: (msg: string) => void, options?: StewardPurgeOptions): StewardHistoryPurgeResult;
1024
1046
  //#endregion
1047
+ //#region src/host/health/source-kind.d.ts
1048
+ /** v4 线起点的宿主版本(会话格式 v4 引入 producer-owned source kind)。 */
1049
+ declare const V4_HOST_MIN = "0.1.7-rc.1";
1050
+ /** 一份日志里的旧署名事实。 */
1051
+ interface SourceKindFacts {
1052
+ /** 旧署名事件总数。 */
1053
+ legacyCount: number;
1054
+ /** 按生产者插件名统计。 */
1055
+ byPlugin: Record<string, number>;
1056
+ /** 命中样例(seq + 插件名),最多 5 条,供证据展示。 */
1057
+ examples: {
1058
+ seq: number;
1059
+ plugin: string;
1060
+ }[];
1061
+ /** 日志 header 的格式代次(无从读取时 undefined)。 */
1062
+ headerVersion?: number;
1063
+ }
1064
+ /** 从解码后的日志提取旧署名事实(只读)。 */
1065
+ declare function readSourceKindFacts(log: SessionLogRead): SourceKindFacts;
1066
+ /**
1067
+ * gate 5:插件署名格式(v4 线要求 producer-owned kind)。
1068
+ *
1069
+ * 档位判据(有据才抬档):
1070
+ * - header.version ≥ 4 且观测到旧署名行 → `warn`:v4 校验拒绝这种署名;存量行让
1071
+ * 未适配插件的读回判断(`kind === 'plugin' && plugin === name`)失配,转换可消除;
1072
+ * - header.version < 4 → `ok`:v3 及更早线旧行合法,宿主迁移负责,**不动**(防过度操作);
1073
+ * - header.version 无从读取 → `skipped`:无从判定该走哪条版本线。
1074
+ * @param facts - 旧署名事实;undefined 表示未提供(无日志)。
1075
+ */
1076
+ declare function gateSourceKind(facts: SourceKindFacts | undefined): {
1077
+ id: 'source-kind';
1078
+ level: GateLevel;
1079
+ evidence: string;
1080
+ detail?: Record<string, unknown>;
1081
+ };
1082
+ /** 转换结果。 */
1083
+ interface SourceKindMigrationOutcome {
1084
+ ok: boolean;
1085
+ sessionId: string;
1086
+ /** 被改写的日志路径。 */
1087
+ path: string;
1088
+ /** 备份路径(改写前的完整副本;ok 且 changed 时必有)。 */
1089
+ backup?: string;
1090
+ /** 改写的行数。 */
1091
+ changedRows?: number;
1092
+ /** 按生产者插件名统计的改写行数。 */
1093
+ byPlugin?: Record<string, number>;
1094
+ /**
1095
+ * 按生产者名统计的**跳过**行数(第一方名,宿主迁移职权,见
1096
+ * `isFirstPartyLegacyProducer`)。跳过是如实上报,不是静默丢弃。
1097
+ */
1098
+ skippedFirstParty?: Record<string, number>;
1099
+ error?: string;
1100
+ }
1101
+ /**
1102
+ * 从旧署名对象构造新署名:`{ kind: 'plugin', plugin: name, …rest }` → `{ kind: 'plugin:name', …rest }`。
1103
+ * 非 legacy(缺 plugin 字段 / kind 不符)返回 undefined,调用方跳过该行。
1104
+ *
1105
+ * ⚠️ 只对**第三方**生产者名成立(第四轮审计 ST1):宿主 `producerKind`
1106
+ * (dsh-session-format-v3-to-v4@0.1.7-rc.2 lib/index.js:88-96)对第一方名走改名表
1107
+ * 或同名裸 kind,本函数无条件加前缀会对那 30 个名字写出宿主永不产出的 kind。
1108
+ * 第一方名由 `FIRST_PARTY_RENAMED_PRODUCERS` / `FIRST_PARTY_SAME_NAME_PRODUCERS`
1109
+ * 判定,`migrateSessionSourceKind` 命中即跳过并如实上报(宿主迁移职权,不代转换)。
1110
+ */
1111
+ declare function migrateLegacySource(source: unknown): Record<string, unknown> | undefined;
1112
+ /**
1113
+ * 转换一个会话日志里的旧署名行(v4 线专用;先备份,只动署名字段)。
1114
+ *
1115
+ * 执行闸(任一不满足即拒绝,不写盘):
1116
+ * 1. 日志可整体解码且无完整性问题(撕裂尾帧 / 解码失败 / seq 缺口);
1117
+ * 2. header.version ≥ 4(v3 及更早的旧行按契约由宿主迁移,不动);
1118
+ * 3. 确有旧署名行(没有则空手而归,不做无谓重压缩)。
1119
+ * @param sessionId - 会话 id(用于结果标注)。
1120
+ * @param logPath - 当前代日志路径(必须 .zstd 结尾)。
1121
+ * @param log - 已解码的日志(复用体检结果,闸 1/2 在其上判定)。
1122
+ * @param dshHome - DSH home(备份不依赖它,参数保留与其它处置一致的面)。
1123
+ * @param now - 时间源(备份后缀,测试可控)。
1124
+ */
1125
+ declare function migrateSessionSourceKind(sessionId: string, logPath: string, log: SessionLogRead, dshHome?: string, now?: () => number): SourceKindMigrationOutcome;
1126
+ /** 备份文件的后缀约定(purge/清理工具可据此识别并一并处置)。 */
1127
+ declare const SOURCE_MIGRATE_BACKUP_SUFFIX = ".pre-sourcemigrate-";
1128
+ //#endregion
1025
1129
  //#region src/host/health/lossless.d.ts
1026
1130
  /**
1027
1131
  * 无损 JSON 判定 —— 本次事故的核心 gate 判据。
@@ -1228,6 +1332,16 @@ declare function scanSessions(options: {
1228
1332
  //#region src/index.d.ts
1229
1333
  /** 本插件声明的宿主服务(与 toggle 相同的注入面)。 */
1230
1334
  declare const inject: string[];
1335
+ /** 运行时配置 schema(与 src/config.ts 的形状保持一致)。0.1.7:volatile 字段即设置表单。 */
1336
+ declare const Config: z<Schemastery.ObjectS<NoInfer<{
1337
+ enabled: z<boolean, boolean, "volatile-defined">;
1338
+ historyFiles: z<boolean, boolean, "volatile-defined">;
1339
+ healthCheck: z<boolean, boolean, "volatile-defined">;
1340
+ }>>, Schemastery.ObjectT<NoInfer<{
1341
+ enabled: z<boolean, boolean, "volatile-defined">;
1342
+ historyFiles: z<boolean, boolean, "volatile-defined">;
1343
+ healthCheck: z<boolean, boolean, "volatile-defined">;
1344
+ }>>, "plain">;
1231
1345
  /** 运行时依赖。 */
1232
1346
  interface StewardRuntime {
1233
1347
  config: () => Required<StewardConfig>;
@@ -1255,7 +1369,7 @@ interface StewardRuntime {
1255
1369
  * prune = 取消归档状态(可逆,会话回到侧边栏);purge = 清理归档文件(不可逆,真删实体)。
1256
1370
  */
1257
1371
  declare const HISTORY_METHODS: readonly ["session-history-list", "session-history-prune", "session-history-purge"];
1258
- declare const HEALTH_METHODS: readonly ["session-health-status", "session-health-scan", "session-health-session", "session-health-repair"];
1372
+ declare const HEALTH_METHODS: readonly ["session-health-status", "session-health-scan", "session-health-session", "session-health-repair", "session-health-source-migrate"];
1259
1373
  /** 依据开关判定某方法是否启用。 */
1260
1374
  declare function methodEnabled(method: string, config: Required<StewardConfig>): boolean;
1261
1375
  /**
@@ -1266,9 +1380,10 @@ declare function methodEnabled(method: string, config: Required<StewardConfig>):
1266
1380
  */
1267
1381
  declare function handleMethod(method: string, payload: unknown, runtime: StewardRuntime): Promise<unknown>;
1268
1382
  /**
1269
- * 插件主体:注册设置命名空间、装配运行时、挂载 fenced 路由。
1270
- * @param ctx - host 插件上下文(webServer / webRuntime / 可选 settings、sessionQuery、sessions、sessionProjections)。
1383
+ * 插件主体:装配运行时、挂载 fenced 路由。
1384
+ * @param ctx - host 插件上下文(webServer / webRuntime / 可选 sessionQuery、sessions、sessionProjections)。
1385
+ * @param config - 组合条目(0.1.7:`.volatile()` 字段为 live ref)。
1271
1386
  */
1272
- declare function apply(ctx: Context): void;
1387
+ declare function apply(ctx: Context, config?: Partial<StewardConfig>): void;
1273
1388
  //#endregion
1274
- export { DEFAULT_CONFIG, type DiscoveredSession, type GenerationArtifact, HEALTH_METHODS, HISTORY_METHODS, HealthCache, type HealthCacheEntry, type LogArtifact, type LogCompression, type RepairAssessment, type RepairVerdict, STEWARD_API_PREFIX, STEWARD_SETTINGS_NAMESPACE, type SessionGenerations, type SessionPriority, type StewardConfig, StewardRuntime, apply, assessRepair, buildProjectionOwnerIndex, buildSessionReport, classifyGenerationFilename, countCorpus, createAttributor, decodeSessionLogBytes, decodeSessionLogFile, dirSize, discoverSessions, editWorkspaceDocument, findSession, findSessionLog, firstLosslessViolation, gateColdRead, gateGeneration, gateLogIntegrity, gateLosslessJson, gateProjectionCache, generationLogFilename, handleMethod, indexSessionDirs, inject, isLossless, isMigrationStagingFilename, isSafeChild, latestArtifactMtime, listHistory, locateSessionUsage, methodEnabled, parseGenerationLogFilename, prescribe, projCacheRootFor, pruneArchiveFile, pruneHistory, purgeHistory, quarantineProjectionCache, readArchiveSet, readProjectionCache, readSessionGenerations, readTailFacts, scanSessions, scanZstdFrames, sessionPriority, sessionsRootFor };
1389
+ export { Config, DEFAULT_CONFIG, type DiscoveredSession, type GenerationArtifact, HEALTH_METHODS, HISTORY_METHODS, HealthCache, type HealthCacheEntry, type LogArtifact, type LogCompression, type RepairAssessment, type RepairVerdict, SOURCE_MIGRATE_BACKUP_SUFFIX, STEWARD_API_PREFIX, STEWARD_SETTINGS_NAMESPACE, type SessionGenerations, type SessionPriority, type StewardConfig, StewardRuntime, V4_HOST_MIN, apply, assessRepair, backupFilesIn, buildProjectionOwnerIndex, buildSessionReport, classifyGenerationFilename, countCorpus, createAttributor, decodeSessionLogBytes, decodeSessionLogFile, dirSize, discoverSessions, editWorkspaceDocument, findSession, findSessionLog, firstLosslessViolation, gateColdRead, gateGeneration, gateLogIntegrity, gateLosslessJson, gateProjectionCache, gateSourceKind, generationLogFilename, handleMethod, indexSessionDirs, inject, isLossless, isMigrationStagingFilename, isSafeChild, isSourceMigrateBackupName, latestArtifactMtime, listHistory, locateSessionUsage, methodEnabled, migrateLegacySource, migrateSessionSourceKind, parseGenerationLogFilename, prescribe, projCacheRootFor, pruneArchiveFile, pruneHistory, purgeHistory, quarantineProjectionCache, readArchiveSet, readProjectionCache, readSessionGenerations, readSourceKindFacts, readTailFacts, scanSessions, scanZstdFrames, sessionPriority, sessionsRootFor };