dsh-mnemon-source-runtime 0.5.13 → 0.5.14

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.
@@ -0,0 +1,32 @@
1
+ //#region src/defaults.ts
2
+ const DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES = 10240;
3
+ const DEFAULT_RUNTIME_USER_LIMIT_BYTES = 4096;
4
+ const MAX_RUNTIME_MEMORY_LIMIT_BYTES = 1048576;
5
+ //#endregion
6
+ //#region src/contracts.ts
7
+ const RUNTIME_MEMORY_VERSION = 1;
8
+ const RUNTIME_ENTRY_DELIMITER = "\n§\n";
9
+ const RUNTIME_MEMORY_LIMITS = {
10
+ memory: DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES,
11
+ user: DEFAULT_RUNTIME_USER_LIMIT_BYTES
12
+ };
13
+ /** The longest git branch name a scope may hold. */
14
+ const RUNTIME_BRANCH_NAME_MAX = 128;
15
+ /** The characters a git branch name in a scope may use. */
16
+ const RUNTIME_BRANCH_NAME_PATTERN = /^[A-Za-z0-9._/-]+$/u;
17
+ /**
18
+ * Read a stored branch scope. Absent or malformed data reads as no scope, so an entry that
19
+ * a hand edit or another installation left malformed is projected on every branch instead
20
+ * of breaking the projection that reads it.
21
+ */
22
+ function parseRuntimeBranches(value) {
23
+ if (!Array.isArray(value)) return void 0;
24
+ const branches = [];
25
+ for (const item of value) {
26
+ if (typeof item !== "string" || item === "" || item.length > 128 || !RUNTIME_BRANCH_NAME_PATTERN.test(item)) return void 0;
27
+ branches.push(item);
28
+ }
29
+ return branches;
30
+ }
31
+ //#endregion
32
+ export { RUNTIME_MEMORY_VERSION as a, DEFAULT_RUNTIME_USER_LIMIT_BYTES as c, RUNTIME_MEMORY_LIMITS as i, MAX_RUNTIME_MEMORY_LIMIT_BYTES as l, RUNTIME_BRANCH_NAME_PATTERN as n, parseRuntimeBranches as o, RUNTIME_ENTRY_DELIMITER as r, DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES as s, RUNTIME_BRANCH_NAME_MAX as t };
@@ -2,6 +2,12 @@
2
2
  type RuntimeMemoryTarget = 'memory' | 'user';
3
3
  type RuntimeMemoryImportance = 'critical' | 'normal' | 'low';
4
4
  type RuntimeMemoryAction = 'add' | 'replace' | 'remove';
5
+ /** Provenance a DSH Host stamps when an entry crosses machines; absent for local writes. */
6
+ interface RuntimeMemoryEntryOrigin {
7
+ machine: string;
8
+ label: string;
9
+ at: string;
10
+ }
5
11
  interface RuntimeMemoryEntry {
6
12
  content: string;
7
13
  created_at: string;
@@ -10,6 +16,8 @@ interface RuntimeMemoryEntry {
10
16
  importance: RuntimeMemoryImportance;
11
17
  /** Optional git branch names that limit where this entry is projected. Absent means every branch. */
12
18
  branches?: string[];
19
+ /** Which installation wrote this entry, so a merge can tell two machines apart. */
20
+ origin?: RuntimeMemoryEntryOrigin;
13
21
  }
14
22
  interface RuntimeMemoryUsage {
15
23
  used: number;
@@ -89,5 +97,15 @@ interface RuntimeMemoryLimits {
89
97
  readonly user: number;
90
98
  }
91
99
  declare const RUNTIME_MEMORY_LIMITS: RuntimeMemoryLimits;
100
+ /** The longest git branch name a scope may hold. */
101
+ declare const RUNTIME_BRANCH_NAME_MAX = 128;
102
+ /** The characters a git branch name in a scope may use. */
103
+ declare const RUNTIME_BRANCH_NAME_PATTERN: RegExp;
104
+ /**
105
+ * Read a stored branch scope. Absent or malformed data reads as no scope, so an entry that
106
+ * a hand edit or another installation left malformed is projected on every branch instead
107
+ * of breaking the projection that reads it.
108
+ */
109
+ declare function parseRuntimeBranches(value: unknown): string[] | undefined;
92
110
  //#endregion
93
- export { RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION, RuntimeMemoryAction, RuntimeMemoryCompactedEntry, RuntimeMemoryEntry, RuntimeMemoryImportance, RuntimeMemoryLimits, RuntimeMemoryMaintenancePlan, RuntimeMemoryMutation, RuntimeMemoryMutationResult, RuntimeMemorySnapshot, RuntimeMemoryTarget, RuntimeMemoryTargetView, RuntimeMemoryUsage };
111
+ export { RUNTIME_BRANCH_NAME_MAX, RUNTIME_BRANCH_NAME_PATTERN, RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION, RuntimeMemoryAction, RuntimeMemoryCompactedEntry, RuntimeMemoryEntry, RuntimeMemoryEntryOrigin, RuntimeMemoryImportance, RuntimeMemoryLimits, RuntimeMemoryMaintenancePlan, RuntimeMemoryMutation, RuntimeMemoryMutationResult, RuntimeMemorySnapshot, RuntimeMemoryTarget, RuntimeMemoryTargetView, RuntimeMemoryUsage, parseRuntimeBranches };
package/lib/contracts.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as RUNTIME_MEMORY_LIMITS, r as RUNTIME_MEMORY_VERSION, t as RUNTIME_ENTRY_DELIMITER } from "./contracts-BqaPCrGD.js";
2
- export { RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION };
1
+ import { a as RUNTIME_MEMORY_VERSION, i as RUNTIME_MEMORY_LIMITS, n as RUNTIME_BRANCH_NAME_PATTERN, o as parseRuntimeBranches, r as RUNTIME_ENTRY_DELIMITER, t as RUNTIME_BRANCH_NAME_MAX } from "./contracts-B6vRCw3C.js";
2
+ export { RUNTIME_BRANCH_NAME_MAX, RUNTIME_BRANCH_NAME_PATTERN, RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION, parseRuntimeBranches };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION, RuntimeMemoryAction, RuntimeMemoryCompactedEntry, RuntimeMemoryEntry, RuntimeMemoryImportance, RuntimeMemoryLimits, RuntimeMemoryMaintenancePlan, RuntimeMemoryMutation, RuntimeMemoryMutationResult, RuntimeMemorySnapshot, RuntimeMemoryTarget, RuntimeMemoryTargetView, RuntimeMemoryUsage } from "./contracts.js";
1
+ import { RUNTIME_BRANCH_NAME_MAX, RUNTIME_BRANCH_NAME_PATTERN, RUNTIME_ENTRY_DELIMITER, RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_VERSION, RuntimeMemoryAction, RuntimeMemoryCompactedEntry, RuntimeMemoryEntry, RuntimeMemoryEntryOrigin, RuntimeMemoryImportance, RuntimeMemoryLimits, RuntimeMemoryMaintenancePlan, RuntimeMemoryMutation, RuntimeMemoryMutationResult, RuntimeMemorySnapshot, RuntimeMemoryTarget, RuntimeMemoryTargetView, RuntimeMemoryUsage, parseRuntimeBranches } from "./contracts.js";
2
2
  import z from "@deepseek-ai/schemastery";
3
3
  import { MemorySourceDefinition } from "dsh-mnemon/contracts";
4
4
  import { Context } from "@deepseek-ai/cordis";
@@ -21,4 +21,4 @@ declare const inject: string[];
21
21
  declare const memoryPlugin: import("dsh-mnemon/extension-sdk").MemoryPluginDescriptor;
22
22
  declare function apply(ctx: Context, config?: Config): void;
23
23
  //#endregion
24
- export { Config, type RUNTIME_ENTRY_DELIMITER, type RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_SOURCE, type RUNTIME_MEMORY_VERSION, type RuntimeMemoryAction, type RuntimeMemoryCompactedEntry, type RuntimeMemoryEntry, type RuntimeMemoryImportance, type RuntimeMemoryLimits, type RuntimeMemoryMaintenancePlan, type RuntimeMemoryMutation, type RuntimeMemoryMutationResult, type RuntimeMemorySnapshot, type RuntimeMemoryTarget, type RuntimeMemoryTargetView, type RuntimeMemoryUsage, apply, createRuntimeMemorySource, inject, memoryPlugin, name };
24
+ export { Config, type RUNTIME_BRANCH_NAME_MAX, type RUNTIME_BRANCH_NAME_PATTERN, type RUNTIME_ENTRY_DELIMITER, type RUNTIME_MEMORY_LIMITS, RUNTIME_MEMORY_SOURCE, type RUNTIME_MEMORY_VERSION, type RuntimeMemoryAction, type RuntimeMemoryCompactedEntry, type RuntimeMemoryEntry, type RuntimeMemoryEntryOrigin, type RuntimeMemoryImportance, type RuntimeMemoryLimits, type RuntimeMemoryMaintenancePlan, type RuntimeMemoryMutation, type RuntimeMemoryMutationResult, type RuntimeMemorySnapshot, type RuntimeMemoryTarget, type RuntimeMemoryTargetView, type RuntimeMemoryUsage, apply, createRuntimeMemorySource, inject, memoryPlugin, name, type parseRuntimeBranches };
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as RUNTIME_MEMORY_LIMITS, o as MAX_RUNTIME_MEMORY_LIMIT_BYTES, t as RUNTIME_ENTRY_DELIMITER } from "./contracts-BqaPCrGD.js";
1
+ import { i as RUNTIME_MEMORY_LIMITS, l as MAX_RUNTIME_MEMORY_LIMIT_BYTES, n as RUNTIME_BRANCH_NAME_PATTERN, o as parseRuntimeBranches, r as RUNTIME_ENTRY_DELIMITER } from "./contracts-B6vRCw3C.js";
2
2
  import { createMemoryMutationReceipt, defineMemoryPlugin, defineMemorySource, installMemory, memoryConfigurationDigest, memoryInputRecord, memoryInputStringArray, memoryInputText, truncateMemoryText } from "dsh-mnemon/extension-sdk";
3
3
  import { homedir } from "node:os";
4
4
  import { basename, isAbsolute, join } from "node:path";
@@ -34,6 +34,19 @@ const GIT_BRANCH_TIMEOUT_MS = 2e3;
34
34
  * the directory is not a git working tree, HEAD is detached, or the probe
35
35
  * fails or times out, so callers fall back to the unfiltered view.
36
36
  */
37
+ /**
38
+ * Git takes the repository location from the environment, so a launcher that
39
+ * exports `GIT_DIR` for its own reasons would point this probe at a directory
40
+ * that is not the workspace. The probe runs with those variables removed.
41
+ */
42
+ function gitEnvironment(environment = process.env) {
43
+ const sanitized = {};
44
+ for (const [name, value] of Object.entries(environment)) {
45
+ if (value === void 0 || name.toUpperCase().startsWith("GIT_")) continue;
46
+ sanitized[name] = value;
47
+ }
48
+ return sanitized;
49
+ }
37
50
  function resolveGitBranch(cwd) {
38
51
  const root = cwd?.trim();
39
52
  if (root === void 0 || root === "") return void 0;
@@ -51,7 +64,8 @@ function resolveGitBranch(cwd) {
51
64
  "pipe",
52
65
  "ignore"
53
66
  ],
54
- windowsHide: true
67
+ windowsHide: true,
68
+ env: gitEnvironment()
55
69
  }).trim();
56
70
  return branch === "" ? void 0 : branch;
57
71
  } catch {
@@ -105,7 +119,6 @@ function isTarget(value) {
105
119
  function isImportance(value) {
106
120
  return value === "critical" || value === "normal" || value === "low";
107
121
  }
108
- const RUNTIME_BRANCH_NAME_RE = /^[A-Za-z0-9._/-]+$/u;
109
122
  /** Validate a model-supplied branch scope. Returns the normalized list; an empty list means "no scope". */
110
123
  function normalizeRuntimeBranches(value, field = "branches") {
111
124
  if (!Array.isArray(value)) throw new Error(`${field} must be an array of git branch names`);
@@ -114,7 +127,7 @@ function normalizeRuntimeBranches(value, field = "branches") {
114
127
  for (const item of value) {
115
128
  if (typeof item !== "string") throw new Error(`${field} must contain only git branch names`);
116
129
  const branch = item.trim();
117
- if (branch === "" || branch.length > 128 || !RUNTIME_BRANCH_NAME_RE.test(branch) || branch === "-" || branch.startsWith("/") || branch.startsWith("-") || branch.endsWith("/") || branch.endsWith(".") || branch.includes("..") || branch.includes("//") || branch.includes("@{")) throw new Error(`${field} must contain git branch names (letters, numbers, dot, underscore, slash, dash)`);
130
+ if (branch === "" || branch.length > 128 || !RUNTIME_BRANCH_NAME_PATTERN.test(branch) || branch === "-" || branch.startsWith("/") || branch.startsWith("-") || branch.endsWith("/") || branch.endsWith(".") || branch.includes("..") || branch.includes("//") || branch.includes("@{")) throw new Error(`${field} must contain git branch names (letters, numbers, dot, underscore, slash, dash)`);
118
131
  if (seen.has(branch)) throw new Error(`${field} must not repeat a branch name`);
119
132
  seen.add(branch);
120
133
  branches.push(branch);
@@ -122,17 +135,6 @@ function normalizeRuntimeBranches(value, field = "branches") {
122
135
  if (branches.length > 16) throw new Error(`${field} supports at most 16 branch names`);
123
136
  return branches;
124
137
  }
125
- /** Parse a stored branch scope. Returns undefined for absent or invalid data. */
126
- function parseRuntimeBranches(value) {
127
- if (value === void 0) return void 0;
128
- if (!Array.isArray(value)) return void 0;
129
- const branches = [];
130
- for (const item of value) {
131
- if (typeof item !== "string" || item === "" || item.length > 128 || !RUNTIME_BRANCH_NAME_RE.test(item)) return void 0;
132
- branches.push(item);
133
- }
134
- return branches;
135
- }
136
138
  function entryMatchesBranch(entry, branch) {
137
139
  return entry.branches === void 0 || entry.branches.length === 0 || entry.branches.includes(branch);
138
140
  }
@@ -148,6 +150,15 @@ function normalizeContent(value, field) {
148
150
  if (bytes > MAX_ENTRY_BYTES) throw new Error(`${field} is too large (${bytes} bytes; max ${MAX_ENTRY_BYTES})`);
149
151
  return content;
150
152
  }
153
+ function parseOrigin(value) {
154
+ if (!isRecord(value)) return void 0;
155
+ if (typeof value.machine !== "string" || typeof value.label !== "string" || typeof value.at !== "string") return void 0;
156
+ return {
157
+ machine: value.machine,
158
+ label: value.label,
159
+ at: value.at
160
+ };
161
+ }
151
162
  function parseEntry(value) {
152
163
  if (!isRecord(value) || typeof value.content !== "string" || !isTarget(value.target) || !isImportance(value.importance)) return void 0;
153
164
  if (typeof value.created_at !== "string" || typeof value.updated_at !== "string") return void 0;
@@ -155,13 +166,15 @@ function parseEntry(value) {
155
166
  if (content === "" || content.includes("§")) return void 0;
156
167
  if (value.target === "user" && value.branches !== void 0) return void 0;
157
168
  const branches = parseRuntimeBranches(value.branches);
169
+ const origin = parseOrigin(value.origin);
158
170
  return {
159
171
  content,
160
172
  created_at: value.created_at,
161
173
  updated_at: value.updated_at,
162
174
  target: value.target,
163
175
  importance: value.importance,
164
- ...branches === void 0 ? {} : { branches }
176
+ ...branches === void 0 ? {} : { branches },
177
+ ...origin === void 0 ? {} : { origin }
165
178
  };
166
179
  }
167
180
  function byteCount(entries, target) {
@@ -1,6 +1,12 @@
1
1
  export type RuntimeMemoryTarget = 'memory' | 'user';
2
2
  export type RuntimeMemoryImportance = 'critical' | 'normal' | 'low';
3
3
  export type RuntimeMemoryAction = 'add' | 'replace' | 'remove';
4
+ /** Provenance a DSH Host stamps when an entry crosses machines; absent for local writes. */
5
+ export interface RuntimeMemoryEntryOrigin {
6
+ machine: string;
7
+ label: string;
8
+ at: string;
9
+ }
4
10
  export interface RuntimeMemoryEntry {
5
11
  content: string;
6
12
  created_at: string;
@@ -9,6 +15,8 @@ export interface RuntimeMemoryEntry {
9
15
  importance: RuntimeMemoryImportance;
10
16
  /** Optional git branch names that limit where this entry is projected. Absent means every branch. */
11
17
  branches?: string[];
18
+ /** Which installation wrote this entry, so a merge can tell two machines apart. */
19
+ origin?: RuntimeMemoryEntryOrigin;
12
20
  }
13
21
  export interface RuntimeMemoryUsage {
14
22
  used: number;
@@ -88,3 +96,13 @@ export interface RuntimeMemoryLimits {
88
96
  readonly user: number;
89
97
  }
90
98
  export declare const RUNTIME_MEMORY_LIMITS: RuntimeMemoryLimits;
99
+ /** The longest git branch name a scope may hold. */
100
+ export declare const RUNTIME_BRANCH_NAME_MAX = 128;
101
+ /** The characters a git branch name in a scope may use. */
102
+ export declare const RUNTIME_BRANCH_NAME_PATTERN: RegExp;
103
+ /**
104
+ * Read a stored branch scope. Absent or malformed data reads as no scope, so an entry that
105
+ * a hand edit or another installation left malformed is projected on every branch instead
106
+ * of breaking the projection that reads it.
107
+ */
108
+ export declare function parseRuntimeBranches(value: unknown): string[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-source-runtime",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "Self-contained runtime Source for Composable View Memory.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -60,7 +60,7 @@
60
60
  "@types/node": "^22.0.0",
61
61
  "@types/react": "^18.3.0",
62
62
  "@types/react-dom": "^18.3.0",
63
- "dsh-mnemon": "^0.5.25",
63
+ "dsh-mnemon": "^0.5.26",
64
64
  "jsdom": "^26.0.0",
65
65
  "react": "^18.2.0",
66
66
  "react-dom": "^18.2.0",
@@ -1,14 +0,0 @@
1
- //#region src/defaults.ts
2
- const DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES = 10240;
3
- const DEFAULT_RUNTIME_USER_LIMIT_BYTES = 4096;
4
- const MAX_RUNTIME_MEMORY_LIMIT_BYTES = 1048576;
5
- //#endregion
6
- //#region src/contracts.ts
7
- const RUNTIME_MEMORY_VERSION = 1;
8
- const RUNTIME_ENTRY_DELIMITER = "\n§\n";
9
- const RUNTIME_MEMORY_LIMITS = {
10
- memory: DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES,
11
- user: DEFAULT_RUNTIME_USER_LIMIT_BYTES
12
- };
13
- //#endregion
14
- export { DEFAULT_RUNTIME_USER_LIMIT_BYTES as a, DEFAULT_RUNTIME_MEMORY_LIMIT_BYTES as i, RUNTIME_MEMORY_LIMITS as n, MAX_RUNTIME_MEMORY_LIMIT_BYTES as o, RUNTIME_MEMORY_VERSION as r, RUNTIME_ENTRY_DELIMITER as t };