@lmzhen/dsh-evolution-core 0.52.0 → 0.54.0

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.
@@ -3,7 +3,97 @@ import { t as connectionPort } from "../connection-DAJy7Xjm.js";
3
3
  import { C as workingDirectoryPort, D as profileContextPort, E as pluginManagerPort, O as commandsPort, S as skillsPort, T as pluginInventoryPort, _ as agentsPort, b as storageDomainPort, d as EvolutionLlmError, f as llmPort, g as subagentsPort, h as userQuestionsPort, m as projectionPort, p as modelRoute, v as systemPromptPort, w as configEditorPort, x as sessionQueryPort, y as settingsPort } from "../platform-DyHnHUmQ.js";
4
4
  import { t as presetsPort } from "../presets-C8vuCuNA.js";
5
5
  import { n as toolsPort } from "../tools-BrUswg8v.js";
6
+ import { join } from "node:path";
7
+ import { existsSync, readFileSync } from "node:fs";
6
8
  import { Service } from "@deepseek-ai/cordis";
9
+ //#region lib/types/runtime/coherence.js
10
+ /**
11
+ * Family version coherence probe.
12
+ *
13
+ * A profile can contain one bundle whose implementation packages come from
14
+ * different family releases: the bundle row updates while a directly pinned
15
+ * sibling stays behind, or old hand-copied packages shadow the pnpm tree. The
16
+ * loader then runs an old client against a new host, which looks like a UI
17
+ * regression rather than a mixed install. This probe names that state at
18
+ * startup; it never repairs a live profile (a package-manager write while the
19
+ * host runs is unsafe and needs a restart).
20
+ *
21
+ * @module @lmzhen/dsh-evolution-core/runtime/coherence
22
+ */
23
+ function packageTail(name) {
24
+ return name.slice(name.lastIndexOf("/") + 1);
25
+ }
26
+ /** Family implementation tails; external @deepseek-ai packages stay out. */
27
+ function isFamilyPackage(name) {
28
+ const tail = packageTail(name);
29
+ return tail.startsWith("dsh-evolution-") || tail === "dsh-memory" || tail === "dsh-memory-files" || tail === "dsh-skill-usage" || tail === "dsh-tool-memory" || tail === "dsh-tool-skill-manage";
30
+ }
31
+ /**
32
+ * Compare every implementation package with the installed `all` bundle.
33
+ * Missing packages count as a mismatch because the old loader would fall back
34
+ * to an unrelated copy or fail at load.
35
+ * @param profileDir - profile directory containing `package.json` and `node_modules`.
36
+ * @returns The coherence result, or undefined when the profile has no readable `all` bundle.
37
+ */
38
+ function checkFamilyCoherence(profileDir) {
39
+ if (!existsSync(join(profileDir, "package.json"))) return void 0;
40
+ const resolveManifest = (name) => {
41
+ const path = join(profileDir, "node_modules", name, "package.json");
42
+ return existsSync(path) ? path : void 0;
43
+ };
44
+ const allPath = resolveManifest("@lmzhen/dsh-evolution-all") ?? resolveManifest("@lmzhen/dsh-evolution-all");
45
+ if (allPath === void 0) return void 0;
46
+ let all;
47
+ try {
48
+ all = JSON.parse(readFileSync(allPath, "utf8"));
49
+ } catch {
50
+ return;
51
+ }
52
+ if (typeof all.version !== "string") return void 0;
53
+ const components = [];
54
+ const visited = /* @__PURE__ */ new Set();
55
+ const queue = Object.keys(all.dependencies ?? {}).filter(isFamilyPackage);
56
+ while (queue.length > 0) {
57
+ const name = queue.shift();
58
+ if (name === void 0 || visited.has(name)) continue;
59
+ visited.add(name);
60
+ const manifestPath = resolveManifest(name);
61
+ if (manifestPath === void 0) {
62
+ components.push({ name });
63
+ continue;
64
+ }
65
+ try {
66
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
67
+ components.push({
68
+ name,
69
+ ...typeof manifest.version === "string" ? { version: manifest.version } : {}
70
+ });
71
+ for (const child of [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.optionalDependencies ?? {})]) if (isFamilyPackage(child) && !visited.has(child)) queue.push(child);
72
+ } catch {
73
+ components.push({ name });
74
+ }
75
+ }
76
+ return {
77
+ allVersion: all.version,
78
+ components,
79
+ mismatched: components.filter((component) => component.version !== all.version)
80
+ };
81
+ }
82
+ /**
83
+ * Warn once when the running profile is a mixed family install.
84
+ * @param ctx - the running host context; a bare library mount has no profile and is skipped.
85
+ * @returns The detected mismatch, or undefined when no profile/all bundle is present.
86
+ */
87
+ function warnIfFamilyMixed(ctx) {
88
+ const profile = profileContextPort(ctx);
89
+ if (profile === void 0) return void 0;
90
+ const coherence = checkFamilyCoherence(profile.dir);
91
+ if (coherence === void 0 || coherence.mismatched.length === 0) return void 0;
92
+ const details = coherence.mismatched.map((component) => `${component.name}@${component.version ?? "missing"}`).join(", ");
93
+ console.warn(`[dsh-evolution] mixed family install: all@${coherence.allVersion} but ${details}; the loaded client may be an older release. Run the profile repair in INSTALL.md before restarting.`);
94
+ return coherence;
95
+ }
96
+ //#endregion
7
97
  //#region lib/types/runtime/llm.js
8
98
  /**
9
99
  * The family's LLM runtime: one route/purpose/transport path for auxiliary
@@ -231,6 +321,7 @@ async function apply(ctx) {
231
321
  await ctx.plugin(EvolutionPlatform);
232
322
  await ctx.plugin(EvolutionProjections);
233
323
  await ctx.plugin(EvolutionLlm);
324
+ warnIfFamilyMixed(ctx);
234
325
  }
235
326
  //#endregion
236
327
  export { apply, name };
package/lib/skills.js CHANGED
@@ -22,10 +22,33 @@ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:pat
22
22
  *
23
23
  * @module @lmzhen/dsh-evolution-core
24
24
  */
25
+ /** Human-facing "最近使用" window; one constant so host and tests cannot drift. */
26
+ const RECENT_USE_WINDOW_DAYS = 30;
27
+ /** Newest model load / external use timestamp, or null when neither was measured. */
28
+ function latestActivityAt(usage) {
29
+ let best = null;
30
+ let bestMs = Number.NEGATIVE_INFINITY;
31
+ for (const value of [usage?.lastUsedAt ?? null, usage?.lastViewedAt ?? null]) {
32
+ if (value === null) continue;
33
+ const ms = Date.parse(value);
34
+ if (!Number.isFinite(ms)) continue;
35
+ if (ms > bestMs) {
36
+ best = value;
37
+ bestMs = ms;
38
+ }
39
+ }
40
+ return best;
41
+ }
42
+ /** Whether an activity timestamp is inside the use window; null when no activity was measured. */
43
+ function recentlyUsedAt(lastActivityAtValue, now = /* @__PURE__ */ new Date()) {
44
+ if (lastActivityAtValue === null) return null;
45
+ const ms = Date.parse(lastActivityAtValue);
46
+ if (!Number.isFinite(ms)) return null;
47
+ return ms >= now.getTime() - 30 * 864e5;
48
+ }
25
49
  /** A verdict that asks the user to act; `healthy` and `unknown` do not. */
26
50
  function needsAttention(row) {
27
- const verdict = row.health?.verdict;
28
- return verdict === "warn" || verdict === "needs-restructure";
51
+ return row.needsAttention;
29
52
  }
30
53
  /** Severity order for the status column: actionable first, healthy last. */
31
54
  function verdictRank(verdict) {
@@ -58,7 +81,7 @@ function sortValue(row, key) {
58
81
  case "feedback30d": return row.feedback30d;
59
82
  case "negativeFeedback30d": return row.negativeFeedback30d;
60
83
  case "feedbackRate30d": return row.feedbackRate30d;
61
- case "lastAt": return row.lastAt === null ? null : Date.parse(row.lastAt);
84
+ case "lastAt": return row.lastChangedAt === null ? null : Date.parse(row.lastChangedAt);
62
85
  }
63
86
  }
64
87
  /**
@@ -84,7 +107,7 @@ function sortSkillStats(rows, key, direction) {
84
107
  function filterSkillStats(rows, filter) {
85
108
  if (filter === "all") return [...rows];
86
109
  if (filter === "attention") return rows.filter(needsAttention);
87
- return rows.filter((row) => row.lastAt !== null);
110
+ return rows.filter((row) => row.recentlyUsed === true);
88
111
  }
89
112
  /** Sum a nullable numeric column: all-null means the total itself is unknown, not zero. */
90
113
  function sumNullable(values) {
@@ -108,6 +131,39 @@ function computeSkillStatsTotals(rows, counts) {
108
131
  };
109
132
  }
110
133
  //#endregion
134
+ //#region lib/types/skill-operations.js
135
+ /**
136
+ * User-facing operation identities shared by the stats UI, command copy and history labels.
137
+ *
138
+ * The tool/command layers own execution; this table owns only presentation semantics. Keeping it in
139
+ * core means a UI label and a success-count key cannot drift into two spellings of the same action.
140
+ * @module @lmzhen/dsh-evolution-core
141
+ */
142
+ /** The one operation table. Unknown ids never gain a label by accident. */
143
+ const SKILL_OPERATIONS = Object.freeze([
144
+ {
145
+ id: "offload",
146
+ labelKey: "operation.offload.label",
147
+ descriptionKey: "operation.offload.description",
148
+ kind: "deterministic",
149
+ surface: "advanced"
150
+ },
151
+ {
152
+ id: "condense",
153
+ labelKey: "operation.condense.label",
154
+ descriptionKey: "operation.condense.description",
155
+ kind: "agent",
156
+ surface: "advanced"
157
+ },
158
+ {
159
+ id: "extract",
160
+ labelKey: "operation.extract.label",
161
+ descriptionKey: "operation.extract.description",
162
+ kind: "agent",
163
+ surface: "advanced"
164
+ }
165
+ ]);
166
+ //#endregion
111
167
  //#region lib/types/skill-row-cells.js
112
168
  /**
113
169
  * The cells one row shows, decided here and rendered by the client.
@@ -4274,4 +4330,4 @@ function newSkillLibrary(options) {
4274
4330
  } : void 0, transact, [...threatExemptLabels ?? []], authority, options.mutationLock ?? mutationLockFrom(ctx), options.fence ?? ctx?.get?.("evolutionMutationAuthority")?.homeFence);
4275
4331
  }
4276
4332
  //#endregion
4277
- export { BASELINE_ACTION, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_WRITE_SUMMARY_CHARS, DEFAULT_SUPPORT_FILE_CHAR_POLICY, HEALTH_STAMP_RE, HISTORY_DIR, HISTORY_INDEX_VERSION, MAX_RESTRUCTURE_MOVES, MIN_STAMP_BODY_CHARS, POLICY_STAGE_DEFAULTS, READ_REQUIRED_ACTIONS, RESTRUCTURE_TARGET_RE, RETENTION_FEEDBACK_KEEP_RATIO, RETENTION_FEEDBACK_MIN_CHARS, RULES, SNAPSHOT_EXTRA_NAME_RE, SkillLibrary, SkillModel, TEXT_DIFF_MAX_CHARS, TEXT_DIFF_MAX_LINES, ageCopyKey, anchorVerdict, assertSkillsRootAliasRetired, assessStructureHealth, authoringFeedback, blobPath, clipChangeSummary, compareSkillStats, computeSkillStatsTotals, contentRetentionFeedback, diffFindings, elapsedSince, ensureSkillFrontmatter, entryTarget, exceedsContentLimit, filterSkillStats, filterUnreadSkillOps, frontmatterBlock, frontmatterCatalogInvalid, historyIndexFile, historyRoot, isUnreadWrite, latestVersionAt, lintBody, lintSkill, loadVersionContent, loadVersions, markerEntryName, needsAttention, newSkillLibrary, nextHistoryIndex, normalizeChangeSummary, normalizeFrontmatter, orderVersions, parseFrontmatter, parseHistoryIndex, partitionVersions, policyStageLimits, readHistoryIndex, recordVersions, relatedSkillNames, resolveExecOrigins, resolveOrigins, resolveRootConfig, resolveSkillsRoot, revisionAnchor, revisionAnchorOf, revisionFingerprint, revisionSupportDigest, sessionReadSkillNames, sessionReadSupportFiles, shrinksOverLimit, skillMdOnDisk, skillRowCells, skillStateKey, skillsRoot, sortSkillStats, sortValue, summaryChars, textDiffFacts, validateFrontmatter, validateRestructureTarget, validateSupportPath, verdictRank, versionActionKind, versionRowCells, versionTarget, yamlPlainScalarNeedsQuotes };
4333
+ export { BASELINE_ACTION, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_WRITE_SUMMARY_CHARS, DEFAULT_SUPPORT_FILE_CHAR_POLICY, HEALTH_STAMP_RE, HISTORY_DIR, HISTORY_INDEX_VERSION, MAX_RESTRUCTURE_MOVES, MIN_STAMP_BODY_CHARS, POLICY_STAGE_DEFAULTS, READ_REQUIRED_ACTIONS, RECENT_USE_WINDOW_DAYS, RESTRUCTURE_TARGET_RE, RETENTION_FEEDBACK_KEEP_RATIO, RETENTION_FEEDBACK_MIN_CHARS, RULES, SKILL_OPERATIONS, SNAPSHOT_EXTRA_NAME_RE, SkillLibrary, SkillModel, TEXT_DIFF_MAX_CHARS, TEXT_DIFF_MAX_LINES, ageCopyKey, anchorVerdict, assertSkillsRootAliasRetired, assessStructureHealth, authoringFeedback, blobPath, clipChangeSummary, compareSkillStats, computeSkillStatsTotals, contentRetentionFeedback, diffFindings, elapsedSince, ensureSkillFrontmatter, entryTarget, exceedsContentLimit, filterSkillStats, filterUnreadSkillOps, frontmatterBlock, frontmatterCatalogInvalid, historyIndexFile, historyRoot, isUnreadWrite, latestActivityAt, latestVersionAt, lintBody, lintSkill, loadVersionContent, loadVersions, markerEntryName, needsAttention, newSkillLibrary, nextHistoryIndex, normalizeChangeSummary, normalizeFrontmatter, orderVersions, parseFrontmatter, parseHistoryIndex, partitionVersions, policyStageLimits, readHistoryIndex, recentlyUsedAt, recordVersions, relatedSkillNames, resolveExecOrigins, resolveOrigins, resolveRootConfig, resolveSkillsRoot, revisionAnchor, revisionAnchorOf, revisionFingerprint, revisionSupportDigest, sessionReadSkillNames, sessionReadSupportFiles, shrinksOverLimit, skillMdOnDisk, skillRowCells, skillStateKey, skillsRoot, sortSkillStats, sortValue, summaryChars, textDiffFacts, validateFrontmatter, validateRestructureTarget, validateSupportPath, verdictRank, versionActionKind, versionRowCells, versionTarget, yamlPlainScalarNeedsQuotes };
@@ -0,0 +1,27 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ /** One family package as found in the profile. */
3
+ export interface FamilyComponent {
4
+ readonly name: string;
5
+ readonly version?: string;
6
+ }
7
+ /** The family coherence result for one profile. */
8
+ export interface FamilyCoherence {
9
+ readonly allVersion: string;
10
+ readonly components: readonly FamilyComponent[];
11
+ readonly mismatched: readonly FamilyComponent[];
12
+ }
13
+ /**
14
+ * Compare every implementation package with the installed `all` bundle.
15
+ * Missing packages count as a mismatch because the old loader would fall back
16
+ * to an unrelated copy or fail at load.
17
+ * @param profileDir - profile directory containing `package.json` and `node_modules`.
18
+ * @returns The coherence result, or undefined when the profile has no readable `all` bundle.
19
+ */
20
+ export declare function checkFamilyCoherence(profileDir: string): FamilyCoherence | undefined;
21
+ /**
22
+ * Warn once when the running profile is a mixed family install.
23
+ * @param ctx - the running host context; a bare library mount has no profile and is skipped.
24
+ * @returns The detected mismatch, or undefined when no profile/all bundle is present.
25
+ */
26
+ export declare function warnIfFamilyMixed(ctx: Context): FamilyCoherence | undefined;
27
+ //# sourceMappingURL=coherence.d.ts.map
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Family version coherence probe.
3
+ *
4
+ * A profile can contain one bundle whose implementation packages come from
5
+ * different family releases: the bundle row updates while a directly pinned
6
+ * sibling stays behind, or old hand-copied packages shadow the pnpm tree. The
7
+ * loader then runs an old client against a new host, which looks like a UI
8
+ * regression rather than a mixed install. This probe names that state at
9
+ * startup; it never repairs a live profile (a package-manager write while the
10
+ * host runs is unsafe and needs a restart).
11
+ *
12
+ * @module @lmzhen/dsh-evolution-core/runtime/coherence
13
+ */
14
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ import { profileContextPort } from "../platform/profileContext.js";
17
+ function packageTail(name) {
18
+ return name.slice(name.lastIndexOf('/') + 1);
19
+ }
20
+ /** Family implementation tails; external @deepseek-ai packages stay out. */
21
+ function isFamilyPackage(name) {
22
+ const tail = packageTail(name);
23
+ return tail.startsWith('dsh-evolution-')
24
+ || tail === 'dsh-memory'
25
+ || tail === 'dsh-memory-files'
26
+ || tail === 'dsh-skill-usage'
27
+ || tail === 'dsh-tool-memory'
28
+ || tail === 'dsh-tool-skill-manage';
29
+ }
30
+ /**
31
+ * Compare every implementation package with the installed `all` bundle.
32
+ * Missing packages count as a mismatch because the old loader would fall back
33
+ * to an unrelated copy or fail at load.
34
+ * @param profileDir - profile directory containing `package.json` and `node_modules`.
35
+ * @returns The coherence result, or undefined when the profile has no readable `all` bundle.
36
+ */
37
+ export function checkFamilyCoherence(profileDir) {
38
+ const profileManifest = join(profileDir, 'package.json');
39
+ if (!existsSync(profileManifest))
40
+ return undefined;
41
+ // Resolve ONLY inside this profile. A createRequire fallback can walk the
42
+ // test/launcher NODE_PATH and report the build tree's packages as installed,
43
+ // which would hide exactly the mixed profile this probe exists to catch.
44
+ const resolveManifest = (name) => {
45
+ const path = join(profileDir, 'node_modules', name, 'package.json');
46
+ return existsSync(path) ? path : undefined;
47
+ };
48
+ const allPath = resolveManifest('@lmzhen/dsh-evolution-all') ?? resolveManifest('@lmzhen/dsh-evolution-all');
49
+ if (allPath === undefined)
50
+ return undefined;
51
+ let all;
52
+ try {
53
+ all = JSON.parse(readFileSync(allPath, 'utf8'));
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ if (typeof all.version !== 'string')
59
+ return undefined;
60
+ const components = [];
61
+ const visited = new Set();
62
+ const queue = Object.keys(all.dependencies ?? {}).filter(isFamilyPackage);
63
+ while (queue.length > 0) {
64
+ const name = queue.shift();
65
+ if (name === undefined || visited.has(name))
66
+ continue;
67
+ visited.add(name);
68
+ const manifestPath = resolveManifest(name);
69
+ if (manifestPath === undefined) {
70
+ components.push({ name });
71
+ continue;
72
+ }
73
+ try {
74
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
75
+ components.push({ name, ...(typeof manifest.version === 'string' ? { version: manifest.version } : {}) });
76
+ // The family is a dependency graph, not only the bundle's direct list:
77
+ // client-kit arrives through evolution-ui, merge-engine through merge.
78
+ for (const child of [
79
+ ...Object.keys(manifest.dependencies ?? {}),
80
+ ...Object.keys(manifest.optionalDependencies ?? {}),
81
+ ]) {
82
+ if (isFamilyPackage(child) && !visited.has(child))
83
+ queue.push(child);
84
+ }
85
+ }
86
+ catch {
87
+ components.push({ name });
88
+ }
89
+ }
90
+ return {
91
+ allVersion: all.version,
92
+ components,
93
+ mismatched: components.filter(component => component.version !== all.version),
94
+ };
95
+ }
96
+ /**
97
+ * Warn once when the running profile is a mixed family install.
98
+ * @param ctx - the running host context; a bare library mount has no profile and is skipped.
99
+ * @returns The detected mismatch, or undefined when no profile/all bundle is present.
100
+ */
101
+ export function warnIfFamilyMixed(ctx) {
102
+ const profile = profileContextPort(ctx);
103
+ if (profile === undefined)
104
+ return undefined;
105
+ const coherence = checkFamilyCoherence(profile.dir);
106
+ if (coherence === undefined || coherence.mismatched.length === 0)
107
+ return undefined;
108
+ const details = coherence.mismatched
109
+ .map(component => `${component.name}@${component.version ?? 'missing'}`)
110
+ .join(', ');
111
+ console.warn(`[dsh-evolution] mixed family install: all@${coherence.allVersion} but ${details}; `
112
+ + 'the loaded client may be an older release. Run the profile repair in INSTALL.md before restarting.');
113
+ return coherence;
114
+ }
115
+ //# sourceMappingURL=coherence.js.map
@@ -1,3 +1,4 @@
1
+ import { warnIfFamilyMixed } from "./coherence.js";
1
2
  import { EvolutionLlm } from "./llm.js";
2
3
  import { EvolutionPlatform } from "./platform.js";
3
4
  import { EvolutionProjections } from "./projections.js";
@@ -9,5 +10,6 @@ export async function apply(ctx) {
9
10
  await ctx.plugin(EvolutionPlatform);
10
11
  await ctx.plugin(EvolutionProjections);
11
12
  await ctx.plugin(EvolutionLlm);
13
+ warnIfFamilyMixed(ctx);
12
14
  }
13
15
  //# sourceMappingURL=plugin.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * User-facing operation identities shared by the stats UI, command copy and history labels.
3
+ *
4
+ * The tool/command layers own execution; this table owns only presentation semantics. Keeping it in
5
+ * core means a UI label and a success-count key cannot drift into two spellings of the same action.
6
+ * @module @lmzhen/dsh-evolution-core
7
+ */
8
+ /** Operations that can be counted in the library summary. */
9
+ export type SkillOperationId = 'offload' | 'condense' | 'extract';
10
+ /** Where one operation belongs on the C-end surface. */
11
+ export type SkillOperationSurface = 'primary' | 'advanced' | 'hidden';
12
+ /** One operation's presentation identity; label keys resolve in the UI catalog. */
13
+ export interface SkillOperationMeta {
14
+ readonly id: SkillOperationId;
15
+ readonly labelKey: string;
16
+ readonly descriptionKey: string;
17
+ readonly kind: 'deterministic' | 'agent';
18
+ readonly surface: SkillOperationSurface;
19
+ }
20
+ /** The one operation table. Unknown ids never gain a label by accident. */
21
+ export declare const SKILL_OPERATIONS: readonly SkillOperationMeta[];
22
+ //# sourceMappingURL=skill-operations.d.ts.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * User-facing operation identities shared by the stats UI, command copy and history labels.
3
+ *
4
+ * The tool/command layers own execution; this table owns only presentation semantics. Keeping it in
5
+ * core means a UI label and a success-count key cannot drift into two spellings of the same action.
6
+ * @module @lmzhen/dsh-evolution-core
7
+ */
8
+ /** The one operation table. Unknown ids never gain a label by accident. */
9
+ export const SKILL_OPERATIONS = Object.freeze([
10
+ {
11
+ id: 'offload',
12
+ labelKey: 'operation.offload.label',
13
+ descriptionKey: 'operation.offload.description',
14
+ kind: 'deterministic',
15
+ surface: 'advanced',
16
+ },
17
+ {
18
+ id: 'condense',
19
+ labelKey: 'operation.condense.label',
20
+ descriptionKey: 'operation.condense.description',
21
+ kind: 'agent',
22
+ surface: 'advanced',
23
+ },
24
+ {
25
+ id: 'extract',
26
+ labelKey: 'operation.extract.label',
27
+ descriptionKey: 'operation.extract.description',
28
+ kind: 'agent',
29
+ surface: 'advanced',
30
+ },
31
+ ]);
32
+ //# sourceMappingURL=skill-operations.js.map
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * @module @lmzhen/dsh-evolution-core
12
12
  */
13
+ import type { SkillOperationId } from './skill-operations.ts';
13
14
  /** One health dimension the aggregate view exposes for a skill. */
14
15
  export interface SkillHealthFacts {
15
16
  readonly verdict: string;
@@ -40,13 +41,25 @@ export interface SkillUsageFacts {
40
41
  readonly state: string | null;
41
42
  readonly pinned: boolean | null;
42
43
  }
44
+ /** Human-facing "最近使用" window; one constant so host and tests cannot drift. */
45
+ export declare const RECENT_USE_WINDOW_DAYS = 30;
46
+ /** Newest model load / external use timestamp, or null when neither was measured. */
47
+ export declare function latestActivityAt(usage: SkillUsageFacts | null): string | null;
48
+ /** Whether an activity timestamp is inside the use window; null when no activity was measured. */
49
+ export declare function recentlyUsedAt(lastActivityAtValue: string | null, now?: Date): boolean | null;
43
50
  /** One row of the full skill table. */
44
51
  export interface SkillStatsRow {
45
52
  readonly name: string;
46
53
  readonly description: string;
47
54
  readonly versions: number;
48
- /** Last content change, or null when the skill has no recorded versions. */
49
- readonly lastAt: string | null;
55
+ /** Canonical last content change. */
56
+ readonly lastChangedAt: string | null;
57
+ /** Newest model load / external use; null when neither timestamp was measured. */
58
+ readonly lastActivityAt: string | null;
59
+ /** True when lastActivityAt is inside the 30-day use window; null when no activity was measured. */
60
+ readonly recentlyUsed: boolean | null;
61
+ /** Server-derived actionable verdict; the browser must not re-derive it. */
62
+ readonly needsAttention: boolean;
50
63
  readonly health: SkillHealthFacts | null;
51
64
  readonly usage: SkillUsageFacts | null;
52
65
  readonly feedback: number | null;
@@ -82,12 +95,22 @@ export interface SkillStatsGovernance {
82
95
  readonly mode: string | null;
83
96
  readonly resultRef: string | null;
84
97
  }
85
- /** One complete read of the skill library, as the host route returns it. */
86
- export interface SkillStatsSnapshot {
87
- readonly rows: readonly SkillStatsRow[];
98
+ /** Library-wide facts. These never belong in a single-skill detail view. */
99
+ export interface SkillStatsGlobal {
88
100
  readonly totals: SkillStatsTotals;
89
101
  readonly counts: SkillStatsCounts | null;
90
102
  readonly governance: readonly SkillStatsGovernance[];
103
+ /** Label keys for the three success counters; the browser never imports core runtime. */
104
+ readonly operations?: readonly {
105
+ readonly id: SkillOperationId;
106
+ readonly labelKey: string;
107
+ }[];
108
+ }
109
+ /** One complete read of the skill library, as the host route returns it. */
110
+ export interface SkillStatsSnapshot {
111
+ readonly rows: readonly SkillStatsRow[];
112
+ /** Library-wide facts live here, never in a single-skill detail view. */
113
+ readonly global: SkillStatsGlobal;
91
114
  readonly generatedAt: string;
92
115
  }
93
116
  /** Sortable columns the table exposes. */
@@ -10,10 +10,37 @@
10
10
  *
11
11
  * @module @lmzhen/dsh-evolution-core
12
12
  */
13
+ /** Human-facing "最近使用" window; one constant so host and tests cannot drift. */
14
+ export const RECENT_USE_WINDOW_DAYS = 30;
15
+ /** Newest model load / external use timestamp, or null when neither was measured. */
16
+ export function latestActivityAt(usage) {
17
+ let best = null;
18
+ let bestMs = Number.NEGATIVE_INFINITY;
19
+ for (const value of [usage?.lastUsedAt ?? null, usage?.lastViewedAt ?? null]) {
20
+ if (value === null)
21
+ continue;
22
+ const ms = Date.parse(value);
23
+ if (!Number.isFinite(ms))
24
+ continue;
25
+ if (ms > bestMs) {
26
+ best = value;
27
+ bestMs = ms;
28
+ }
29
+ }
30
+ return best;
31
+ }
32
+ /** Whether an activity timestamp is inside the use window; null when no activity was measured. */
33
+ export function recentlyUsedAt(lastActivityAtValue, now = new Date()) {
34
+ if (lastActivityAtValue === null)
35
+ return null;
36
+ const ms = Date.parse(lastActivityAtValue);
37
+ if (!Number.isFinite(ms))
38
+ return null;
39
+ return ms >= now.getTime() - RECENT_USE_WINDOW_DAYS * 86_400_000;
40
+ }
13
41
  /** A verdict that asks the user to act; `healthy` and `unknown` do not. */
14
42
  export function needsAttention(row) {
15
- const verdict = row.health?.verdict;
16
- return verdict === 'warn' || verdict === 'needs-restructure';
43
+ return row.needsAttention;
17
44
  }
18
45
  /** Severity order for the status column: actionable first, healthy last. */
19
46
  export function verdictRank(verdict) {
@@ -48,7 +75,7 @@ export function sortValue(row, key) {
48
75
  case 'feedback30d': return row.feedback30d;
49
76
  case 'negativeFeedback30d': return row.negativeFeedback30d;
50
77
  case 'feedbackRate30d': return row.feedbackRate30d;
51
- case 'lastAt': return row.lastAt === null ? null : Date.parse(row.lastAt);
78
+ case 'lastAt': return row.lastChangedAt === null ? null : Date.parse(row.lastChangedAt);
52
79
  }
53
80
  }
54
81
  /**
@@ -82,7 +109,7 @@ export function filterSkillStats(rows, filter) {
82
109
  return [...rows];
83
110
  if (filter === 'attention')
84
111
  return rows.filter(needsAttention);
85
- return rows.filter(row => row.lastAt !== null);
112
+ return rows.filter(row => row.recentlyUsed === true);
86
113
  }
87
114
  /** Sum a nullable numeric column: all-null means the total itself is unknown, not zero. */
88
115
  function sumNullable(values) {
@@ -2,6 +2,7 @@
2
2
  export * from './skill-lint.ts';
3
3
  export * from './skill-health.ts';
4
4
  export * from './skill-stats.ts';
5
+ export * from './skill-operations.ts';
5
6
  export * from './skill-reads.ts';
6
7
  export * from './skill-row-cells.ts';
7
8
  export * from './skill-history.ts';
@@ -2,6 +2,7 @@
2
2
  export * from "./skill-lint.js";
3
3
  export * from "./skill-health.js";
4
4
  export * from "./skill-stats.js";
5
+ export * from "./skill-operations.js";
5
6
  export * from "./skill-reads.js";
6
7
  export * from "./skill-row-cells.js";
7
8
  export * from "./skill-history.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.52.0",
4
+ "version": "0.54.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },