@lmzhen/dsh-evolution-core 0.52.0 → 0.53.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.
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,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.53.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },