@openviking/openclaw-plugin 2026.10.23 → 2026.10.26

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.
@@ -1,339 +0,0 @@
1
- // GENERATED FROM examples/memory-plugin-shared/lib. DO NOT EDIT.
2
- /**
3
- * Workspace identity: where the workspace root is, and what git calls it.
4
- *
5
- * Every hook is a fresh Node process and this runs on prompt-level paths, so
6
- * the derivation is pure filesystem work — no `git` subprocess. That keeps it
7
- * inside the tightest hook budget (Codex allows SessionEnd 3s against
8
- * SessionStart's 70s), and it keeps working where git is absent from PATH or
9
- * would refuse the repo over dubious ownership.
10
- *
11
- * The result is cached per cwd under the state dir so the several hooks of one
12
- * turn pay for the walk once.
13
- */
14
- import { createHash } from "node:crypto";
15
- import { mkdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
16
- import { homedir } from "node:os";
17
- import { dirname, isAbsolute, join, parse, resolve, sep } from "node:path";
18
- // The workspace config file names live here, and `workspace-config.mjs`
19
- // re-exports them: the walk below needs the filenames to recognise a directory
20
- // someone marked as a workspace, and it must not pull in the config layer to
21
- // learn them.
22
- export const CONFIG_DIR_NAME = ".openviking";
23
- export const TEAM_FILE = "config.json";
24
- export const LOCAL_FILE = "config.local.json";
25
- const IDENTITY_CACHE_TTL_MS = 60_000;
26
- // 255 is the AGFS path-segment limit; stopping well short leaves room for the
27
- // hash suffix and for anything that later prefixes a peer id.
28
- const MAX_PEER_ID_LENGTH = 100;
29
- export function stateDir(env = process.env) {
30
- const explicit = String(env.OPENVIKING_STATE_DIR || "").trim();
31
- if (explicit)
32
- return explicit;
33
- const home = String(env.OPENVIKING_HOME || "").trim();
34
- const base = home ? home.replace(/^~(?=$|\/)/, homedir()) : join(homedir(), ".openviking");
35
- return join(base, "state");
36
- }
37
- function shortHash(value) {
38
- return createHash("sha256").update(String(value)).digest("hex").slice(0, 12);
39
- }
40
- /**
41
- * Legacy peer sanitation: one byte in, one byte out, no collapsing and no
42
- * trimming, so a leading `/` still becomes a leading `-`. Kept byte-exact
43
- * because `peer.source: "cwd"` and the legacy id that dual-read recomputes both
44
- * depend on it — do not "improve" it.
45
- */
46
- export function legacySanitize(value) {
47
- return String(value || "").replace(/[^A-Za-z0-9]/g, "-");
48
- }
49
- /**
50
- * Readable sanitation for values that were never path-shaped — a normalized
51
- * remote, a directory name. Mirrors the server's own `_sanitize_component`
52
- * (`openviking/ingest/peer.py:32`) so both languages agree on the id, then
53
- * enforces what `validate_identifier_part` additionally requires.
54
- */
55
- export function sanitizePeerId(value) {
56
- const raw = String(value || "").trim();
57
- let cleaned = raw.replace(/[^a-zA-Z0-9_.@-]+/g, "-").replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
58
- if (!cleaned)
59
- return "";
60
- // The server accepts at most one `@` in an identifier part.
61
- const at = cleaned.indexOf("@");
62
- if (at !== -1)
63
- cleaned = cleaned.slice(0, at + 1) + cleaned.slice(at + 1).replace(/@/g, "-");
64
- // `ext-` is the server's namespace for base64-encoded external identities,
65
- // and `__self` its operation-target sentinel. Neither is ours to occupy.
66
- if (cleaned.startsWith("ext-"))
67
- cleaned = `x-${cleaned}`;
68
- if (cleaned === "__self")
69
- cleaned = "self";
70
- if (cleaned === "." || cleaned === "..")
71
- return "";
72
- if (cleaned.length > MAX_PEER_ID_LENGTH) {
73
- cleaned = `${cleaned.slice(0, MAX_PEER_ID_LENGTH - 13).replace(/[-.]+$/, "")}-${shortHash(raw)}`;
74
- }
75
- return cleaned;
76
- }
77
- /**
78
- * Normalize a remote URL to `host/path`, lowercased.
79
- *
80
- * Both spellings of the same repo converge, and userinfo is dropped — so a
81
- * remote with an embedded token cannot leak it into a peer id. The cost of
82
- * case folding is that two repos differing only in case share one namespace on
83
- * the rare case-sensitive forge.
84
- */
85
- export function normalizeGitRemote(url) {
86
- const raw = String(url || "").trim();
87
- if (!raw)
88
- return "";
89
- // `C:\src\repo` and `C:/src/repo` are one machine's directory, not a shared
90
- // identity — and the scp pattern would happily read the drive as a host.
91
- if (/^[A-Za-z]:[\\/]/.test(raw))
92
- return "";
93
- let host = "";
94
- let path = "";
95
- const scp = /^(?:[^@/\\]+@)?([^:/\\]+):(?!\/)(.+)$/.exec(raw);
96
- if (scp && !/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(raw)) {
97
- host = scp[1];
98
- path = scp[2];
99
- }
100
- else {
101
- let parsed;
102
- try {
103
- parsed = new URL(raw);
104
- }
105
- catch {
106
- return "";
107
- }
108
- // A local clone has no stable shared identity — fall through to the path
109
- // rules instead of minting one from `file://` or a bare directory.
110
- if (parsed.protocol === "file:" || !parsed.hostname)
111
- return "";
112
- host = parsed.hostname;
113
- path = parsed.pathname;
114
- }
115
- host = host.toLowerCase().replace(/^\[|\]$/g, "");
116
- path = path.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "").toLowerCase();
117
- if (!host || !path)
118
- return "";
119
- return `${host}/${path}`;
120
- }
121
- function readFileOrEmpty(path) {
122
- try {
123
- return readFileSync(path, "utf-8");
124
- }
125
- catch {
126
- return "";
127
- }
128
- }
129
- /**
130
- * Read `[remote "origin"] url` out of a git config with a minimal INI parse.
131
- *
132
- * `include` / `includeIf` are deliberately not followed: resolving them means
133
- * more filesystem walking for a value the fallback chain already covers, so an
134
- * unreadable remote just falls through to the next template.
135
- */
136
- export function readGitRemoteUrl(commonDir, remote = "origin") {
137
- const text = readFileOrEmpty(join(commonDir, "config"));
138
- if (!text)
139
- return "";
140
- let inSection = false;
141
- for (const line of text.split("\n")) {
142
- const trimmed = line.trim();
143
- if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith(";"))
144
- continue;
145
- const section = /^\[([^\]]+)\]/.exec(trimmed);
146
- if (section) {
147
- const header = section[1].trim();
148
- // git folds section and key names to lower case but keeps a quoted
149
- // subsection exact, so `[Remote "origin"]` is the same section and
150
- // `[remote "Origin"]` is not.
151
- const quoted = /^remote\s+"(.*)"$/i.exec(header);
152
- inSection = Boolean(quoted && quoted[1] === remote);
153
- continue;
154
- }
155
- if (!inSection)
156
- continue;
157
- const pair = /^url\s*=\s*(.*)$/i.exec(trimmed);
158
- // git treats an unquoted `#` or `;` as starting a comment anywhere on the
159
- // line, so a trailing note is not part of the URL.
160
- if (pair)
161
- return pair[1].split(/[#;]/)[0].trim().replace(/^["']|["']$/g, "");
162
- }
163
- return "";
164
- }
165
- function resolveGitDir(root) {
166
- const dotGit = join(root, ".git");
167
- let stat;
168
- try {
169
- stat = statSync(dotGit);
170
- }
171
- catch {
172
- return null;
173
- }
174
- if (stat.isDirectory())
175
- return { gitDir: dotGit, commonDir: dotGit, kind: "repo" };
176
- if (!stat.isFile())
177
- return null;
178
- const pointer = /^gitdir:\s*(.+)$/m.exec(readFileOrEmpty(dotGit));
179
- if (!pointer)
180
- return null;
181
- const gitDir = resolve(root, pointer[1].trim());
182
- // `commondir` is the worktree signal, so it is read first — a repository
183
- // that merely lives under a directory called `modules` is not a submodule.
184
- const commonRef = readFileOrEmpty(join(gitDir, "commondir")).trim();
185
- const commonDir = commonRef
186
- ? (isAbsolute(commonRef) ? commonRef : resolve(gitDir, commonRef))
187
- : gitDir;
188
- // A submodule keeps its own remote under the superproject's
189
- // `.git/modules/<name>`; converging it onto the superproject would merge two
190
- // repositories that release, and are reviewed, separately. Only the segment
191
- // right after a `.git` directory means that, which is also why a worktree of
192
- // a submodule resolves here through its own commondir.
193
- const kind = /[/\\]\.git[/\\]modules[/\\]/.test(`${commonDir}${sep}`)
194
- ? "submodule"
195
- : (commonRef ? "worktree" : "repo");
196
- return { gitDir, commonDir, kind };
197
- }
198
- /** A directory the user made a workspace on purpose, by giving it a config file. */
199
- function hasWorkspaceMarker(dir) {
200
- for (const name of [TEAM_FILE, LOCAL_FILE]) {
201
- try {
202
- if (statSync(join(dir, CONFIG_DIR_NAME, name)).isFile())
203
- return true;
204
- }
205
- catch { /* not marked here */ }
206
- }
207
- return false;
208
- }
209
- const NO_ROOT = Object.freeze({ root: "", rootKind: "", git: null, gitRoot: "" });
210
- /**
211
- * Walk up from `cwd` to the nearest workspace root.
212
- *
213
- * A workspace is a git repository, or a directory someone marked as one by
214
- * creating `.openviking/config.json` (or `config.local.json`) in it. Nearest
215
- * wins. Above a marked directory the walk continues to the enclosing
216
- * repository, if any, so the git-shaped variables still resolve there.
217
- * Anything else — a scratch folder, a download, an app's per-task directory —
218
- * is not a workspace and gets no peer of its own.
219
- *
220
- * `$HOME` and the filesystem root are never workspace roots: a stray `.git`
221
- * in either would silently make every unrelated directory one workspace.
222
- */
223
- export function findWorkspaceRoot(cwd, env = process.env) {
224
- const start = String(cwd || "").trim();
225
- if (!start)
226
- return NO_ROOT;
227
- let absolute;
228
- try {
229
- // A relative `start` makes `resolve` read process.cwd(), which throws when
230
- // the directory is gone — the very case the catch below is meant to cover.
231
- absolute = resolve(start);
232
- }
233
- catch {
234
- return NO_ROOT;
235
- }
236
- // `current` and `stopAt` are compared as strings, so they must be
237
- // canonicalized together. A `$HOME` reached through a symlink plus an
238
- // unresolvable cwd would otherwise walk straight past the guard.
239
- const home = String(env.HOME || "").trim() || homedir();
240
- let current;
241
- let stopAt;
242
- try {
243
- current = realpathSync(absolute);
244
- stopAt = realpathSync(home);
245
- }
246
- catch {
247
- current = absolute;
248
- stopAt = home;
249
- }
250
- const filesystemRoot = parse(current).root;
251
- if (current === stopAt || current === filesystemRoot)
252
- return NO_ROOT;
253
- let root = "";
254
- let rootKind = "";
255
- while (current && current !== filesystemRoot && current !== stopAt) {
256
- const git = resolveGitDir(current);
257
- if (git)
258
- return { root: root || current, rootKind: rootKind || "git", git, gitRoot: current };
259
- if (!root && hasWorkspaceMarker(current)) {
260
- root = current;
261
- rootKind = "config";
262
- }
263
- const parent = dirname(current);
264
- if (parent === current)
265
- break;
266
- current = parent;
267
- }
268
- return root ? { root, rootKind, git: null, gitRoot: "" } : NO_ROOT;
269
- }
270
- function cachePath(cwd, env) {
271
- return join(stateDir(env), `ws-identity-${shortHash(cwd)}.json`);
272
- }
273
- function readCache(path, now) {
274
- try {
275
- const cached = JSON.parse(readFileSync(path, "utf-8"));
276
- // Bounded on both sides: an entry stamped in the future — a clock that ran
277
- // fast, or `Infinity` — would otherwise pin a stale identity indefinitely.
278
- if (typeof cached?.ts !== "number" || cached.ts > now || now - cached.ts > IDENTITY_CACHE_TTL_MS)
279
- return null;
280
- const identity = cached.identity;
281
- if (identity && typeof identity === "object" && identity.vars && typeof identity.vars === "object") {
282
- return identity;
283
- }
284
- }
285
- catch { /* a cold or corrupt cache just costs one walk */ }
286
- return null;
287
- }
288
- function writeCache(path, identity, now) {
289
- try {
290
- mkdirSync(dirname(path), { recursive: true });
291
- const tmp = `${path}.${process.pid}.tmp`;
292
- writeFileSync(tmp, JSON.stringify({ ts: now, identity }), { mode: 0o600 });
293
- renameSync(tmp, path);
294
- }
295
- catch { /* best effort */ }
296
- }
297
- /**
298
- * Everything the peer templates can substitute, for one cwd.
299
- *
300
- * `git_remote` and `dir` are already sanitized; `git_root` and `cwd` carry the
301
- * legacy byte-for-byte rule, because they are the two that must reproduce a
302
- * peer minted before any of this existed.
303
- */
304
- export function resolveWorkspaceIdentity({ cwd = "", env = process.env, cache = true, now = Date.now() } = {}) {
305
- const key = String(cwd || "");
306
- const path = cachePath(key, env);
307
- if (cache) {
308
- const hit = readCache(path, now);
309
- if (hit)
310
- return hit;
311
- }
312
- const { root, rootKind, git, gitRoot } = findWorkspaceRoot(key, env);
313
- // Only the normalized form is kept. The raw URL may carry a token, and this
314
- // file outlives the process — writing it here would undo the care
315
- // `normalizeGitRemote` takes to drop userinfo.
316
- const remote = git ? normalizeGitRemote(readGitRemoteUrl(git.commonDir)) : "";
317
- const identity = {
318
- cwd: key,
319
- root,
320
- rootKind,
321
- isGit: Boolean(git),
322
- gitKind: git?.kind || "",
323
- gitCommonDir: git?.commonDir || "",
324
- gitRoot,
325
- remote,
326
- vars: {
327
- git_remote: sanitizePeerId(remote),
328
- // The enclosing repository's root, which is not the workspace root when a
329
- // marker file below it won. Empty outside a repository, so the `git`
330
- // preset resolves to nothing there rather than to a bare path.
331
- git_root: git ? legacySanitize(gitRoot) : "",
332
- cwd: legacySanitize(key),
333
- dir: root ? sanitizePeerId(root.split(/[/\\]/).filter(Boolean).pop() || "") : "",
334
- },
335
- };
336
- if (cache)
337
- writeCache(path, identity, now);
338
- return identity;
339
- }
@@ -1,26 +0,0 @@
1
- // GENERATED FROM examples/memory-plugin-shared/lib. DO NOT EDIT.
2
- export type RedactTier = "off" | "standard" | "strict";
3
-
4
- export interface RedactOptions {
5
- /** One of REDACT_TIERS; anything else is normalised (unknown names mean "standard"). */
6
- tier?: string;
7
- /** Override the per-install HMAC key (tests). */
8
- key?: string | Uint8Array;
9
- /** Where the install key's state directory is looked up. */
10
- env?: Record<string, string | undefined>;
11
- /** Scannable characters per string before the rest is cut (default MAX_SCAN_CHARS). */
12
- maxChars?: number;
13
- /** A field name to scan the value under, as `keyName=value`. */
14
- keyName?: string;
15
- }
16
-
17
- export const REDACT_TIERS: readonly string[];
18
- export const DEFAULT_REDACT_TIER: "standard";
19
- export const MAX_SCAN_CHARS: number;
20
-
21
- export function normalizeRedactTier(value: unknown, fallback?: string): string;
22
- export function redactText(text: string, opts?: RedactOptions): string;
23
- export function redactPayload<T>(payload: T, opts?: RedactOptions): T;
24
- export function redactPayloads<T>(payloads: T[], opts?: RedactOptions): T[];
25
- export function loadInstallKey(opts?: { env?: Record<string, string | undefined> }): Uint8Array;
26
- export function shannonEntropy(data: string): number;