@amoree-code/ocean 1.6.2 → 1.8.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/README.md +10 -1
- package/dist/application/clients/desktop-watcher.js +234 -0
- package/dist/application/clients/opencode-plugin.js +4 -3
- package/dist/application/layout/layout-plan.js +1 -0
- package/dist/application/onboarding/steps.js +20 -1
- package/dist/infrastructure/desktop/claude-export.js +84 -0
- package/dist/infrastructure/desktop/desktop-chat.js +165 -0
- package/dist/infrastructure/desktop/indexeddb.js +158 -0
- package/dist/infrastructure/desktop/leveldb.js +247 -0
- package/dist/infrastructure/desktop/snappy.js +74 -0
- package/dist/infrastructure/process/service.js +8 -0
- package/dist/interfaces/cli/brief-command.js +17 -0
- package/dist/interfaces/cli/capture-command.js +1 -1
- package/dist/interfaces/cli/clients-command.js +15 -2
- package/dist/interfaces/cli/command-registry.js +31 -2
- package/dist/interfaces/cli/desktop-command.js +124 -0
- package/dist/interfaces/cli/distill-command.js +36 -0
- package/dist/interfaces/cli/express-command.js +18 -0
- package/dist/interfaces/cli/harvest-command.js +58 -0
- package/dist/interfaces/cli/help-command.js +34 -2
- package/dist/interfaces/cli/interests-command.js +33 -0
- package/dist/interfaces/cli/memory-command.js +37 -3
- package/dist/interfaces/cli/note-command.js +7 -0
- package/dist/interfaces/cli/setup-command.js +2 -1
- package/dist/interfaces/cli/telemetry-command.js +23 -0
- package/node_modules/@ocean/brain/dist/brain/brain-reindex.js +4 -1
- package/node_modules/@ocean/brain/dist/brain/brain-service.js +11 -1
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +73 -24
- package/node_modules/@ocean/brain/dist/memory/fact-routing.js +54 -0
- package/node_modules/@ocean/brain/dist/memory/frontmatter-flatten.js +89 -0
- package/node_modules/@ocean/brain/dist/memory/lessons.js +20 -0
- package/node_modules/@ocean/brain/dist/memory/memory-paths.js +3 -1
- package/node_modules/@ocean/brain/dist/memory/memory-review.js +19 -2
- package/node_modules/@ocean/brain/dist/memory/memory-write.js +45 -3
- package/node_modules/@ocean/brain/dist/memory/people.js +70 -0
- package/node_modules/@ocean/brain/dist/memory/routing.json +39 -0
- package/node_modules/@ocean/brain/dist/memory/session-facts.js +7 -1
- package/node_modules/@ocean/brain/dist/memory/session-promotion.js +1 -1
- package/node_modules/@ocean/brain/package.json +1 -1
- package/node_modules/@ocean/context/package.json +1 -1
- package/node_modules/@ocean/core/dist/shared/paths.js +7 -0
- package/node_modules/@ocean/core/package.json +1 -1
- package/node_modules/@ocean/loop/dist/handoff/handoff-service.js +5 -1
- package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +154 -0
- package/node_modules/@ocean/loop/dist/hooks/session-end-hook.js +1 -1
- package/node_modules/@ocean/loop/package.json +1 -1
- package/node_modules/@ocean/market/package.json +1 -1
- package/node_modules/@ocean/services/dist/brief/brief.js +218 -0
- package/node_modules/@ocean/services/dist/brief/interest-discovery.js +236 -0
- package/node_modules/@ocean/services/dist/brief/source-registry.json +35 -0
- package/node_modules/@ocean/services/dist/distill/distill.js +258 -0
- package/node_modules/@ocean/services/dist/doctor/workspace-doctor.js +129 -8
- package/node_modules/@ocean/services/dist/express/express.js +99 -0
- package/node_modules/@ocean/services/dist/harvest/harvest.js +453 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/ocean-server.js +17 -1
- package/node_modules/@ocean/services/dist/journey/telemetry.js +81 -0
- package/node_modules/@ocean/services/dist/obsidian/folder-templates.js +82 -0
- package/node_modules/@ocean/services/dist/onboarding/onboarding.js +62 -0
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +82 -28
- package/package.json +7 -7
- package/skills/core/daily-harvest/SKILL.md +72 -0
- package/skills/core/memory-review/SKILL.md +53 -0
- package/skills/core/weekly-review/SKILL.md +24 -0
- package/skills/index.json +18 -0
- package/templates/workspace/02-personal/education/study/study.base +15 -0
- package/templates/workspace/02-personal/milestones/milestones.base +14 -0
- package/templates/workspace/02-personal/people/people.base +18 -0
- package/templates/workspace/06-templates/TEMPLATES.md +12 -0
- package/templates/workspace/06-templates/capture.md +9 -0
- package/templates/workspace/06-templates/daily.md +13 -0
- package/templates/workspace/06-templates/decision.md +8 -0
- package/templates/workspace/06-templates/failure.md +13 -0
- package/templates/workspace/06-templates/intelligence.md +7 -0
- package/templates/workspace/06-templates/interest.md +13 -0
- package/templates/workspace/06-templates/lesson.md +16 -0
- package/templates/workspace/06-templates/milestone.md +10 -0
- package/templates/workspace/06-templates/note.md +8 -0
- package/templates/workspace/06-templates/person.md +15 -0
- package/templates/workspace/06-templates/session.md +10 -0
- package/templates/workspace/06-templates/solution.md +14 -0
- package/templates/workspace/06-templates/study.md +14 -0
- package/templates/workspace/07-notes/.gitkeep +0 -0
- package/templates/workspace/MANIFEST.json +14 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import v8 from "node:v8";
|
|
4
|
+
import { readLevelDb } from "./leveldb.js";
|
|
5
|
+
import { unsnappy, varint } from "./snappy.js";
|
|
6
|
+
// Chromium IndexedDB on LevelDB (T-315), read-only. Every key starts with a prefix naming the
|
|
7
|
+
// database, object store and index; index 1 holds a store's records, index 3 the blob list of a
|
|
8
|
+
// record whose value lives in a separate blob file. A value is a varint version, then either a
|
|
9
|
+
// Blink-serialized value or a wrapper: 0xFF 0x11 0x02 + raw Snappy of one, or 0xFF 0x11 0x01 +
|
|
10
|
+
// size + blob index, meaning the bytes are in that blob file. A Blink value is 0xFF + version
|
|
11
|
+
// (+ 0xFE and a 12-byte trailer from version 21), then V8's own serialization.
|
|
12
|
+
export class IndexedDbFormatError extends Error {
|
|
13
|
+
}
|
|
14
|
+
const OBJECT_STORE_DATA = 1;
|
|
15
|
+
const BLOB_ENTRY = 3;
|
|
16
|
+
const OBJECT_STORE_META = 50;
|
|
17
|
+
const WRAPPED = 0x11;
|
|
18
|
+
const WRAPPED_IN_BLOB = 0x01;
|
|
19
|
+
const WRAPPED_SNAPPY = 0x02;
|
|
20
|
+
export function keyPrefix(key) {
|
|
21
|
+
if (key.length < 4)
|
|
22
|
+
return null;
|
|
23
|
+
const first = key[0];
|
|
24
|
+
const sizes = [(first >> 5) + 1, ((first >> 2) & 7) + 1, (first & 3) + 1];
|
|
25
|
+
let pos = 1;
|
|
26
|
+
const ids = [];
|
|
27
|
+
for (const size of sizes) {
|
|
28
|
+
if (pos + size > key.length)
|
|
29
|
+
return null;
|
|
30
|
+
ids.push(key.readUIntLE(pos, size));
|
|
31
|
+
pos += size;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
database: ids[0],
|
|
35
|
+
store: ids[1],
|
|
36
|
+
index: ids[2],
|
|
37
|
+
rest: key.subarray(pos),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function utf16be(bytes) {
|
|
41
|
+
const copy = Buffer.from(bytes);
|
|
42
|
+
copy.swap16();
|
|
43
|
+
return copy.toString("utf16le");
|
|
44
|
+
}
|
|
45
|
+
// V8's serializer writes a format version; this Node may know only older ones. Version 16 is
|
|
46
|
+
// read as 15 only after a plain read fails (Desktop's Chromium writes 16, Node 22 reads up to
|
|
47
|
+
// 15); the fixture test guards that this still decodes.
|
|
48
|
+
function v8Value(bytes) {
|
|
49
|
+
if (bytes[0] !== 0xff)
|
|
50
|
+
throw new IndexedDbFormatError("no V8 header");
|
|
51
|
+
try {
|
|
52
|
+
return v8.deserialize(bytes);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (bytes[1] !== 16)
|
|
56
|
+
throw error;
|
|
57
|
+
const patched = Buffer.from(bytes);
|
|
58
|
+
patched[1] = 15;
|
|
59
|
+
return v8.deserialize(patched);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function blinkValue(bytes) {
|
|
63
|
+
if (bytes[0] !== 0xff)
|
|
64
|
+
throw new IndexedDbFormatError("no Blink header");
|
|
65
|
+
let [, pos] = varint(bytes, 1);
|
|
66
|
+
if (bytes[pos] === 0xfe)
|
|
67
|
+
pos += 13;
|
|
68
|
+
return v8Value(Buffer.from(bytes.subarray(pos)));
|
|
69
|
+
}
|
|
70
|
+
// A record's blob list: per blob, is-file flag, blob number, MIME type, then size (a plain blob)
|
|
71
|
+
// or name and modification time (a File). Only plain blobs are read.
|
|
72
|
+
export function blobNumbers(value) {
|
|
73
|
+
const numbers = [];
|
|
74
|
+
let pos = 0;
|
|
75
|
+
while (pos < value.length) {
|
|
76
|
+
const isFile = value[pos++] !== 0;
|
|
77
|
+
let number;
|
|
78
|
+
let typeChars;
|
|
79
|
+
[number, pos] = varint(value, pos);
|
|
80
|
+
[typeChars, pos] = varint(value, pos);
|
|
81
|
+
pos += typeChars * 2;
|
|
82
|
+
if (isFile)
|
|
83
|
+
throw new IndexedDbFormatError("file blobs are not read");
|
|
84
|
+
[, pos] = varint(value, pos);
|
|
85
|
+
numbers.push(number);
|
|
86
|
+
}
|
|
87
|
+
return numbers;
|
|
88
|
+
}
|
|
89
|
+
export function blobPath(blobDir, database, number) {
|
|
90
|
+
return path.join(blobDir, database.toString(16), (Math.floor(number / 256) % 256).toString(16).padStart(2, "0"), number.toString(16));
|
|
91
|
+
}
|
|
92
|
+
async function wireValue(bytes, blob, depth = 0) {
|
|
93
|
+
if (bytes[0] === 0xff && bytes[1] === WRAPPED) {
|
|
94
|
+
if (bytes[2] === WRAPPED_SNAPPY)
|
|
95
|
+
return blinkValue(unsnappy(bytes.subarray(3)));
|
|
96
|
+
if (bytes[2] === WRAPPED_IN_BLOB && depth === 0) {
|
|
97
|
+
const [, next] = varint(bytes, 3);
|
|
98
|
+
const [index] = varint(bytes, next);
|
|
99
|
+
return wireValue(await blob(index), blob, depth + 1);
|
|
100
|
+
}
|
|
101
|
+
throw new IndexedDbFormatError("unknown value wrapper");
|
|
102
|
+
}
|
|
103
|
+
return blinkValue(bytes);
|
|
104
|
+
}
|
|
105
|
+
// The decoded records of every object store whose name `wanted` accepts. A record that does not
|
|
106
|
+
// decode is counted in `skipped`, never fatal.
|
|
107
|
+
export async function readIndexedDb(leveldbDir, blobDir, wanted) {
|
|
108
|
+
const entries = await readLevelDb(leveldbDir);
|
|
109
|
+
const names = new Map();
|
|
110
|
+
const blobs = new Map();
|
|
111
|
+
const data = [];
|
|
112
|
+
for (const [id, value] of entries) {
|
|
113
|
+
const prefix = keyPrefix(Buffer.from(id, "latin1"));
|
|
114
|
+
if (!prefix || prefix.database === 0)
|
|
115
|
+
continue;
|
|
116
|
+
const { database, store, index, rest } = prefix;
|
|
117
|
+
if (store === 0 && index === 0 && rest[0] === OBJECT_STORE_META) {
|
|
118
|
+
// Metadata keys this reader does not know are passed over, never fatal.
|
|
119
|
+
const parsed = (() => {
|
|
120
|
+
try {
|
|
121
|
+
return varint(rest, 1);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
if (parsed && parsed[1] === rest.length - 1 && rest[parsed[1]] === 0)
|
|
128
|
+
names.set(`${database}/${parsed[0]}`, utf16be(value));
|
|
129
|
+
}
|
|
130
|
+
else if (store > 0 && index === BLOB_ENTRY)
|
|
131
|
+
blobs.set(`${database}/${store}/${rest.toString("latin1")}`, value);
|
|
132
|
+
else if (store > 0 && index === OBJECT_STORE_DATA)
|
|
133
|
+
data.push({ prefix, value });
|
|
134
|
+
}
|
|
135
|
+
const records = [];
|
|
136
|
+
let skipped = 0;
|
|
137
|
+
for (const { prefix, value } of data) {
|
|
138
|
+
const store = names.get(`${prefix.database}/${prefix.store}`);
|
|
139
|
+
if (store === undefined || !wanted(store))
|
|
140
|
+
continue;
|
|
141
|
+
try {
|
|
142
|
+
const [, pos] = varint(value, 0);
|
|
143
|
+
const decoded = await wireValue(Buffer.from(value.subarray(pos)), async (index) => {
|
|
144
|
+
const list = blobs.get(`${prefix.database}/${prefix.store}/${prefix.rest.toString("latin1")}`);
|
|
145
|
+
const number = list ? blobNumbers(list)[index] : undefined;
|
|
146
|
+
if (number === undefined)
|
|
147
|
+
throw new IndexedDbFormatError("missing blob entry");
|
|
148
|
+
return readFile(blobPath(blobDir, prefix.database, number));
|
|
149
|
+
});
|
|
150
|
+
records.push({ database: prefix.database, store, value: decoded });
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
skipped++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { records, skipped };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=indexeddb.js.map
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { unsnappy, varint } from "./snappy.js";
|
|
4
|
+
// A read-only LevelDB reader (T-315), just enough to read a Chromium IndexedDB folder that was
|
|
5
|
+
// copied aside: CURRENT → MANIFEST names the live tables and the current log, every live entry
|
|
6
|
+
// is read, and for each user key the highest sequence number wins (a deletion hides the key).
|
|
7
|
+
// Never point it at a folder an app has open: copy the folder first.
|
|
8
|
+
export class LevelDbFormatError extends Error {
|
|
9
|
+
}
|
|
10
|
+
const BLOCK_SIZE = 32 * 1024;
|
|
11
|
+
const RECORD_FULL = 1;
|
|
12
|
+
const RECORD_FIRST = 2;
|
|
13
|
+
const RECORD_MIDDLE = 3;
|
|
14
|
+
const RECORD_LAST = 4;
|
|
15
|
+
const TABLE_MAGIC = 0xdb4775248b80fb57n;
|
|
16
|
+
const CRC_TABLE = (() => {
|
|
17
|
+
const table = new Uint32Array(256);
|
|
18
|
+
for (let n = 0; n < 256; n++) {
|
|
19
|
+
let c = n;
|
|
20
|
+
for (let k = 0; k < 8; k++)
|
|
21
|
+
c = c & 1 ? 0x82f63b78 ^ (c >>> 1) : c >>> 1;
|
|
22
|
+
table[n] = c >>> 0;
|
|
23
|
+
}
|
|
24
|
+
return table;
|
|
25
|
+
})();
|
|
26
|
+
// LevelDB's masked CRC32C of a log record's type byte and payload.
|
|
27
|
+
function maskedCrc(data) {
|
|
28
|
+
let crc = 0xffffffff;
|
|
29
|
+
for (const byte of data)
|
|
30
|
+
crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
31
|
+
crc = (crc ^ 0xffffffff) >>> 0;
|
|
32
|
+
return (((crc >>> 15) | (crc << 17)) + 0xa282ead8) >>> 0;
|
|
33
|
+
}
|
|
34
|
+
// The records of a log-format file (a .log write-ahead log or a MANIFEST). A record whose
|
|
35
|
+
// checksum fails, or one cut off at the end (a file copied while being written), ends the
|
|
36
|
+
// read: everything before it is kept.
|
|
37
|
+
export function* logRecords(buf) {
|
|
38
|
+
let pos = 0;
|
|
39
|
+
let pending = null;
|
|
40
|
+
while (pos + 7 <= buf.length) {
|
|
41
|
+
const left = BLOCK_SIZE - (pos % BLOCK_SIZE);
|
|
42
|
+
if (left < 7) {
|
|
43
|
+
pos += left;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const length = buf.readUInt16LE(pos + 4);
|
|
47
|
+
const type = buf[pos + 6];
|
|
48
|
+
if (type === 0 && length === 0) {
|
|
49
|
+
pos += left;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (pos + 7 + length > buf.length)
|
|
53
|
+
return;
|
|
54
|
+
if (maskedCrc(buf.subarray(pos + 6, pos + 7 + length)) !==
|
|
55
|
+
buf.readUInt32LE(pos))
|
|
56
|
+
return;
|
|
57
|
+
const data = buf.subarray(pos + 7, pos + 7 + length);
|
|
58
|
+
pos += 7 + length;
|
|
59
|
+
if (type === RECORD_FULL) {
|
|
60
|
+
pending = null;
|
|
61
|
+
yield data;
|
|
62
|
+
}
|
|
63
|
+
else if (type === RECORD_FIRST)
|
|
64
|
+
pending = [data];
|
|
65
|
+
else if (type === RECORD_MIDDLE)
|
|
66
|
+
pending?.push(data);
|
|
67
|
+
else if (type === RECORD_LAST && pending) {
|
|
68
|
+
pending.push(data);
|
|
69
|
+
yield Buffer.concat(pending);
|
|
70
|
+
pending = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class Entries {
|
|
75
|
+
map = new Map();
|
|
76
|
+
put(key, sequence, deleted, value) {
|
|
77
|
+
const id = key.toString("latin1");
|
|
78
|
+
const current = this.map.get(id);
|
|
79
|
+
if (!current || current.sequence < sequence)
|
|
80
|
+
this.map.set(id, { key, sequence, deleted, value });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function lengthPrefixed(buf, start) {
|
|
84
|
+
const [length, pos] = varint(buf, start);
|
|
85
|
+
if (pos + length > buf.length)
|
|
86
|
+
throw new LevelDbFormatError("truncated field");
|
|
87
|
+
return [buf.subarray(pos, pos + length), pos + length];
|
|
88
|
+
}
|
|
89
|
+
// A write batch: sequence (8), count (4), then put (1, key, value) or delete (0, key) entries.
|
|
90
|
+
function readBatch(record, entries) {
|
|
91
|
+
if (record.length < 12)
|
|
92
|
+
return;
|
|
93
|
+
const sequence = Number(record.readBigUInt64LE(0));
|
|
94
|
+
const count = record.readUInt32LE(8);
|
|
95
|
+
let pos = 12;
|
|
96
|
+
for (let i = 0; i < count; i++) {
|
|
97
|
+
const tag = record[pos++];
|
|
98
|
+
let key;
|
|
99
|
+
[key, pos] = lengthPrefixed(record, pos);
|
|
100
|
+
if (tag === 1) {
|
|
101
|
+
let value;
|
|
102
|
+
[value, pos] = lengthPrefixed(record, pos);
|
|
103
|
+
entries.put(Buffer.from(key), sequence + i, false, Buffer.from(value));
|
|
104
|
+
}
|
|
105
|
+
else if (tag === 0)
|
|
106
|
+
entries.put(Buffer.from(key), sequence + i, true, Buffer.alloc(0));
|
|
107
|
+
else
|
|
108
|
+
throw new LevelDbFormatError(`unknown batch tag ${tag}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function tableBlock(file, handle) {
|
|
112
|
+
const [offset, next] = varint(handle, 0);
|
|
113
|
+
const [size] = varint(handle, next);
|
|
114
|
+
if (offset + size + 5 > file.length)
|
|
115
|
+
throw new LevelDbFormatError("block out of range");
|
|
116
|
+
const raw = file.subarray(offset, offset + size);
|
|
117
|
+
const compression = file[offset + size];
|
|
118
|
+
if (compression === 0)
|
|
119
|
+
return raw;
|
|
120
|
+
if (compression === 1)
|
|
121
|
+
return unsnappy(raw);
|
|
122
|
+
throw new LevelDbFormatError(`unsupported block compression ${compression}`);
|
|
123
|
+
}
|
|
124
|
+
function* blockEntries(block) {
|
|
125
|
+
if (block.length < 4)
|
|
126
|
+
throw new LevelDbFormatError("short block");
|
|
127
|
+
const restarts = block.readUInt32LE(block.length - 4);
|
|
128
|
+
const end = block.length - 4 - 4 * restarts;
|
|
129
|
+
if (end < 0)
|
|
130
|
+
throw new LevelDbFormatError("bad restart count");
|
|
131
|
+
let pos = 0;
|
|
132
|
+
let key = Buffer.alloc(0);
|
|
133
|
+
while (pos < end) {
|
|
134
|
+
let shared;
|
|
135
|
+
let unshared;
|
|
136
|
+
let valueLength;
|
|
137
|
+
[shared, pos] = varint(block, pos);
|
|
138
|
+
[unshared, pos] = varint(block, pos);
|
|
139
|
+
[valueLength, pos] = varint(block, pos);
|
|
140
|
+
if (shared > key.length || pos + unshared + valueLength > end)
|
|
141
|
+
throw new LevelDbFormatError("bad block entry");
|
|
142
|
+
key = Buffer.concat([
|
|
143
|
+
key.subarray(0, shared),
|
|
144
|
+
block.subarray(pos, pos + unshared),
|
|
145
|
+
]);
|
|
146
|
+
pos += unshared;
|
|
147
|
+
yield [key, block.subarray(pos, pos + valueLength)];
|
|
148
|
+
pos += valueLength;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// An SSTable: the footer's index block lists the data blocks; each internal key is the user key
|
|
152
|
+
// followed by 8 bytes of (sequence << 8 | type), type 1 a value and 0 a deletion.
|
|
153
|
+
function readTable(file, entries) {
|
|
154
|
+
if (file.length < 48)
|
|
155
|
+
throw new LevelDbFormatError("short table");
|
|
156
|
+
const footer = file.subarray(file.length - 48);
|
|
157
|
+
if (footer.readBigUInt64LE(40) !== TABLE_MAGIC)
|
|
158
|
+
throw new LevelDbFormatError("bad table magic");
|
|
159
|
+
let pos = 0;
|
|
160
|
+
[, pos] = varint(footer, pos);
|
|
161
|
+
[, pos] = varint(footer, pos);
|
|
162
|
+
const index = tableBlock(file, footer.subarray(pos));
|
|
163
|
+
for (const [, handle] of blockEntries(index)) {
|
|
164
|
+
for (const [internal, value] of blockEntries(tableBlock(file, handle))) {
|
|
165
|
+
if (internal.length < 8)
|
|
166
|
+
continue;
|
|
167
|
+
const tail = internal.readBigUInt64LE(internal.length - 8);
|
|
168
|
+
entries.put(Buffer.from(internal.subarray(0, internal.length - 8)), Number(tail >> 8n), (tail & 0xffn) === 0n, Buffer.from(value));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// The live tables and the oldest log still needed, from the version edits in the MANIFEST.
|
|
173
|
+
function readManifest(buf) {
|
|
174
|
+
const tables = new Set();
|
|
175
|
+
let logNumber = 0;
|
|
176
|
+
let prevLogNumber = 0;
|
|
177
|
+
for (const record of logRecords(buf)) {
|
|
178
|
+
let pos = 0;
|
|
179
|
+
const number = () => {
|
|
180
|
+
let value;
|
|
181
|
+
[value, pos] = varint(record, pos);
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
const skipString = () => {
|
|
185
|
+
[, pos] = lengthPrefixed(record, pos);
|
|
186
|
+
};
|
|
187
|
+
while (pos < record.length) {
|
|
188
|
+
const tag = number();
|
|
189
|
+
if (tag === 1)
|
|
190
|
+
skipString();
|
|
191
|
+
else if (tag === 2)
|
|
192
|
+
logNumber = number();
|
|
193
|
+
else if (tag === 9)
|
|
194
|
+
prevLogNumber = number();
|
|
195
|
+
else if (tag === 3 || tag === 4)
|
|
196
|
+
number();
|
|
197
|
+
else if (tag === 5) {
|
|
198
|
+
number();
|
|
199
|
+
skipString();
|
|
200
|
+
}
|
|
201
|
+
else if (tag === 6) {
|
|
202
|
+
number();
|
|
203
|
+
tables.delete(number());
|
|
204
|
+
}
|
|
205
|
+
else if (tag === 7) {
|
|
206
|
+
number();
|
|
207
|
+
const file = number();
|
|
208
|
+
number();
|
|
209
|
+
skipString();
|
|
210
|
+
skipString();
|
|
211
|
+
tables.add(file);
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
throw new LevelDbFormatError(`unknown manifest tag ${tag}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
tables,
|
|
219
|
+
logNumber: prevLogNumber > 0 ? Math.min(prevLogNumber, logNumber) : logNumber,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const fileName = (number, ext) => `${String(number).padStart(6, "0")}.${ext}`;
|
|
223
|
+
// Every live key of the database in `dir`, with its newest value.
|
|
224
|
+
export async function readLevelDb(dir) {
|
|
225
|
+
const current = (await readFile(path.join(dir, "CURRENT"), "utf8")).trim();
|
|
226
|
+
if (!/^MANIFEST-\d+$/.test(current))
|
|
227
|
+
throw new LevelDbFormatError("CURRENT does not name a MANIFEST");
|
|
228
|
+
const { tables, logNumber } = readManifest(await readFile(path.join(dir, current)));
|
|
229
|
+
const entries = new Entries();
|
|
230
|
+
for (const table of [...tables].sort((a, b) => a - b)) {
|
|
231
|
+
const name = fileName(table, "ldb");
|
|
232
|
+
const file = await readFile(path.join(dir, name)).catch(() => readFile(path.join(dir, fileName(table, "sst"))));
|
|
233
|
+
readTable(file, entries);
|
|
234
|
+
}
|
|
235
|
+
const logs = (await readdir(dir))
|
|
236
|
+
.filter((name) => /^\d+\.log$/.test(name) && Number.parseInt(name, 10) >= logNumber)
|
|
237
|
+
.sort();
|
|
238
|
+
for (const log of logs)
|
|
239
|
+
for (const record of logRecords(await readFile(path.join(dir, log))))
|
|
240
|
+
readBatch(record, entries);
|
|
241
|
+
const live = new Map();
|
|
242
|
+
for (const [id, entry] of entries.map)
|
|
243
|
+
if (!entry.deleted)
|
|
244
|
+
live.set(id, entry.value);
|
|
245
|
+
return live;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=leveldb.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Raw Snappy block decompression (T-315), the format LevelDB uses for table blocks and Chromium
|
|
2
|
+
// IndexedDB uses for compressed values. Read-only and dependency-free; malformed input throws.
|
|
3
|
+
export function varint(buf, start) {
|
|
4
|
+
let result = 0;
|
|
5
|
+
let shift = 0;
|
|
6
|
+
let pos = start;
|
|
7
|
+
for (;;) {
|
|
8
|
+
if (pos >= buf.length || shift > 63)
|
|
9
|
+
throw new Error("bad varint");
|
|
10
|
+
const byte = buf[pos++];
|
|
11
|
+
result += (byte & 0x7f) * 2 ** shift;
|
|
12
|
+
if (!(byte & 0x80))
|
|
13
|
+
return [result, pos];
|
|
14
|
+
shift += 7;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function unsnappy(src) {
|
|
18
|
+
let [length, pos] = varint(src, 0);
|
|
19
|
+
if (length > 512 * 1024 * 1024)
|
|
20
|
+
throw new Error("snappy: length too large");
|
|
21
|
+
const out = Buffer.alloc(length);
|
|
22
|
+
let op = 0;
|
|
23
|
+
while (pos < src.length) {
|
|
24
|
+
const tag = src[pos++];
|
|
25
|
+
const type = tag & 3;
|
|
26
|
+
if (type === 0) {
|
|
27
|
+
let len = tag >> 2;
|
|
28
|
+
if (len >= 60) {
|
|
29
|
+
const bytes = len - 59;
|
|
30
|
+
if (pos + bytes > src.length)
|
|
31
|
+
throw new Error("snappy: truncated");
|
|
32
|
+
len = src.readUIntLE(pos, bytes);
|
|
33
|
+
pos += bytes;
|
|
34
|
+
}
|
|
35
|
+
len += 1;
|
|
36
|
+
if (pos + len > src.length || op + len > length)
|
|
37
|
+
throw new Error("snappy: literal out of range");
|
|
38
|
+
src.copy(out, op, pos, pos + len);
|
|
39
|
+
pos += len;
|
|
40
|
+
op += len;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let len;
|
|
44
|
+
let offset;
|
|
45
|
+
if (type === 1) {
|
|
46
|
+
if (pos >= src.length)
|
|
47
|
+
throw new Error("snappy: truncated");
|
|
48
|
+
len = ((tag >> 2) & 7) + 4;
|
|
49
|
+
offset = ((tag >> 5) << 8) | src[pos++];
|
|
50
|
+
}
|
|
51
|
+
else if (type === 2) {
|
|
52
|
+
if (pos + 2 > src.length)
|
|
53
|
+
throw new Error("snappy: truncated");
|
|
54
|
+
len = (tag >> 2) + 1;
|
|
55
|
+
offset = src.readUInt16LE(pos);
|
|
56
|
+
pos += 2;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (pos + 4 > src.length)
|
|
60
|
+
throw new Error("snappy: truncated");
|
|
61
|
+
len = (tag >> 2) + 1;
|
|
62
|
+
offset = src.readUInt32LE(pos);
|
|
63
|
+
pos += 4;
|
|
64
|
+
}
|
|
65
|
+
if (offset === 0 || offset > op || op + len > length)
|
|
66
|
+
throw new Error("snappy: copy out of range");
|
|
67
|
+
for (let i = 0; i < len; i++, op++)
|
|
68
|
+
out[op] = out[op - offset];
|
|
69
|
+
}
|
|
70
|
+
if (op !== length)
|
|
71
|
+
throw new Error("snappy: length mismatch");
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=snappy.js.map
|
|
@@ -73,6 +73,14 @@ export function startBackgroundPull() {
|
|
|
73
73
|
})
|
|
74
74
|
.on("error", () => { })
|
|
75
75
|
.unref();
|
|
76
|
+
// The daily harvest (T-316) rides the same start: days not yet harvested, then the archive.
|
|
77
|
+
// It returns at once when nothing is pending.
|
|
78
|
+
spawn(process.execPath, [process.argv[1], "harvest", "--pending", "--yes"], {
|
|
79
|
+
detached: true,
|
|
80
|
+
stdio: "ignore",
|
|
81
|
+
})
|
|
82
|
+
.on("error", () => { })
|
|
83
|
+
.unref();
|
|
76
84
|
}
|
|
77
85
|
catch {
|
|
78
86
|
// no pull this time; the next try runs it
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
2
|
+
import { buildBrief } from "@ocean/services/brief/brief.js";
|
|
3
|
+
// `ocean brief [--weekly] [--dry-run] [--date YYYY-MM-DD]` (T-314): what moved in what the owner
|
|
4
|
+
// follows, written to 01-daily/briefs/.
|
|
5
|
+
export async function runBriefCommand(args) {
|
|
6
|
+
const at = args.indexOf("--date");
|
|
7
|
+
const date = at >= 0 ? args[at + 1] : localDate();
|
|
8
|
+
if (!date || !/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
9
|
+
throw new Error("Usage: ocean brief [--weekly] [--dry-run] [--date YYYY-MM-DD]");
|
|
10
|
+
const result = await buildBrief({
|
|
11
|
+
date,
|
|
12
|
+
weekly: args.includes("--weekly"),
|
|
13
|
+
dryRun: args.includes("--dry-run"),
|
|
14
|
+
});
|
|
15
|
+
console.log(JSON.stringify(result, null, 2));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=brief-command.js.map
|
|
@@ -119,7 +119,7 @@ async function promote(item, target = "knowledge/results") {
|
|
|
119
119
|
const slug = safe || `capture-${item.captureId}`;
|
|
120
120
|
const file = path.join(oceanPath(KNOWLEDGE_DIR, match[1], `${slug}-${item.captureId}.md`));
|
|
121
121
|
await mkdir(path.dirname(file), { recursive: true });
|
|
122
|
-
await writeFile(file, `---\nname: ${slug}-${item.captureId}\ndescription: Candidate promoted from a reviewed session input\
|
|
122
|
+
await writeFile(file, `---\nname: ${slug}-${item.captureId}\ndescription: Candidate promoted from a reviewed session input\ntype: ${match[1] === "results" ? "task-result" : match[1].slice(0, -1)}\ndomain: ${match[1]}\nstatus: current\nverification: unverified\nsource: session-capture-${item.captureId}\n---\n\n${item.content.trim()}\n`);
|
|
123
123
|
await syncMemoryIndexes(true);
|
|
124
124
|
}
|
|
125
125
|
//# sourceMappingURL=capture-command.js.map
|
|
@@ -4,6 +4,7 @@ import { marketplacePaths } from "@ocean/market/install/default-marketplace.js";
|
|
|
4
4
|
import { updateGatewayAccess } from "@ocean/market/mcp/mcp-gateway.js";
|
|
5
5
|
import { readCallLedger, summarizeCallLedger, } from "@ocean/services/infrastructure/mcp/call-ledger.js";
|
|
6
6
|
import { applyClients, attributeLedger, confirmClient, defaultClientEnv, gatewayDefault, planClients, readGatewayClients, recordVerification, repairClients, restoreClients, setGatewayClient, setGatewayDefault, temporaryEntryProblem, verifyClient, } from "../../application/clients/clients.js";
|
|
7
|
+
import { applyDesktopWatcher, planDesktopWatcher, restoreDesktopWatcher, } from "../../application/clients/desktop-watcher.js";
|
|
7
8
|
import { applyHooks, planHooks, restoreHooks, } from "../../application/clients/hooks.js";
|
|
8
9
|
import { applyNative, planNative, restoreNative, } from "../../application/clients/native.js";
|
|
9
10
|
import { applyOpencodePlugin, planOpencodePlugin, restoreOpencodePlugin, } from "../../application/clients/opencode-plugin.js";
|
|
@@ -72,6 +73,9 @@ export async function runClientsCommand(args) {
|
|
|
72
73
|
if (action === "plan")
|
|
73
74
|
for (const plugin of await planOpencodePlugin())
|
|
74
75
|
console.log(`${"opencode hook".padEnd(15)} ${plugin.status.padEnd(14)} ${plugin.file} plugin${plugin.reason ? ` (${plugin.reason})` : ""}`);
|
|
76
|
+
if (action === "plan")
|
|
77
|
+
for (const watcher of await planDesktopWatcher())
|
|
78
|
+
console.log(`${"claude-desktop watcher".padEnd(15)} ${watcher.status.padEnd(14)} ${watcher.file} chat capture${watcher.reason ? ` (${watcher.reason})` : ""}`);
|
|
75
79
|
return;
|
|
76
80
|
}
|
|
77
81
|
result =
|
|
@@ -82,6 +86,7 @@ export async function runClientsCommand(args) {
|
|
|
82
86
|
hooks: await planHooks(),
|
|
83
87
|
plugins: await planOpencodePlugin(),
|
|
84
88
|
native: await planNative(),
|
|
89
|
+
watcher: await planDesktopWatcher(),
|
|
85
90
|
};
|
|
86
91
|
}
|
|
87
92
|
else if (action === "apply") {
|
|
@@ -95,13 +100,15 @@ export async function runClientsCommand(args) {
|
|
|
95
100
|
(!clients.length || clients.includes(plan.client)));
|
|
96
101
|
const plugins = (await planOpencodePlugin()).filter((plan) => plan.status === "change" &&
|
|
97
102
|
(!clients.length || clients.includes(plan.client)));
|
|
98
|
-
|
|
103
|
+
const watcher = (await planDesktopWatcher()).filter((plan) => plan.status === "change" &&
|
|
104
|
+
(!clients.length || clients.includes(plan.client)));
|
|
105
|
+
console.log(JSON.stringify({ dryRun: true, pending, hooks, plugins, native, watcher }, null, 2));
|
|
99
106
|
console.error("Dry run: pass --yes to write these client configs.");
|
|
100
107
|
return;
|
|
101
108
|
}
|
|
102
109
|
const selected = clients.length ? clients : undefined;
|
|
103
110
|
const applied = await applyClients({ clients: selected });
|
|
104
|
-
|
|
111
|
+
const appliedAll = {
|
|
105
112
|
...applied,
|
|
106
113
|
hooks: (await applyHooks({ clients: selected, batch: applied.batch }))
|
|
107
114
|
.results,
|
|
@@ -110,6 +117,11 @@ export async function runClientsCommand(args) {
|
|
|
110
117
|
.results,
|
|
111
118
|
sessionFacts: await sessionFactsAnswer(values("--session-facts")[0]),
|
|
112
119
|
};
|
|
120
|
+
// After the session-facts answer: the watcher exists only for capture that is on (T-315).
|
|
121
|
+
result = {
|
|
122
|
+
...appliedAll,
|
|
123
|
+
watcher: (await applyDesktopWatcher({ clients: selected, batch: applied.batch })).results,
|
|
124
|
+
};
|
|
113
125
|
}
|
|
114
126
|
else if (action === "verify") {
|
|
115
127
|
const ids = rest.filter((arg) => !arg.startsWith("--"));
|
|
@@ -187,6 +199,7 @@ export async function runClientsCommand(args) {
|
|
|
187
199
|
hooks: await restoreHooks({ batch: restored.batch }),
|
|
188
200
|
plugins: await restoreOpencodePlugin({ batch: restored.batch }),
|
|
189
201
|
native: await restoreNative({ batch: restored.batch }),
|
|
202
|
+
watcher: await restoreDesktopWatcher({ batch: restored.batch }),
|
|
190
203
|
}
|
|
191
204
|
: restored;
|
|
192
205
|
}
|