dsh-shiori 0.2.0 → 0.2.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.
@@ -18,7 +18,7 @@
18
18
  // - 候选队列持久快照跨重启恢复(queueStore);plan 账不可变(planStore)。
19
19
 
20
20
  import { analyzeCandidates } from "../organize/analyze.mjs";
21
- import { createCandidateQueue, buildDraft as buildOrganizeDraft, buildForgetArchiveDiff } from "../organize/queue.mjs";
21
+ import { createCandidateQueue, buildDraft as buildOrganizeDraft, buildForgetArchiveDiff, listQueue } from "../organize/queue.mjs";
22
22
  import { digestPlan as organizeDigestPlan, createOrganizerExecutor } from "../organize/executor.mjs";
23
23
  import { analyzeForgetting } from "../forgetting/decay.mjs";
24
24
  import { createForgetExecutor } from "../forgetting/executor.mjs";
@@ -183,12 +183,20 @@ export function createManagement(deps) {
183
183
  return timelineReader;
184
184
  }
185
185
 
186
- async function queueDto(scopeId, queue) {
186
+ /**
187
+ * 队列 DTO:items 经 organize/queue.mjs 的 listQueue 投影——候选 sources 补
188
+ * 卡片 title(取不到给 null),其余字段原样(只增不改)。records 缺省时
189
+ * 不投影(保持旧形状,供无需标题的内部路径复用)。
190
+ */
191
+ async function queueDto(scopeId, queue, records) {
187
192
  const snapshot = queue.snapshot();
188
193
  const plans = await state.planStore.list(scopeId);
194
+ const items = records === undefined
195
+ ? snapshot.items
196
+ : listQueue({ items: snapshot.items, records }).items;
189
197
  return {
190
198
  queueRevision: snapshot.revision,
191
- items: snapshot.items,
199
+ items,
192
200
  plans,
193
201
  };
194
202
  }
@@ -395,13 +403,34 @@ export function createManagement(deps) {
395
403
  return executeToolForScope(scope, payload.name, payload.args ?? {});
396
404
  },
397
405
 
398
- /** 候选队列与计划摘要(同 scope;不泄露别卡)。 */
406
+ /**
407
+ * 候选队列与计划摘要(同 scope;不泄露别卡)。可选 limit / offset 分页
408
+ * (缺省不分页,行为与旧版完全一致);候选项 sources 补卡片 title、
409
+ * 条目补 stale(源 revision 与 records 不一致 / 源卡不在 records 即过期)、
410
+ * 顶层补 total / groups / statusCounts / staleCount(计数不受分页影响,
411
+ * staleCount 为分页前全量口径),客户端一次请求即可渲染分组与标题,
412
+ * 无需二次取卡比对。投影走 organize/queue.mjs 的 listQueue(纯只读),
413
+ * 不改变队列状态。
414
+ */
399
415
  async listCandidates(trustedContext, payload) {
400
- validateManagementPayload("listCandidates", payload ?? {});
416
+ const p = payload ?? {};
417
+ validateManagementPayload("listCandidates", p);
401
418
  requireActiveDataAccess("listCandidates");
402
419
  const scope = await scopeFromTrustedContext(trustedContext);
420
+ const resources = await resourcesFor(scope.scopeId, sessionEvidenceFromRpc(trustedContext).agent);
421
+ const records = await resources.sparkStore.listActive();
403
422
  const queue = await loadQueue(scope.scopeId);
404
- return queueDto(scope.scopeId, queue);
423
+ const snapshot = queue.snapshot();
424
+ const page = listQueue({ items: snapshot.items, records, limit: p.limit, offset: p.offset });
425
+ return {
426
+ queueRevision: snapshot.revision,
427
+ items: page.items,
428
+ plans: await state.planStore.list(scope.scopeId),
429
+ total: page.total,
430
+ groups: page.groups,
431
+ statusCounts: page.statusCounts,
432
+ staleCount: page.staleCount,
433
+ };
405
434
  },
406
435
 
407
436
  /**
@@ -445,7 +474,8 @@ export function createManagement(deps) {
445
474
  }
446
475
  }
447
476
  const queue = await loadQueue(scope.scopeId);
448
- const dto = await queueDto(scope.scopeId, queue);
477
+ const replayRecords = await resources.sparkStore.listActive();
478
+ const dto = await queueDto(scope.scopeId, queue, replayRecords);
449
479
  return { ...dto, analysis: prior.analysis };
450
480
  }
451
481
 
@@ -498,7 +528,7 @@ export function createManagement(deps) {
498
528
  keepPlanId: null,
499
529
  operationId: payload.operationId,
500
530
  });
501
- const dto = await queueDto(scope.scopeId, queue);
531
+ const dto = await queueDto(scope.scopeId, queue, records);
502
532
  return { ...dto, analysis };
503
533
  }
504
534
 
@@ -554,7 +584,7 @@ export function createManagement(deps) {
554
584
  });
555
585
  const plans = await state.planStore.list(scope.scopeId);
556
586
  const queue = await loadQueue(scope.scopeId);
557
- const dto = await queueDto(scope.scopeId, queue);
587
+ const dto = await queueDto(scope.scopeId, queue, records);
558
588
  return {
559
589
  queueRevision: dto.queueRevision,
560
590
  items: dto.items,
@@ -571,6 +601,8 @@ export function createManagement(deps) {
571
601
  assertHostWritable("reviewCandidate");
572
602
  requireModule("organize");
573
603
  const scope = await scopeFromTrustedContext(trustedContext);
604
+ const resources = await resourcesFor(scope.scopeId, sessionEvidenceFromRpc(trustedContext).agent);
605
+ const records = await resources.sparkStore.listActive();
574
606
  const queue = await loadQueue(scope.scopeId);
575
607
  queue.review(payload.candidateId, {
576
608
  decision: payload.decision,
@@ -578,7 +610,7 @@ export function createManagement(deps) {
578
610
  operationId: payload.operationId,
579
611
  });
580
612
  await state.queueStore.save(scope.scopeId, queue.snapshot());
581
- return queueDto(scope.scopeId, queue);
613
+ return queueDto(scope.scopeId, queue, records);
582
614
  },
583
615
 
584
616
  /** 计划预览:organize proposal 走 buildDraft;forgetting 用 planId 取回 analyze 保存的计划。 */
@@ -767,19 +799,28 @@ export function createManagement(deps) {
767
799
  fail("AUTHORIZATION_REQUIRED", "executePlan cancelled before execution was recorded", { planId: payload.planId });
768
800
  }
769
801
  await state.planStore.markExecuted(scope.scopeId, payload.planId, payload.operationId);
770
- // P-A:执行后立即收敛队列——移除引用「已不再是 active」源卡的候选
771
- // (merge 退休 / forgetting 归档后,面板不再把失效条目画成可审阅;
772
- // link 计划源卡仍 active,不动队列)。确定性/重放安全:移除集合由
773
- // 「队列项 ∩ 非 active 源卡」决定;重放同 operationId 时首轮已移除、
774
- // 幸存集合不变 → 不动队列、不记队列事务。队列 operationId 复用本次
775
- // 执行 operationId(面板各操作生成唯一 operationId)。
802
+ // P-A:执行后立即收敛队列——移除两类候选:
803
+ // 1) 引用「已不再是 active」源卡的候选(merge 退休 / forgetting 归档后,
804
+ // 面板不再把失效条目画成可审阅);
805
+ // 2) 本次执行的候选本身(organize plan.candidateId 指向的那条):它已
806
+ // 被执行完毕,留在队列里只会让用户再点一个注定 REVISION_CONFLICT
807
+ // 的按钮(link 计划源卡仍 active,旧逻辑因此漏掉它)。收敛/保存后
808
+ // queueRevision 前进,客户端 load() 刷新即拿不到旧候选。
809
+ // forgetting 计划(archive-ephemeral)没有 candidateId → executedCandidateId
810
+ // 为 null,此时行为与只按 active 过滤完全一致。
811
+ // 确定性/重放安全:移除集合由「队列项 ∩ (非 active 源卡 ∪ 已执行候选)」
812
+ // 决定;重放同 operationId 时首轮已移除、幸存集合不变 → 不动队列、不记
813
+ // 队列事务。队列 operationId 复用本次执行 operationId(面板各操作生成
814
+ // 唯一 operationId)。
776
815
  // P-A 残留收紧:收敛/保存抛错时 grant 也必须撤销(merge 已落盘但
777
816
  // 调用报错——grant 泄漏会放大授权窗口),finally 保证两条路径都撤销。
817
+ const executedCandidateId = typeof entry.plan?.candidateId === "string" ? entry.plan.candidateId : null;
778
818
  try {
779
819
  const queue = await loadQueue(scope.scopeId);
780
820
  const snapshot = queue.snapshot();
781
821
  const activeIds = new Set((await resources.sparkStore.listActive()).map((r) => r.id));
782
822
  const survivors = snapshot.items
823
+ .filter((it) => executedCandidateId === null || it.candidate.id !== executedCandidateId)
783
824
  .filter((it) => it.candidate.sources.every((s) => activeIds.has(s.id)))
784
825
  .map((it) => it.candidate);
785
826
  if (survivors.length !== snapshot.items.length) {
@@ -363,7 +363,20 @@ export const MANAGEMENT_METHODS = Object.freeze({
363
363
  },
364
364
 
365
365
  listCandidates: {
366
- inputSchema: { type: "object", additionalProperties: false, properties: {} },
366
+ // 可选 limit / offset 分页(缺省都不传 = 不分页,行为与旧版一致)。
367
+ inputSchema: {
368
+ type: "object",
369
+ additionalProperties: false,
370
+ properties: {
371
+ limit: { type: "integer", minimum: 0 },
372
+ offset: { type: "integer", minimum: 0 },
373
+ },
374
+ },
375
+ // total/groups/statusCounts/staleCount 为增量字段(groups/statusCounts/
376
+ // staleCount 按分页前全量 items 计数);items 内 candidate.sources 增量补
377
+ // title、条目增量补 stale(该候选任一源的 revision 与 records 不一致、
378
+ // 源卡已不在 records 或 ref.revision 缺失/非整数即过期,fail-closed;
379
+ // queueItemEntry 为 additionalProperties:true,无需改条目形状)。
367
380
  outputSchema: {
368
381
  type: "object",
369
382
  additionalProperties: false,
@@ -371,8 +384,30 @@ export const MANAGEMENT_METHODS = Object.freeze({
371
384
  queueRevision,
372
385
  items: { type: "array", items: queueItemEntry },
373
386
  plans: { type: "array", items: planSummary },
387
+ total: { type: "integer", minimum: 0 },
388
+ staleCount: { type: "integer", minimum: 0 },
389
+ groups: {
390
+ type: "object",
391
+ additionalProperties: false,
392
+ properties: {
393
+ cluster: { type: "integer", minimum: 0 },
394
+ link: { type: "integer", minimum: 0 },
395
+ isolated: { type: "integer", minimum: 0 },
396
+ },
397
+ required: ["cluster", "link", "isolated"],
398
+ },
399
+ statusCounts: {
400
+ type: "object",
401
+ additionalProperties: false,
402
+ properties: {
403
+ pending: { type: "integer", minimum: 0 },
404
+ reviewed: { type: "integer", minimum: 0 },
405
+ dismissed: { type: "integer", minimum: 0 },
406
+ },
407
+ required: ["pending", "reviewed", "dismissed"],
408
+ },
374
409
  },
375
- required: ["queueRevision", "items", "plans"],
410
+ required: ["queueRevision", "items", "plans", "total", "groups", "statusCounts", "staleCount"],
376
411
  },
377
412
  },
378
413
 
@@ -10,7 +10,7 @@
10
10
  // code="SEMANTIC_UNAVAILABLE" 的 coded error,带底层 cause 与中文可读
11
11
  // message;绝不静默降级冒充可用。是否回退纯字面由召回合并层决定。
12
12
  // - embed(text) 返回 Float32Array(dims):pipeline("feature-extraction")
13
- // + pooling mean + normalize,与 spike(D:/AIagent/spike-f1b/结论.md)
13
+ // + pooling mean + normalize,与 spike(见 spike 目录的结论.md)
14
14
  // 实测配置一致(q8 短文本 p95 3.98ms,512 维)。
15
15
 
16
16
  // 本模块不引入宿主依赖;fail 与 index.mjs 同风格(可序列化 .code + .details)。
@@ -105,7 +105,7 @@ export function createLocalEmbeddingProvider({
105
105
  }
106
106
  try {
107
107
  const { pipeline, env } = transformers;
108
- // 与 spike bench 完全一致的 env 配置(D:/AIagent/spike-f1b/bench2.mjs):
108
+ // 与 spike bench 完全一致的 env 配置(见 spike 目录的 bench2.mjs):
109
109
  // allowLocalModels=true + cacheDir + remoteHost(hf-mirror)。
110
110
  // 注意 env 是该模块的全局单例:本插件是进程内唯一的 transformers 消费方。
111
111
  env.allowLocalModels = true;