@cjhyy/code-shell-pet 0.9.2 → 0.9.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.
@@ -30,7 +30,7 @@ export interface PetLongTaskCompletionTarget {
30
30
  replyAttachmentKinds?: PetReplyAttachmentKind[];
31
31
  }
32
32
  export type PetReplyAttachmentKind = "image" | "file" | "audio" | "video";
33
- export type PetLongTaskEventKind = "created" | "started" | "progress" | "waiting" | "paused" | "resumed" | "retrying" | "artifact" | "checkpoint" | "verification-changed" | "completion-target-set" | "interrupted" | "completed" | "failed" | "cancelled" | "closure-decided" | "continuation-started" | "closure-recorded";
33
+ export type PetLongTaskEventKind = "created" | "started" | "progress" | "waiting" | "paused" | "resumed" | "retrying" | "artifact" | "checkpoint" | "verification-changed" | "completion-target-set" | "interrupted" | "completed" | "failed" | "cancelled" | "closure-decided" | "continuation-started" | "closure-recorded" | "work-memory-recorded";
34
34
  export interface PetLongTaskEvent {
35
35
  id: string;
36
36
  sequence: number;
@@ -64,8 +64,10 @@ export interface PetLongTask {
64
64
  updatedAt: number;
65
65
  startedAt?: number;
66
66
  completedAt?: number;
67
- /** The current attempt's terminal outcome reached durable Pet work memory. */
67
+ /** User-visible closure effects finished and are safe to deduplicate on replay. */
68
68
  closureRecordedAt?: number;
69
+ /** The current attempt's terminal outcome reached durable Pet work memory. */
70
+ workMemoryRecordedAt?: number;
69
71
  /** Durable Mimi closure decision, persisted before any continuation side effect. */
70
72
  closureDecision?: PetLongTaskClosureDecision;
71
73
  /** Latest assistant-authored result/checkpoint, kept separate from UI progress text. */
@@ -222,8 +224,11 @@ export type PetLongTaskTransition = {
222
224
  sessionId: string;
223
225
  taskId?: string;
224
226
  } | {
225
- kind: "closure-recorded";
227
+ kind: "closure-recorded" | "work-memory-recorded";
226
228
  at: number;
229
+ /** Optional optimistic fence for async closure side effects. */
230
+ attempt?: number;
231
+ status?: PetLongTaskStatus;
227
232
  };
228
233
  export declare function createPetLongTask(input: CreatePetLongTaskInput): PetLongTask;
229
234
  /**
package/dist/long-task.js CHANGED
@@ -204,14 +204,23 @@ export function transitionPetLongTask(current, transition) {
204
204
  transition.kind !== "background-wait-recovered" &&
205
205
  transition.kind !== "closure-decided" &&
206
206
  transition.kind !== "continuation-started" &&
207
- transition.kind !== "closure-recorded") {
207
+ transition.kind !== "closure-recorded" &&
208
+ transition.kind !== "work-memory-recorded") {
208
209
  return current;
209
210
  }
210
211
  if (current.status === "cancelled" &&
211
212
  transition.kind !== "retrying" &&
212
213
  transition.kind !== "closure-decided" &&
213
214
  transition.kind !== "continuation-started" &&
214
- transition.kind !== "closure-recorded") {
215
+ transition.kind !== "closure-recorded" &&
216
+ transition.kind !== "work-memory-recorded") {
217
+ return current;
218
+ }
219
+ if ((transition.kind === "closure-recorded" || transition.kind === "work-memory-recorded") &&
220
+ (!TERMINAL.has(current.status) ||
221
+ (transition.attempt !== undefined && transition.attempt !== current.attempt) ||
222
+ (transition.status !== undefined && transition.status !== current.status) ||
223
+ (transition.kind === "work-memory-recorded" && current.closureRecordedAt === undefined))) {
215
224
  return current;
216
225
  }
217
226
  const next = {
@@ -331,6 +340,7 @@ export function transitionPetLongTask(current, transition) {
331
340
  startedAt: undefined,
332
341
  completedAt: undefined,
333
342
  closureRecordedAt: undefined,
343
+ workMemoryRecordedAt: undefined,
334
344
  closureDecision: undefined,
335
345
  waitingFor: undefined,
336
346
  nextAction: "Retry from the existing work session and checkpoint",
@@ -405,6 +415,7 @@ export function transitionPetLongTask(current, transition) {
405
415
  startedAt: Math.max(current.createdAt, transition.attemptStartedAt),
406
416
  completedAt: undefined,
407
417
  closureRecordedAt: undefined,
418
+ workMemoryRecordedAt: undefined,
408
419
  closureDecision: undefined,
409
420
  waitingFor: bounded(transition.reason, 500),
410
421
  nextAction: "Resume from the durable work session",
@@ -565,6 +576,15 @@ export function transitionPetLongTask(current, transition) {
565
576
  }
566
577
  case "closure-recorded":
567
578
  Object.assign(next, { closureRecordedAt: transition.at });
579
+ event = {
580
+ kind: transition.kind,
581
+ at: transition.at,
582
+ phase: current.phase,
583
+ message: "Terminal closure delivered",
584
+ };
585
+ break;
586
+ case "work-memory-recorded":
587
+ Object.assign(next, { workMemoryRecordedAt: transition.at });
568
588
  event = {
569
589
  kind: transition.kind,
570
590
  at: transition.at,
@@ -614,6 +634,7 @@ function isEventKind(value) {
614
634
  "closure-decided",
615
635
  "continuation-started",
616
636
  "closure-recorded",
637
+ "work-memory-recorded",
617
638
  ].includes(value));
618
639
  }
619
640
  function parseEvent(value) {
@@ -781,6 +802,9 @@ export function parsePetLongTask(value) {
781
802
  ...(typeof record.closureRecordedAt === "number"
782
803
  ? { closureRecordedAt: record.closureRecordedAt }
783
804
  : {}),
805
+ ...(typeof record.workMemoryRecordedAt === "number"
806
+ ? { workMemoryRecordedAt: record.workMemoryRecordedAt }
807
+ : {}),
784
808
  ...(closureDecision ? { closureDecision } : {}),
785
809
  ...(typeof record.resultSummary === "string"
786
810
  ? { resultSummary: record.resultSummary.slice(0, MAX_PET_LONG_TASK_SUMMARY_LENGTH) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-pet",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Pet (top-level personal assistant) capability for CodeShell — projection state machine, DelegateWork contract, Mimi behavior profile.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
37
37
  },
38
38
  "dependencies": {
39
- "@cjhyy/code-shell-core": "0.9.2"
39
+ "@cjhyy/code-shell-core": "0.9.3"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=20.10"