@khanglvm/outline-cli 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 - 2026-07-21
4
+
5
+ - Changes since `v0.2.0`.
6
+ - fix(memory): recover malformed observation cache (e9ec821)
7
+
3
8
  ## 0.2.0 - 2026-06-23
4
9
 
5
10
  - Changes since `v0.1.8`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanglvm/outline-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Agent-optimized CLI for Outline API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,8 +3,8 @@ export const ENTRY_INTEGRITY_MANIFEST = Object.freeze({
3
3
  version: 1,
4
4
  algorithm: "sha256",
5
5
  signatureAlgorithm: "sha256-salted-manifest-v1",
6
- signature: "40638ba4d3f763d584f68234f135e58af065f6cb019257ea0a051dc10010e39a",
7
- generatedAt: "2026-06-23T00:27:13.815Z",
6
+ signature: "c282b3ac3eb71f8543fc1666f780d828853b310203f4fe80f02a5c22cdb925a3",
7
+ generatedAt: "2026-07-21T09:09:21.194Z",
8
8
  files: [
9
9
  {
10
10
  "path": "src/action-gate.js",
@@ -32,7 +32,7 @@ export const ENTRY_INTEGRITY_MANIFEST = Object.freeze({
32
32
  },
33
33
  {
34
34
  "path": "src/memory-store.js",
35
- "sha256": "1bd1ce5c06d3f7a83c28be4c9fd691a5c92d1267a92d97667e966c30f8055152"
35
+ "sha256": "591b0240d9fa0a4645bb9d1f5d875c9a10e7211862731cc2d7ca75a9092afdb5"
36
36
  },
37
37
  {
38
38
  "path": "src/outline-client.js",
@@ -9,6 +9,8 @@ import { compactValue, ensureStringArray, mapLimit, toInteger } from "./utils.js
9
9
  const STORE_VERSION = 1;
10
10
  const DEFAULT_MAX_ENTRIES_PER_PROFILE = 1000;
11
11
  const MAX_SOURCE_TOOLS = 8;
12
+ const UNRECOVERABLE_STORE = Symbol("unrecoverableMemoryStore");
13
+ let saveSequence = 0;
12
14
  const OBSERVED_TOOL_PREFIXES = [
13
15
  "documents.",
14
16
  "collections.",
@@ -36,31 +38,112 @@ function blankStore() {
36
38
  };
37
39
  }
38
40
 
39
- async function loadStore(file = defaultMemoryFile()) {
40
- try {
41
- const raw = await fs.readFile(file, "utf8");
42
- const parsed = JSON.parse(raw);
43
- if (!parsed || typeof parsed !== "object") {
44
- return blankStore();
41
+ function normalizeStore(parsed) {
42
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
43
+ return blankStore();
44
+ }
45
+ if (!parsed.profiles || typeof parsed.profiles !== "object" || Array.isArray(parsed.profiles)) {
46
+ parsed.profiles = {};
47
+ }
48
+ if (!parsed.version) {
49
+ parsed.version = STORE_VERSION;
50
+ }
51
+ return parsed;
52
+ }
53
+
54
+ function parseLeadingStore(raw) {
55
+ let start = 0;
56
+ while (start < raw.length && /\s/.test(raw[start])) {
57
+ start += 1;
58
+ }
59
+ if (raw[start] !== "{") {
60
+ return null;
61
+ }
62
+
63
+ let depth = 0;
64
+ let inString = false;
65
+ let escaped = false;
66
+ for (let index = start; index < raw.length; index += 1) {
67
+ const char = raw[index];
68
+ if (inString) {
69
+ if (escaped) {
70
+ escaped = false;
71
+ } else if (char === "\\") {
72
+ escaped = true;
73
+ } else if (char === '"') {
74
+ inString = false;
75
+ }
76
+ continue;
77
+ }
78
+ if (char === '"') {
79
+ inString = true;
80
+ continue;
81
+ }
82
+ if (char === "{" || char === "[") {
83
+ depth += 1;
84
+ continue;
85
+ }
86
+ if (char !== "}" && char !== "]") {
87
+ continue;
45
88
  }
46
- if (!parsed.profiles || typeof parsed.profiles !== "object") {
47
- parsed.profiles = {};
89
+ depth -= 1;
90
+ if (depth !== 0) {
91
+ continue;
48
92
  }
49
- if (!parsed.version) {
50
- parsed.version = STORE_VERSION;
93
+
94
+ const trailing = raw.slice(index + 1);
95
+ if (!trailing.trim()) {
96
+ return null;
51
97
  }
52
- return parsed;
98
+ try {
99
+ return normalizeStore(JSON.parse(raw.slice(start, index + 1)));
100
+ } catch {
101
+ return null;
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+
107
+ async function loadStore(file = defaultMemoryFile()) {
108
+ let raw;
109
+ try {
110
+ raw = await fs.readFile(file, "utf8");
53
111
  } catch (err) {
54
112
  if (err?.code === "ENOENT") {
55
113
  return blankStore();
56
114
  }
57
115
  throw new Error(`Failed to read memory store ${file}: ${err.message}`);
58
116
  }
117
+
118
+ try {
119
+ return normalizeStore(JSON.parse(raw));
120
+ } catch (err) {
121
+ const recovered = parseLeadingStore(raw);
122
+ if (recovered) {
123
+ return recovered;
124
+ }
125
+ const fallback = blankStore();
126
+ Object.defineProperty(fallback, UNRECOVERABLE_STORE, {
127
+ value: err.message,
128
+ });
129
+ return fallback;
130
+ }
59
131
  }
60
132
 
61
133
  async function saveStore(store, file = defaultMemoryFile()) {
134
+ if (store[UNRECOVERABLE_STORE]) {
135
+ throw new Error(
136
+ `Refusing to overwrite malformed memory store ${file}: ${store[UNRECOVERABLE_STORE]}`,
137
+ );
138
+ }
62
139
  await fs.mkdir(path.dirname(file), { recursive: true });
63
- await fs.writeFile(file, `${JSON.stringify(store, null, 2)}\n`, { mode: 0o600 });
140
+ const tempFile = `${file}.${process.pid}.${saveSequence += 1}.tmp`;
141
+ try {
142
+ await fs.writeFile(tempFile, `${JSON.stringify(store, null, 2)}\n`, { mode: 0o600 });
143
+ await fs.rename(tempFile, file);
144
+ } finally {
145
+ await fs.rm(tempFile, { force: true });
146
+ }
64
147
  }
65
148
 
66
149
  function profileBucket(store, profileId) {