@cjhyy/code-shell-pet 0.8.7 → 0.8.8

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.
@@ -17,6 +17,12 @@ export interface PetReusableSessionOption {
17
17
  workspaceId: string;
18
18
  name: string;
19
19
  description?: string;
20
+ /**
21
+ * Last activity time (epoch ms), when the host knows it. Sessions inactive
22
+ * beyond the staleness threshold are trimmed from the per-turn snapshot;
23
+ * entries without a timestamp are always kept.
24
+ */
25
+ lastActiveAt?: number;
20
26
  }
21
27
  /** Structured decision produced only by a successful DelegateWork tool call. */
22
28
  export interface PetWorkDelegation {
package/dist/index.d.ts CHANGED
@@ -30,3 +30,4 @@ export { createPetCapability } from "./capability.js";
30
30
  export * from "./topic-segment.js";
31
31
  export * from "./segment-closure.js";
32
32
  export * from "./long-task.js";
33
+ export * from "./migration-summary.js";
package/dist/index.js CHANGED
@@ -30,3 +30,4 @@ export { createPetCapability } from "./capability.js";
30
30
  export * from "./topic-segment.js";
31
31
  export * from "./segment-closure.js";
32
32
  export * from "./long-task.js";
33
+ export * from "./migration-summary.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Build the one-time migration summary for a pre-existing Mimi session from
3
+ * its persisted journal entries (oldest → newest). Pure; no model call — the
4
+ * journal already holds the per-segment distillations.
5
+ */
6
+ export declare function buildMigrationSummary(entries: readonly {
7
+ title: string;
8
+ summary: string;
9
+ }[]): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Build the one-time migration summary for a pre-existing Mimi session from
3
+ * its persisted journal entries (oldest → newest). Pure; no model call — the
4
+ * journal already holds the per-segment distillations.
5
+ */
6
+ export function buildMigrationSummary(entries) {
7
+ if (entries.length === 0)
8
+ return "";
9
+ const lines = entries.map((entry) => `【${entry.title}】${entry.summary}`);
10
+ return ["以下是此前各段对话的归档小结(旧 → 新):", ...lines].join("\n\n");
11
+ }
package/dist/profile.js CHANGED
@@ -68,6 +68,9 @@ export const PET_BEHAVIOR_PROFILE = {
68
68
  forcePermissionMode: "default",
69
69
  disablePlanMode: true,
70
70
  disableMcp: true,
71
+ // Mimi manages work from one fixed vantage point and never executes inside
72
+ // other repos — cross-project memory records are dead context for her turns.
73
+ memoryCurrentProjectOnly: true,
71
74
  runtimeContextTag: "pet-world",
72
75
  runtimeContextHeading: "# Trusted Pet Runtime Context (non-durable)",
73
76
  activateForSessionKinds: ["pet"],
@@ -1,6 +1,8 @@
1
1
  import { isPetHostActionKind, } from "./host-actions.js";
2
2
  import { parsePetGatewayCatalog } from "./gateway.js";
3
3
  const MAX_RUNTIME_CONTEXT_LENGTH = 32_768;
4
+ /** Reusable Sessions inactive longer than this are trimmed from the turn snapshot. */
5
+ const STALE_REUSABLE_SESSION_THRESHOLD_MS = 180 * 24 * 60 * 60 * 1000;
4
6
  const MAX_WORKSPACES = 64;
5
7
  const MAX_REUSABLE_SESSIONS = 32;
6
8
  const MAX_FOLLOW_UPS = 100;
@@ -54,16 +56,27 @@ function parseWorkspaces(value) {
54
56
  }
55
57
  return result;
56
58
  }
57
- function parseReusableSessions(value) {
59
+ /**
60
+ * When `staleThresholdMs` is set, entries whose `lastActiveAt` is older than
61
+ * `now - staleThresholdMs` are dropped (after shape validation, so a stale
62
+ * entry with a malformed sibling field still fails the whole array closed).
63
+ * Entries without a timestamp are kept — filtering is opt-in per entry.
64
+ */
65
+ function parseReusableSessions(value, staleThresholdMs) {
58
66
  if (!Array.isArray(value) || value.length > MAX_REUSABLE_SESSIONS)
59
67
  return undefined;
68
+ const staleBefore = staleThresholdMs === undefined ? undefined : Date.now() - staleThresholdMs;
60
69
  const ids = new Set();
61
70
  const result = [];
62
71
  for (const entry of value) {
63
72
  if (!isRecord(entry) ||
64
73
  !validOpaqueId(entry.id) ||
65
74
  !validOpaqueId(entry.workspaceId) ||
66
- ids.has(entry.id)) {
75
+ ids.has(entry.id) ||
76
+ (entry.lastActiveAt !== undefined &&
77
+ (typeof entry.lastActiveAt !== "number" ||
78
+ !Number.isFinite(entry.lastActiveAt) ||
79
+ entry.lastActiveAt < 0))) {
67
80
  return undefined;
68
81
  }
69
82
  const name = normalizedName(entry.name);
@@ -71,11 +84,17 @@ function parseReusableSessions(value) {
71
84
  if (!name || description === null)
72
85
  return undefined;
73
86
  ids.add(entry.id);
87
+ if (staleBefore !== undefined &&
88
+ typeof entry.lastActiveAt === "number" &&
89
+ entry.lastActiveAt < staleBefore) {
90
+ continue;
91
+ }
74
92
  result.push({
75
93
  id: entry.id,
76
94
  workspaceId: entry.workspaceId,
77
95
  name,
78
96
  ...(description ? { description } : {}),
97
+ ...(typeof entry.lastActiveAt === "number" ? { lastActiveAt: entry.lastActiveAt } : {}),
79
98
  });
80
99
  }
81
100
  return result;
@@ -261,7 +280,7 @@ export function petRunOptionsFrom(profileParams) {
261
280
  const workspaces = profileParams.workspaces === undefined ? [] : parseWorkspaces(profileParams.workspaces);
262
281
  const reusableSessions = profileParams.reusableSessions === undefined
263
282
  ? []
264
- : parseReusableSessions(profileParams.reusableSessions);
283
+ : parseReusableSessions(profileParams.reusableSessions, STALE_REUSABLE_SESSION_THRESHOLD_MS);
265
284
  if (!workspaces || !reusableSessions)
266
285
  return empty;
267
286
  const workspaceIds = new Set(workspaces.map((workspace) => workspace.id));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-pet",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
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",
@@ -35,7 +35,7 @@
35
35
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
36
36
  },
37
37
  "dependencies": {
38
- "@cjhyy/code-shell-core": "0.8.7"
38
+ "@cjhyy/code-shell-core": "0.8.8"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=20.10"