@goondocks/myco 0.4.3 → 0.4.4
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/dist/chunk-2AMAOSRF.js +105 -0
- package/dist/chunk-2AMAOSRF.js.map +1 -0
- package/dist/chunk-3F63SFZZ.js +381 -0
- package/dist/chunk-3F63SFZZ.js.map +1 -0
- package/dist/{chunk-WBT5DWGC.js → chunk-42R7KVAW.js} +2 -2
- package/dist/{chunk-GFBG73P4.js → chunk-5FIIK27E.js} +3 -3
- package/dist/{chunk-XCPQHC4X.js → chunk-6CAKKNGD.js} +2 -2
- package/dist/{chunk-I7PNZEBO.js → chunk-6LTNFMXO.js} +12 -1
- package/dist/{chunk-I7PNZEBO.js.map → chunk-6LTNFMXO.js.map} +1 -1
- package/dist/{chunk-V2OWD2VV.js → chunk-DKHYIA2V.js} +24 -146
- package/dist/chunk-DKHYIA2V.js.map +1 -0
- package/dist/{chunk-BNIYWCST.js → chunk-EQVQEFOA.js} +2 -2
- package/dist/{chunk-FPEDTLQ6.js → chunk-JJL6AMDA.js} +3 -101
- package/dist/chunk-JJL6AMDA.js.map +1 -0
- package/dist/{chunk-OUFSLZTX.js → chunk-KDWBZSOB.js} +21 -9
- package/dist/chunk-KDWBZSOB.js.map +1 -0
- package/dist/{chunk-67R6EMYD.js → chunk-OPO47BVS.js} +31 -52
- package/dist/chunk-OPO47BVS.js.map +1 -0
- package/dist/{chunk-IYFKPSRP.js → chunk-OSZRLHIJ.js} +3 -3
- package/dist/chunk-PD7LV22R.js +150 -0
- package/dist/chunk-PD7LV22R.js.map +1 -0
- package/dist/{chunk-JBD5KP5G.js → chunk-TDLQBGKA.js} +6 -2
- package/dist/chunk-TDLQBGKA.js.map +1 -0
- package/dist/{chunk-2GJFTIWX.js → chunk-TK2ZYIAL.js} +2 -2
- package/dist/{chunk-ZCBL5HER.js → chunk-XIIVIMFC.js} +2 -2
- package/dist/{cli-PMOFCZQL.js → cli-WOM4Z2Z4.js} +21 -18
- package/dist/cli-WOM4Z2Z4.js.map +1 -0
- package/dist/{client-5SUO2UYH.js → client-XCNF6NFT.js} +5 -5
- package/dist/{detect-providers-IRL2TTLK.js → detect-providers-CQSPTW2B.js} +3 -3
- package/dist/digest-WTS6S4XP.js +96 -0
- package/dist/digest-WTS6S4XP.js.map +1 -0
- package/dist/{init-NUF5UBUJ.js → init-VPLUEULI.js} +5 -5
- package/dist/{main-2XEBVUR6.js → main-OGXH6XWO.js} +230 -575
- package/dist/main-OGXH6XWO.js.map +1 -0
- package/dist/{rebuild-E6YFIRYZ.js → rebuild-Z4YUY6HT.js} +8 -7
- package/dist/{rebuild-E6YFIRYZ.js.map → rebuild-Z4YUY6HT.js.map} +1 -1
- package/dist/{reprocess-7G7KQWCN.js → reprocess-DMGPZTLC.js} +91 -20
- package/dist/reprocess-DMGPZTLC.js.map +1 -0
- package/dist/{restart-ABW4ZK3P.js → restart-QCQQ55KX.js} +6 -6
- package/dist/{search-MPD7SFK6.js → search-ACEFQOUW.js} +6 -6
- package/dist/{server-NZLZRITH.js → server-BQ3DWKZ6.js} +16 -14
- package/dist/{server-NZLZRITH.js.map → server-BQ3DWKZ6.js.map} +1 -1
- package/dist/{session-start-YB4A4PZB.js → session-start-BXRTKS4X.js} +6 -6
- package/dist/{setup-digest-K732MGOJ.js → setup-digest-EJXSQGZ5.js} +5 -5
- package/dist/{setup-llm-XCCH5LYD.js → setup-llm-P3MLWUDR.js} +5 -5
- package/dist/src/cli.js +4 -4
- package/dist/src/daemon/main.js +4 -4
- package/dist/src/hooks/post-tool-use.js +5 -5
- package/dist/src/hooks/session-end.js +5 -5
- package/dist/src/hooks/session-start.js +4 -4
- package/dist/src/hooks/stop.js +6 -6
- package/dist/src/hooks/stop.js.map +1 -1
- package/dist/src/hooks/user-prompt-submit.js +5 -5
- package/dist/src/mcp/server.js +4 -4
- package/dist/src/prompts/extraction.md +1 -1
- package/dist/src/prompts/summary.md +1 -11
- package/dist/{stats-6G7SN5YZ.js → stats-3FAP5FKV.js} +5 -5
- package/dist/{verify-JFHQH55Z.js → verify-3FTCOULE.js} +4 -4
- package/dist/{version-5B2TWXQJ.js → version-AL67JH7X.js} +4 -4
- package/package.json +1 -1
- package/skills/setup/SKILL.md +56 -28
- package/skills/setup/references/model-recommendations.md +49 -43
- package/dist/chunk-67R6EMYD.js.map +0 -1
- package/dist/chunk-FPEDTLQ6.js.map +0 -1
- package/dist/chunk-JBD5KP5G.js.map +0 -1
- package/dist/chunk-OUFSLZTX.js.map +0 -1
- package/dist/chunk-V2OWD2VV.js.map +0 -1
- package/dist/cli-PMOFCZQL.js.map +0 -1
- package/dist/main-2XEBVUR6.js.map +0 -1
- package/dist/reprocess-7G7KQWCN.js.map +0 -1
- /package/dist/{chunk-WBT5DWGC.js.map → chunk-42R7KVAW.js.map} +0 -0
- /package/dist/{chunk-GFBG73P4.js.map → chunk-5FIIK27E.js.map} +0 -0
- /package/dist/{chunk-XCPQHC4X.js.map → chunk-6CAKKNGD.js.map} +0 -0
- /package/dist/{chunk-BNIYWCST.js.map → chunk-EQVQEFOA.js.map} +0 -0
- /package/dist/{chunk-IYFKPSRP.js.map → chunk-OSZRLHIJ.js.map} +0 -0
- /package/dist/{chunk-2GJFTIWX.js.map → chunk-TK2ZYIAL.js.map} +0 -0
- /package/dist/{chunk-ZCBL5HER.js.map → chunk-XIIVIMFC.js.map} +0 -0
- /package/dist/{client-5SUO2UYH.js.map → client-XCNF6NFT.js.map} +0 -0
- /package/dist/{detect-providers-IRL2TTLK.js.map → detect-providers-CQSPTW2B.js.map} +0 -0
- /package/dist/{init-NUF5UBUJ.js.map → init-VPLUEULI.js.map} +0 -0
- /package/dist/{restart-ABW4ZK3P.js.map → restart-QCQQ55KX.js.map} +0 -0
- /package/dist/{search-MPD7SFK6.js.map → search-ACEFQOUW.js.map} +0 -0
- /package/dist/{session-start-YB4A4PZB.js.map → session-start-BXRTKS4X.js.map} +0 -0
- /package/dist/{setup-digest-K732MGOJ.js.map → setup-digest-EJXSQGZ5.js.map} +0 -0
- /package/dist/{setup-llm-XCCH5LYD.js.map → setup-llm-P3MLWUDR.js.map} +0 -0
- /package/dist/{stats-6G7SN5YZ.js.map → stats-3FAP5FKV.js.map} +0 -0
- /package/dist/{verify-JFHQH55Z.js.map → verify-3FTCOULE.js.map} +0 -0
- /package/dist/{version-5B2TWXQJ.js.map → version-AL67JH7X.js.map} +0 -0
|
@@ -2,19 +2,20 @@ import { createRequire as __cr } from 'node:module'; const require = __cr(import
|
|
|
2
2
|
import {
|
|
3
3
|
BufferProcessor,
|
|
4
4
|
TranscriptMiner,
|
|
5
|
-
buildSimilarityPrompt,
|
|
6
|
-
extractNumber,
|
|
7
5
|
extractTurnsFromBuffer,
|
|
8
|
-
loadPrompt,
|
|
9
|
-
stripReasoningTokens,
|
|
10
6
|
writeObservationNotes
|
|
11
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-DKHYIA2V.js";
|
|
12
8
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
DigestEngine,
|
|
10
|
+
Metabolism
|
|
11
|
+
} from "./chunk-3F63SFZZ.js";
|
|
15
12
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
buildSimilarityPrompt,
|
|
14
|
+
extractNumber
|
|
15
|
+
} from "./chunk-PD7LV22R.js";
|
|
16
|
+
import {
|
|
17
|
+
handleMycoContext
|
|
18
|
+
} from "./chunk-42R7KVAW.js";
|
|
18
19
|
import {
|
|
19
20
|
VaultWriter,
|
|
20
21
|
bareSessionId,
|
|
@@ -22,31 +23,33 @@ import {
|
|
|
22
23
|
sessionNoteId,
|
|
23
24
|
sessionRelativePath,
|
|
24
25
|
sessionWikilink
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-6LTNFMXO.js";
|
|
27
|
+
import {
|
|
28
|
+
DaemonLogger
|
|
29
|
+
} from "./chunk-5EZ7QF6J.js";
|
|
26
30
|
import {
|
|
27
31
|
indexNote,
|
|
28
32
|
rebuildIndex
|
|
29
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-JJL6AMDA.js";
|
|
30
34
|
import {
|
|
31
35
|
generateEmbedding
|
|
32
36
|
} from "./chunk-RGVBGTD6.js";
|
|
33
|
-
import {
|
|
34
|
-
createEmbeddingProvider,
|
|
35
|
-
createLlmProvider
|
|
36
|
-
} from "./chunk-IYFKPSRP.js";
|
|
37
37
|
import {
|
|
38
38
|
VectorIndex
|
|
39
39
|
} from "./chunk-XQXXF6MU.js";
|
|
40
|
+
import "./chunk-2AMAOSRF.js";
|
|
40
41
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
createEmbeddingProvider,
|
|
43
|
+
createLlmProvider
|
|
44
|
+
} from "./chunk-OSZRLHIJ.js";
|
|
45
|
+
import "./chunk-MIU3DKLN.js";
|
|
43
46
|
import {
|
|
44
47
|
initFts
|
|
45
48
|
} from "./chunk-6FQISQNA.js";
|
|
46
49
|
import {
|
|
47
50
|
MycoIndex
|
|
48
51
|
} from "./chunk-AK6GNLPV.js";
|
|
49
|
-
import "./chunk-
|
|
52
|
+
import "./chunk-OPO47BVS.js";
|
|
50
53
|
import {
|
|
51
54
|
loadConfig
|
|
52
55
|
} from "./chunk-TBRZAJ7W.js";
|
|
@@ -59,32 +62,28 @@ import {
|
|
|
59
62
|
} from "./chunk-HIN3UVOG.js";
|
|
60
63
|
import {
|
|
61
64
|
getPluginVersion
|
|
62
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-TK2ZYIAL.js";
|
|
63
66
|
import {
|
|
64
67
|
claudeCodeAdapter,
|
|
65
68
|
createPerProjectAdapter,
|
|
66
69
|
extensionForMimeType
|
|
67
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-EQVQEFOA.js";
|
|
68
71
|
import {
|
|
69
72
|
CANDIDATE_CONTENT_PREVIEW,
|
|
70
|
-
CHARS_PER_TOKEN,
|
|
71
73
|
CONTENT_SNIPPET_CHARS,
|
|
72
74
|
CONTEXT_SESSION_PREVIEW_CHARS,
|
|
73
|
-
DIGEST_LLM_REQUEST_TIMEOUT_MS,
|
|
74
|
-
DIGEST_SUBSTRATE_TYPE_WEIGHTS,
|
|
75
|
-
DIGEST_TIER_MIN_CONTEXT,
|
|
76
75
|
EMBEDDING_INPUT_LIMIT,
|
|
77
76
|
FILE_WATCH_STABILITY_MS,
|
|
78
77
|
LINEAGE_RECENT_SESSIONS_LIMIT,
|
|
78
|
+
LLM_REASONING_MODE,
|
|
79
79
|
MAX_SLUG_LENGTH,
|
|
80
80
|
PROMPT_CONTEXT_MAX_SPORES,
|
|
81
81
|
PROMPT_CONTEXT_MIN_LENGTH,
|
|
82
82
|
PROMPT_CONTEXT_MIN_SIMILARITY,
|
|
83
83
|
RELATED_SPORES_LIMIT,
|
|
84
84
|
SESSION_CONTEXT_MAX_PLANS,
|
|
85
|
-
STALE_BUFFER_MAX_AGE_MS
|
|
86
|
-
|
|
87
|
-
} from "./chunk-JBD5KP5G.js";
|
|
85
|
+
STALE_BUFFER_MAX_AGE_MS
|
|
86
|
+
} from "./chunk-TDLQBGKA.js";
|
|
88
87
|
import {
|
|
89
88
|
__toESM
|
|
90
89
|
} from "./chunk-PZUWP5VK.js";
|
|
@@ -496,7 +495,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
496
495
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
497
496
|
const statMethod = opts.lstat ? lstat : stat;
|
|
498
497
|
if (wantBigintFsStats) {
|
|
499
|
-
this._stat = (
|
|
498
|
+
this._stat = (path7) => statMethod(path7, { bigint: true });
|
|
500
499
|
} else {
|
|
501
500
|
this._stat = statMethod;
|
|
502
501
|
}
|
|
@@ -521,8 +520,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
521
520
|
const par = this.parent;
|
|
522
521
|
const fil = par && par.files;
|
|
523
522
|
if (fil && fil.length > 0) {
|
|
524
|
-
const { path:
|
|
525
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
523
|
+
const { path: path7, depth } = par;
|
|
524
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path7));
|
|
526
525
|
const awaited = await Promise.all(slice);
|
|
527
526
|
for (const entry of awaited) {
|
|
528
527
|
if (!entry)
|
|
@@ -562,20 +561,20 @@ var ReaddirpStream = class extends Readable {
|
|
|
562
561
|
this.reading = false;
|
|
563
562
|
}
|
|
564
563
|
}
|
|
565
|
-
async _exploreDir(
|
|
564
|
+
async _exploreDir(path7, depth) {
|
|
566
565
|
let files;
|
|
567
566
|
try {
|
|
568
|
-
files = await readdir(
|
|
567
|
+
files = await readdir(path7, this._rdOptions);
|
|
569
568
|
} catch (error) {
|
|
570
569
|
this._onError(error);
|
|
571
570
|
}
|
|
572
|
-
return { files, depth, path:
|
|
571
|
+
return { files, depth, path: path7 };
|
|
573
572
|
}
|
|
574
|
-
async _formatEntry(dirent,
|
|
573
|
+
async _formatEntry(dirent, path7) {
|
|
575
574
|
let entry;
|
|
576
575
|
const basename3 = this._isDirent ? dirent.name : dirent;
|
|
577
576
|
try {
|
|
578
|
-
const fullPath = presolve(pjoin(
|
|
577
|
+
const fullPath = presolve(pjoin(path7, basename3));
|
|
579
578
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
|
|
580
579
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
581
580
|
} catch (err) {
|
|
@@ -975,16 +974,16 @@ var delFromSet = (main2, prop, item) => {
|
|
|
975
974
|
};
|
|
976
975
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
977
976
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
978
|
-
function createFsWatchInstance(
|
|
977
|
+
function createFsWatchInstance(path7, options, listener, errHandler, emitRaw) {
|
|
979
978
|
const handleEvent = (rawEvent, evPath) => {
|
|
980
|
-
listener(
|
|
981
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
982
|
-
if (evPath &&
|
|
983
|
-
fsWatchBroadcast(sp.resolve(
|
|
979
|
+
listener(path7);
|
|
980
|
+
emitRaw(rawEvent, evPath, { watchedPath: path7 });
|
|
981
|
+
if (evPath && path7 !== evPath) {
|
|
982
|
+
fsWatchBroadcast(sp.resolve(path7, evPath), KEY_LISTENERS, sp.join(path7, evPath));
|
|
984
983
|
}
|
|
985
984
|
};
|
|
986
985
|
try {
|
|
987
|
-
return fs_watch(
|
|
986
|
+
return fs_watch(path7, {
|
|
988
987
|
persistent: options.persistent
|
|
989
988
|
}, handleEvent);
|
|
990
989
|
} catch (error) {
|
|
@@ -1000,12 +999,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
1000
999
|
listener(val1, val2, val3);
|
|
1001
1000
|
});
|
|
1002
1001
|
};
|
|
1003
|
-
var setFsWatchListener = (
|
|
1002
|
+
var setFsWatchListener = (path7, fullPath, options, handlers) => {
|
|
1004
1003
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
1005
1004
|
let cont = FsWatchInstances.get(fullPath);
|
|
1006
1005
|
let watcher;
|
|
1007
1006
|
if (!options.persistent) {
|
|
1008
|
-
watcher = createFsWatchInstance(
|
|
1007
|
+
watcher = createFsWatchInstance(path7, options, listener, errHandler, rawEmitter);
|
|
1009
1008
|
if (!watcher)
|
|
1010
1009
|
return;
|
|
1011
1010
|
return watcher.close.bind(watcher);
|
|
@@ -1016,7 +1015,7 @@ var setFsWatchListener = (path8, fullPath, options, handlers) => {
|
|
|
1016
1015
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1017
1016
|
} else {
|
|
1018
1017
|
watcher = createFsWatchInstance(
|
|
1019
|
-
|
|
1018
|
+
path7,
|
|
1020
1019
|
options,
|
|
1021
1020
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
1022
1021
|
errHandler,
|
|
@@ -1031,7 +1030,7 @@ var setFsWatchListener = (path8, fullPath, options, handlers) => {
|
|
|
1031
1030
|
cont.watcherUnusable = true;
|
|
1032
1031
|
if (isWindows && error.code === "EPERM") {
|
|
1033
1032
|
try {
|
|
1034
|
-
const fd = await open(
|
|
1033
|
+
const fd = await open(path7, "r");
|
|
1035
1034
|
await fd.close();
|
|
1036
1035
|
broadcastErr(error);
|
|
1037
1036
|
} catch (err) {
|
|
@@ -1062,7 +1061,7 @@ var setFsWatchListener = (path8, fullPath, options, handlers) => {
|
|
|
1062
1061
|
};
|
|
1063
1062
|
};
|
|
1064
1063
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
1065
|
-
var setFsWatchFileListener = (
|
|
1064
|
+
var setFsWatchFileListener = (path7, fullPath, options, handlers) => {
|
|
1066
1065
|
const { listener, rawEmitter } = handlers;
|
|
1067
1066
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
1068
1067
|
const copts = cont && cont.options;
|
|
@@ -1084,7 +1083,7 @@ var setFsWatchFileListener = (path8, fullPath, options, handlers) => {
|
|
|
1084
1083
|
});
|
|
1085
1084
|
const currmtime = curr.mtimeMs;
|
|
1086
1085
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
1087
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
1086
|
+
foreach(cont.listeners, (listener2) => listener2(path7, curr));
|
|
1088
1087
|
}
|
|
1089
1088
|
})
|
|
1090
1089
|
};
|
|
@@ -1114,13 +1113,13 @@ var NodeFsHandler = class {
|
|
|
1114
1113
|
* @param listener on fs change
|
|
1115
1114
|
* @returns closer for the watcher instance
|
|
1116
1115
|
*/
|
|
1117
|
-
_watchWithNodeFs(
|
|
1116
|
+
_watchWithNodeFs(path7, listener) {
|
|
1118
1117
|
const opts = this.fsw.options;
|
|
1119
|
-
const directory = sp.dirname(
|
|
1120
|
-
const basename3 = sp.basename(
|
|
1118
|
+
const directory = sp.dirname(path7);
|
|
1119
|
+
const basename3 = sp.basename(path7);
|
|
1121
1120
|
const parent = this.fsw._getWatchedDir(directory);
|
|
1122
1121
|
parent.add(basename3);
|
|
1123
|
-
const absolutePath = sp.resolve(
|
|
1122
|
+
const absolutePath = sp.resolve(path7);
|
|
1124
1123
|
const options = {
|
|
1125
1124
|
persistent: opts.persistent
|
|
1126
1125
|
};
|
|
@@ -1130,12 +1129,12 @@ var NodeFsHandler = class {
|
|
|
1130
1129
|
if (opts.usePolling) {
|
|
1131
1130
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
1132
1131
|
options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
|
|
1133
|
-
closer = setFsWatchFileListener(
|
|
1132
|
+
closer = setFsWatchFileListener(path7, absolutePath, options, {
|
|
1134
1133
|
listener,
|
|
1135
1134
|
rawEmitter: this.fsw._emitRaw
|
|
1136
1135
|
});
|
|
1137
1136
|
} else {
|
|
1138
|
-
closer = setFsWatchListener(
|
|
1137
|
+
closer = setFsWatchListener(path7, absolutePath, options, {
|
|
1139
1138
|
listener,
|
|
1140
1139
|
errHandler: this._boundHandleError,
|
|
1141
1140
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -1157,7 +1156,7 @@ var NodeFsHandler = class {
|
|
|
1157
1156
|
let prevStats = stats;
|
|
1158
1157
|
if (parent.has(basename3))
|
|
1159
1158
|
return;
|
|
1160
|
-
const listener = async (
|
|
1159
|
+
const listener = async (path7, newStats) => {
|
|
1161
1160
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
1162
1161
|
return;
|
|
1163
1162
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -1171,11 +1170,11 @@ var NodeFsHandler = class {
|
|
|
1171
1170
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
1172
1171
|
}
|
|
1173
1172
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
1174
|
-
this.fsw._closeFile(
|
|
1173
|
+
this.fsw._closeFile(path7);
|
|
1175
1174
|
prevStats = newStats2;
|
|
1176
1175
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
1177
1176
|
if (closer2)
|
|
1178
|
-
this.fsw._addPathCloser(
|
|
1177
|
+
this.fsw._addPathCloser(path7, closer2);
|
|
1179
1178
|
} else {
|
|
1180
1179
|
prevStats = newStats2;
|
|
1181
1180
|
}
|
|
@@ -1207,7 +1206,7 @@ var NodeFsHandler = class {
|
|
|
1207
1206
|
* @param item basename of this item
|
|
1208
1207
|
* @returns true if no more processing is needed for this entry.
|
|
1209
1208
|
*/
|
|
1210
|
-
async _handleSymlink(entry, directory,
|
|
1209
|
+
async _handleSymlink(entry, directory, path7, item) {
|
|
1211
1210
|
if (this.fsw.closed) {
|
|
1212
1211
|
return;
|
|
1213
1212
|
}
|
|
@@ -1217,7 +1216,7 @@ var NodeFsHandler = class {
|
|
|
1217
1216
|
this.fsw._incrReadyCount();
|
|
1218
1217
|
let linkPath;
|
|
1219
1218
|
try {
|
|
1220
|
-
linkPath = await fsrealpath(
|
|
1219
|
+
linkPath = await fsrealpath(path7);
|
|
1221
1220
|
} catch (e) {
|
|
1222
1221
|
this.fsw._emitReady();
|
|
1223
1222
|
return true;
|
|
@@ -1227,12 +1226,12 @@ var NodeFsHandler = class {
|
|
|
1227
1226
|
if (dir.has(item)) {
|
|
1228
1227
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
1229
1228
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1230
|
-
this.fsw._emit(EV.CHANGE,
|
|
1229
|
+
this.fsw._emit(EV.CHANGE, path7, entry.stats);
|
|
1231
1230
|
}
|
|
1232
1231
|
} else {
|
|
1233
1232
|
dir.add(item);
|
|
1234
1233
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1235
|
-
this.fsw._emit(EV.ADD,
|
|
1234
|
+
this.fsw._emit(EV.ADD, path7, entry.stats);
|
|
1236
1235
|
}
|
|
1237
1236
|
this.fsw._emitReady();
|
|
1238
1237
|
return true;
|
|
@@ -1262,9 +1261,9 @@ var NodeFsHandler = class {
|
|
|
1262
1261
|
return;
|
|
1263
1262
|
}
|
|
1264
1263
|
const item = entry.path;
|
|
1265
|
-
let
|
|
1264
|
+
let path7 = sp.join(directory, item);
|
|
1266
1265
|
current.add(item);
|
|
1267
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
1266
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path7, item)) {
|
|
1268
1267
|
return;
|
|
1269
1268
|
}
|
|
1270
1269
|
if (this.fsw.closed) {
|
|
@@ -1273,8 +1272,8 @@ var NodeFsHandler = class {
|
|
|
1273
1272
|
}
|
|
1274
1273
|
if (item === target || !target && !previous.has(item)) {
|
|
1275
1274
|
this.fsw._incrReadyCount();
|
|
1276
|
-
|
|
1277
|
-
this._addToNodeFs(
|
|
1275
|
+
path7 = sp.join(dir, sp.relative(dir, path7));
|
|
1276
|
+
this._addToNodeFs(path7, initialAdd, wh, depth + 1);
|
|
1278
1277
|
}
|
|
1279
1278
|
}).on(EV.ERROR, this._boundHandleError);
|
|
1280
1279
|
return new Promise((resolve3, reject) => {
|
|
@@ -1343,13 +1342,13 @@ var NodeFsHandler = class {
|
|
|
1343
1342
|
* @param depth Child path actually targeted for watch
|
|
1344
1343
|
* @param target Child path actually targeted for watch
|
|
1345
1344
|
*/
|
|
1346
|
-
async _addToNodeFs(
|
|
1345
|
+
async _addToNodeFs(path7, initialAdd, priorWh, depth, target) {
|
|
1347
1346
|
const ready = this.fsw._emitReady;
|
|
1348
|
-
if (this.fsw._isIgnored(
|
|
1347
|
+
if (this.fsw._isIgnored(path7) || this.fsw.closed) {
|
|
1349
1348
|
ready();
|
|
1350
1349
|
return false;
|
|
1351
1350
|
}
|
|
1352
|
-
const wh = this.fsw._getWatchHelpers(
|
|
1351
|
+
const wh = this.fsw._getWatchHelpers(path7);
|
|
1353
1352
|
if (priorWh) {
|
|
1354
1353
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
1355
1354
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -1365,8 +1364,8 @@ var NodeFsHandler = class {
|
|
|
1365
1364
|
const follow = this.fsw.options.followSymlinks;
|
|
1366
1365
|
let closer;
|
|
1367
1366
|
if (stats.isDirectory()) {
|
|
1368
|
-
const absPath = sp.resolve(
|
|
1369
|
-
const targetPath = follow ? await fsrealpath(
|
|
1367
|
+
const absPath = sp.resolve(path7);
|
|
1368
|
+
const targetPath = follow ? await fsrealpath(path7) : path7;
|
|
1370
1369
|
if (this.fsw.closed)
|
|
1371
1370
|
return;
|
|
1372
1371
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -1376,29 +1375,29 @@ var NodeFsHandler = class {
|
|
|
1376
1375
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
1377
1376
|
}
|
|
1378
1377
|
} else if (stats.isSymbolicLink()) {
|
|
1379
|
-
const targetPath = follow ? await fsrealpath(
|
|
1378
|
+
const targetPath = follow ? await fsrealpath(path7) : path7;
|
|
1380
1379
|
if (this.fsw.closed)
|
|
1381
1380
|
return;
|
|
1382
1381
|
const parent = sp.dirname(wh.watchPath);
|
|
1383
1382
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
1384
1383
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
1385
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
1384
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path7, wh, targetPath);
|
|
1386
1385
|
if (this.fsw.closed)
|
|
1387
1386
|
return;
|
|
1388
1387
|
if (targetPath !== void 0) {
|
|
1389
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
1388
|
+
this.fsw._symlinkPaths.set(sp.resolve(path7), targetPath);
|
|
1390
1389
|
}
|
|
1391
1390
|
} else {
|
|
1392
1391
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
1393
1392
|
}
|
|
1394
1393
|
ready();
|
|
1395
1394
|
if (closer)
|
|
1396
|
-
this.fsw._addPathCloser(
|
|
1395
|
+
this.fsw._addPathCloser(path7, closer);
|
|
1397
1396
|
return false;
|
|
1398
1397
|
} catch (error) {
|
|
1399
1398
|
if (this.fsw._handleError(error)) {
|
|
1400
1399
|
ready();
|
|
1401
|
-
return
|
|
1400
|
+
return path7;
|
|
1402
1401
|
}
|
|
1403
1402
|
}
|
|
1404
1403
|
}
|
|
@@ -1441,24 +1440,24 @@ function createPattern(matcher) {
|
|
|
1441
1440
|
}
|
|
1442
1441
|
return () => false;
|
|
1443
1442
|
}
|
|
1444
|
-
function normalizePath(
|
|
1445
|
-
if (typeof
|
|
1443
|
+
function normalizePath(path7) {
|
|
1444
|
+
if (typeof path7 !== "string")
|
|
1446
1445
|
throw new Error("string expected");
|
|
1447
|
-
|
|
1448
|
-
|
|
1446
|
+
path7 = sp2.normalize(path7);
|
|
1447
|
+
path7 = path7.replace(/\\/g, "/");
|
|
1449
1448
|
let prepend = false;
|
|
1450
|
-
if (
|
|
1449
|
+
if (path7.startsWith("//"))
|
|
1451
1450
|
prepend = true;
|
|
1452
|
-
|
|
1451
|
+
path7 = path7.replace(DOUBLE_SLASH_RE, "/");
|
|
1453
1452
|
if (prepend)
|
|
1454
|
-
|
|
1455
|
-
return
|
|
1453
|
+
path7 = "/" + path7;
|
|
1454
|
+
return path7;
|
|
1456
1455
|
}
|
|
1457
1456
|
function matchPatterns(patterns, testString, stats) {
|
|
1458
|
-
const
|
|
1457
|
+
const path7 = normalizePath(testString);
|
|
1459
1458
|
for (let index = 0; index < patterns.length; index++) {
|
|
1460
1459
|
const pattern = patterns[index];
|
|
1461
|
-
if (pattern(
|
|
1460
|
+
if (pattern(path7, stats)) {
|
|
1462
1461
|
return true;
|
|
1463
1462
|
}
|
|
1464
1463
|
}
|
|
@@ -1496,19 +1495,19 @@ var toUnix = (string) => {
|
|
|
1496
1495
|
}
|
|
1497
1496
|
return str;
|
|
1498
1497
|
};
|
|
1499
|
-
var normalizePathToUnix = (
|
|
1500
|
-
var normalizeIgnored = (cwd = "") => (
|
|
1501
|
-
if (typeof
|
|
1502
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
1498
|
+
var normalizePathToUnix = (path7) => toUnix(sp2.normalize(toUnix(path7)));
|
|
1499
|
+
var normalizeIgnored = (cwd = "") => (path7) => {
|
|
1500
|
+
if (typeof path7 === "string") {
|
|
1501
|
+
return normalizePathToUnix(sp2.isAbsolute(path7) ? path7 : sp2.join(cwd, path7));
|
|
1503
1502
|
} else {
|
|
1504
|
-
return
|
|
1503
|
+
return path7;
|
|
1505
1504
|
}
|
|
1506
1505
|
};
|
|
1507
|
-
var getAbsolutePath = (
|
|
1508
|
-
if (sp2.isAbsolute(
|
|
1509
|
-
return
|
|
1506
|
+
var getAbsolutePath = (path7, cwd) => {
|
|
1507
|
+
if (sp2.isAbsolute(path7)) {
|
|
1508
|
+
return path7;
|
|
1510
1509
|
}
|
|
1511
|
-
return sp2.join(cwd,
|
|
1510
|
+
return sp2.join(cwd, path7);
|
|
1512
1511
|
};
|
|
1513
1512
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
1514
1513
|
var DirEntry = class {
|
|
@@ -1573,10 +1572,10 @@ var WatchHelper = class {
|
|
|
1573
1572
|
dirParts;
|
|
1574
1573
|
followSymlinks;
|
|
1575
1574
|
statMethod;
|
|
1576
|
-
constructor(
|
|
1575
|
+
constructor(path7, follow, fsw) {
|
|
1577
1576
|
this.fsw = fsw;
|
|
1578
|
-
const watchPath =
|
|
1579
|
-
this.path =
|
|
1577
|
+
const watchPath = path7;
|
|
1578
|
+
this.path = path7 = path7.replace(REPLACER_RE, "");
|
|
1580
1579
|
this.watchPath = watchPath;
|
|
1581
1580
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
1582
1581
|
this.dirParts = [];
|
|
@@ -1716,20 +1715,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1716
1715
|
this._closePromise = void 0;
|
|
1717
1716
|
let paths = unifyPaths(paths_);
|
|
1718
1717
|
if (cwd) {
|
|
1719
|
-
paths = paths.map((
|
|
1720
|
-
const absPath = getAbsolutePath(
|
|
1718
|
+
paths = paths.map((path7) => {
|
|
1719
|
+
const absPath = getAbsolutePath(path7, cwd);
|
|
1721
1720
|
return absPath;
|
|
1722
1721
|
});
|
|
1723
1722
|
}
|
|
1724
|
-
paths.forEach((
|
|
1725
|
-
this._removeIgnoredPath(
|
|
1723
|
+
paths.forEach((path7) => {
|
|
1724
|
+
this._removeIgnoredPath(path7);
|
|
1726
1725
|
});
|
|
1727
1726
|
this._userIgnored = void 0;
|
|
1728
1727
|
if (!this._readyCount)
|
|
1729
1728
|
this._readyCount = 0;
|
|
1730
1729
|
this._readyCount += paths.length;
|
|
1731
|
-
Promise.all(paths.map(async (
|
|
1732
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
1730
|
+
Promise.all(paths.map(async (path7) => {
|
|
1731
|
+
const res = await this._nodeFsHandler._addToNodeFs(path7, !_internal, void 0, 0, _origAdd);
|
|
1733
1732
|
if (res)
|
|
1734
1733
|
this._emitReady();
|
|
1735
1734
|
return res;
|
|
@@ -1751,17 +1750,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1751
1750
|
return this;
|
|
1752
1751
|
const paths = unifyPaths(paths_);
|
|
1753
1752
|
const { cwd } = this.options;
|
|
1754
|
-
paths.forEach((
|
|
1755
|
-
if (!sp2.isAbsolute(
|
|
1753
|
+
paths.forEach((path7) => {
|
|
1754
|
+
if (!sp2.isAbsolute(path7) && !this._closers.has(path7)) {
|
|
1756
1755
|
if (cwd)
|
|
1757
|
-
|
|
1758
|
-
|
|
1756
|
+
path7 = sp2.join(cwd, path7);
|
|
1757
|
+
path7 = sp2.resolve(path7);
|
|
1759
1758
|
}
|
|
1760
|
-
this._closePath(
|
|
1761
|
-
this._addIgnoredPath(
|
|
1762
|
-
if (this._watched.has(
|
|
1759
|
+
this._closePath(path7);
|
|
1760
|
+
this._addIgnoredPath(path7);
|
|
1761
|
+
if (this._watched.has(path7)) {
|
|
1763
1762
|
this._addIgnoredPath({
|
|
1764
|
-
path:
|
|
1763
|
+
path: path7,
|
|
1765
1764
|
recursive: true
|
|
1766
1765
|
});
|
|
1767
1766
|
}
|
|
@@ -1825,38 +1824,38 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1825
1824
|
* @param stats arguments to be passed with event
|
|
1826
1825
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
1827
1826
|
*/
|
|
1828
|
-
async _emit(event,
|
|
1827
|
+
async _emit(event, path7, stats) {
|
|
1829
1828
|
if (this.closed)
|
|
1830
1829
|
return;
|
|
1831
1830
|
const opts = this.options;
|
|
1832
1831
|
if (isWindows)
|
|
1833
|
-
|
|
1832
|
+
path7 = sp2.normalize(path7);
|
|
1834
1833
|
if (opts.cwd)
|
|
1835
|
-
|
|
1836
|
-
const args = [
|
|
1834
|
+
path7 = sp2.relative(opts.cwd, path7);
|
|
1835
|
+
const args = [path7];
|
|
1837
1836
|
if (stats != null)
|
|
1838
1837
|
args.push(stats);
|
|
1839
1838
|
const awf = opts.awaitWriteFinish;
|
|
1840
1839
|
let pw;
|
|
1841
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
1840
|
+
if (awf && (pw = this._pendingWrites.get(path7))) {
|
|
1842
1841
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
1843
1842
|
return this;
|
|
1844
1843
|
}
|
|
1845
1844
|
if (opts.atomic) {
|
|
1846
1845
|
if (event === EVENTS.UNLINK) {
|
|
1847
|
-
this._pendingUnlinks.set(
|
|
1846
|
+
this._pendingUnlinks.set(path7, [event, ...args]);
|
|
1848
1847
|
setTimeout(() => {
|
|
1849
|
-
this._pendingUnlinks.forEach((entry,
|
|
1848
|
+
this._pendingUnlinks.forEach((entry, path8) => {
|
|
1850
1849
|
this.emit(...entry);
|
|
1851
1850
|
this.emit(EVENTS.ALL, ...entry);
|
|
1852
|
-
this._pendingUnlinks.delete(
|
|
1851
|
+
this._pendingUnlinks.delete(path8);
|
|
1853
1852
|
});
|
|
1854
1853
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
1855
1854
|
return this;
|
|
1856
1855
|
}
|
|
1857
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
1856
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path7)) {
|
|
1858
1857
|
event = EVENTS.CHANGE;
|
|
1859
|
-
this._pendingUnlinks.delete(
|
|
1858
|
+
this._pendingUnlinks.delete(path7);
|
|
1860
1859
|
}
|
|
1861
1860
|
}
|
|
1862
1861
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -1874,16 +1873,16 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1874
1873
|
this.emitWithAll(event, args);
|
|
1875
1874
|
}
|
|
1876
1875
|
};
|
|
1877
|
-
this._awaitWriteFinish(
|
|
1876
|
+
this._awaitWriteFinish(path7, awf.stabilityThreshold, event, awfEmit);
|
|
1878
1877
|
return this;
|
|
1879
1878
|
}
|
|
1880
1879
|
if (event === EVENTS.CHANGE) {
|
|
1881
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
1880
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path7, 50);
|
|
1882
1881
|
if (isThrottled)
|
|
1883
1882
|
return this;
|
|
1884
1883
|
}
|
|
1885
1884
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
1886
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
1885
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path7) : path7;
|
|
1887
1886
|
let stats2;
|
|
1888
1887
|
try {
|
|
1889
1888
|
stats2 = await stat3(fullPath);
|
|
@@ -1914,23 +1913,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1914
1913
|
* @param timeout duration of time to suppress duplicate actions
|
|
1915
1914
|
* @returns tracking object or false if action should be suppressed
|
|
1916
1915
|
*/
|
|
1917
|
-
_throttle(actionType,
|
|
1916
|
+
_throttle(actionType, path7, timeout) {
|
|
1918
1917
|
if (!this._throttled.has(actionType)) {
|
|
1919
1918
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
1920
1919
|
}
|
|
1921
1920
|
const action = this._throttled.get(actionType);
|
|
1922
1921
|
if (!action)
|
|
1923
1922
|
throw new Error("invalid throttle");
|
|
1924
|
-
const actionPath = action.get(
|
|
1923
|
+
const actionPath = action.get(path7);
|
|
1925
1924
|
if (actionPath) {
|
|
1926
1925
|
actionPath.count++;
|
|
1927
1926
|
return false;
|
|
1928
1927
|
}
|
|
1929
1928
|
let timeoutObject;
|
|
1930
1929
|
const clear = () => {
|
|
1931
|
-
const item = action.get(
|
|
1930
|
+
const item = action.get(path7);
|
|
1932
1931
|
const count = item ? item.count : 0;
|
|
1933
|
-
action.delete(
|
|
1932
|
+
action.delete(path7);
|
|
1934
1933
|
clearTimeout(timeoutObject);
|
|
1935
1934
|
if (item)
|
|
1936
1935
|
clearTimeout(item.timeoutObject);
|
|
@@ -1938,7 +1937,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1938
1937
|
};
|
|
1939
1938
|
timeoutObject = setTimeout(clear, timeout);
|
|
1940
1939
|
const thr = { timeoutObject, clear, count: 0 };
|
|
1941
|
-
action.set(
|
|
1940
|
+
action.set(path7, thr);
|
|
1942
1941
|
return thr;
|
|
1943
1942
|
}
|
|
1944
1943
|
_incrReadyCount() {
|
|
@@ -1952,44 +1951,44 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1952
1951
|
* @param event
|
|
1953
1952
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
1954
1953
|
*/
|
|
1955
|
-
_awaitWriteFinish(
|
|
1954
|
+
_awaitWriteFinish(path7, threshold, event, awfEmit) {
|
|
1956
1955
|
const awf = this.options.awaitWriteFinish;
|
|
1957
1956
|
if (typeof awf !== "object")
|
|
1958
1957
|
return;
|
|
1959
1958
|
const pollInterval = awf.pollInterval;
|
|
1960
1959
|
let timeoutHandler;
|
|
1961
|
-
let fullPath =
|
|
1962
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
1963
|
-
fullPath = sp2.join(this.options.cwd,
|
|
1960
|
+
let fullPath = path7;
|
|
1961
|
+
if (this.options.cwd && !sp2.isAbsolute(path7)) {
|
|
1962
|
+
fullPath = sp2.join(this.options.cwd, path7);
|
|
1964
1963
|
}
|
|
1965
1964
|
const now = /* @__PURE__ */ new Date();
|
|
1966
1965
|
const writes = this._pendingWrites;
|
|
1967
1966
|
function awaitWriteFinishFn(prevStat) {
|
|
1968
1967
|
statcb(fullPath, (err, curStat) => {
|
|
1969
|
-
if (err || !writes.has(
|
|
1968
|
+
if (err || !writes.has(path7)) {
|
|
1970
1969
|
if (err && err.code !== "ENOENT")
|
|
1971
1970
|
awfEmit(err);
|
|
1972
1971
|
return;
|
|
1973
1972
|
}
|
|
1974
1973
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
1975
1974
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
1976
|
-
writes.get(
|
|
1975
|
+
writes.get(path7).lastChange = now2;
|
|
1977
1976
|
}
|
|
1978
|
-
const pw = writes.get(
|
|
1977
|
+
const pw = writes.get(path7);
|
|
1979
1978
|
const df = now2 - pw.lastChange;
|
|
1980
1979
|
if (df >= threshold) {
|
|
1981
|
-
writes.delete(
|
|
1980
|
+
writes.delete(path7);
|
|
1982
1981
|
awfEmit(void 0, curStat);
|
|
1983
1982
|
} else {
|
|
1984
1983
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
1985
1984
|
}
|
|
1986
1985
|
});
|
|
1987
1986
|
}
|
|
1988
|
-
if (!writes.has(
|
|
1989
|
-
writes.set(
|
|
1987
|
+
if (!writes.has(path7)) {
|
|
1988
|
+
writes.set(path7, {
|
|
1990
1989
|
lastChange: now,
|
|
1991
1990
|
cancelWait: () => {
|
|
1992
|
-
writes.delete(
|
|
1991
|
+
writes.delete(path7);
|
|
1993
1992
|
clearTimeout(timeoutHandler);
|
|
1994
1993
|
return event;
|
|
1995
1994
|
}
|
|
@@ -2000,8 +1999,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2000
1999
|
/**
|
|
2001
2000
|
* Determines whether user has asked to ignore this path.
|
|
2002
2001
|
*/
|
|
2003
|
-
_isIgnored(
|
|
2004
|
-
if (this.options.atomic && DOT_RE.test(
|
|
2002
|
+
_isIgnored(path7, stats) {
|
|
2003
|
+
if (this.options.atomic && DOT_RE.test(path7))
|
|
2005
2004
|
return true;
|
|
2006
2005
|
if (!this._userIgnored) {
|
|
2007
2006
|
const { cwd } = this.options;
|
|
@@ -2011,17 +2010,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2011
2010
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
2012
2011
|
this._userIgnored = anymatch(list, void 0);
|
|
2013
2012
|
}
|
|
2014
|
-
return this._userIgnored(
|
|
2013
|
+
return this._userIgnored(path7, stats);
|
|
2015
2014
|
}
|
|
2016
|
-
_isntIgnored(
|
|
2017
|
-
return !this._isIgnored(
|
|
2015
|
+
_isntIgnored(path7, stat4) {
|
|
2016
|
+
return !this._isIgnored(path7, stat4);
|
|
2018
2017
|
}
|
|
2019
2018
|
/**
|
|
2020
2019
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
2021
2020
|
* @param path file or directory pattern being watched
|
|
2022
2021
|
*/
|
|
2023
|
-
_getWatchHelpers(
|
|
2024
|
-
return new WatchHelper(
|
|
2022
|
+
_getWatchHelpers(path7) {
|
|
2023
|
+
return new WatchHelper(path7, this.options.followSymlinks, this);
|
|
2025
2024
|
}
|
|
2026
2025
|
// Directory helpers
|
|
2027
2026
|
// -----------------
|
|
@@ -2053,63 +2052,63 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2053
2052
|
* @param item base path of item/directory
|
|
2054
2053
|
*/
|
|
2055
2054
|
_remove(directory, item, isDirectory) {
|
|
2056
|
-
const
|
|
2057
|
-
const fullPath = sp2.resolve(
|
|
2058
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
2059
|
-
if (!this._throttle("remove",
|
|
2055
|
+
const path7 = sp2.join(directory, item);
|
|
2056
|
+
const fullPath = sp2.resolve(path7);
|
|
2057
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path7) || this._watched.has(fullPath);
|
|
2058
|
+
if (!this._throttle("remove", path7, 100))
|
|
2060
2059
|
return;
|
|
2061
2060
|
if (!isDirectory && this._watched.size === 1) {
|
|
2062
2061
|
this.add(directory, item, true);
|
|
2063
2062
|
}
|
|
2064
|
-
const wp = this._getWatchedDir(
|
|
2063
|
+
const wp = this._getWatchedDir(path7);
|
|
2065
2064
|
const nestedDirectoryChildren = wp.getChildren();
|
|
2066
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
2065
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path7, nested));
|
|
2067
2066
|
const parent = this._getWatchedDir(directory);
|
|
2068
2067
|
const wasTracked = parent.has(item);
|
|
2069
2068
|
parent.remove(item);
|
|
2070
2069
|
if (this._symlinkPaths.has(fullPath)) {
|
|
2071
2070
|
this._symlinkPaths.delete(fullPath);
|
|
2072
2071
|
}
|
|
2073
|
-
let relPath =
|
|
2072
|
+
let relPath = path7;
|
|
2074
2073
|
if (this.options.cwd)
|
|
2075
|
-
relPath = sp2.relative(this.options.cwd,
|
|
2074
|
+
relPath = sp2.relative(this.options.cwd, path7);
|
|
2076
2075
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
2077
2076
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
2078
2077
|
if (event === EVENTS.ADD)
|
|
2079
2078
|
return;
|
|
2080
2079
|
}
|
|
2081
|
-
this._watched.delete(
|
|
2080
|
+
this._watched.delete(path7);
|
|
2082
2081
|
this._watched.delete(fullPath);
|
|
2083
2082
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
2084
|
-
if (wasTracked && !this._isIgnored(
|
|
2085
|
-
this._emit(eventName,
|
|
2086
|
-
this._closePath(
|
|
2083
|
+
if (wasTracked && !this._isIgnored(path7))
|
|
2084
|
+
this._emit(eventName, path7);
|
|
2085
|
+
this._closePath(path7);
|
|
2087
2086
|
}
|
|
2088
2087
|
/**
|
|
2089
2088
|
* Closes all watchers for a path
|
|
2090
2089
|
*/
|
|
2091
|
-
_closePath(
|
|
2092
|
-
this._closeFile(
|
|
2093
|
-
const dir = sp2.dirname(
|
|
2094
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
2090
|
+
_closePath(path7) {
|
|
2091
|
+
this._closeFile(path7);
|
|
2092
|
+
const dir = sp2.dirname(path7);
|
|
2093
|
+
this._getWatchedDir(dir).remove(sp2.basename(path7));
|
|
2095
2094
|
}
|
|
2096
2095
|
/**
|
|
2097
2096
|
* Closes only file-specific watchers
|
|
2098
2097
|
*/
|
|
2099
|
-
_closeFile(
|
|
2100
|
-
const closers = this._closers.get(
|
|
2098
|
+
_closeFile(path7) {
|
|
2099
|
+
const closers = this._closers.get(path7);
|
|
2101
2100
|
if (!closers)
|
|
2102
2101
|
return;
|
|
2103
2102
|
closers.forEach((closer) => closer());
|
|
2104
|
-
this._closers.delete(
|
|
2103
|
+
this._closers.delete(path7);
|
|
2105
2104
|
}
|
|
2106
|
-
_addPathCloser(
|
|
2105
|
+
_addPathCloser(path7, closer) {
|
|
2107
2106
|
if (!closer)
|
|
2108
2107
|
return;
|
|
2109
|
-
let list = this._closers.get(
|
|
2108
|
+
let list = this._closers.get(path7);
|
|
2110
2109
|
if (!list) {
|
|
2111
2110
|
list = [];
|
|
2112
|
-
this._closers.set(
|
|
2111
|
+
this._closers.set(path7, list);
|
|
2113
2112
|
}
|
|
2114
2113
|
list.push(closer);
|
|
2115
2114
|
}
|
|
@@ -2205,358 +2204,10 @@ var PlanWatcher = class {
|
|
|
2205
2204
|
}
|
|
2206
2205
|
};
|
|
2207
2206
|
|
|
2208
|
-
// src/daemon/digest.ts
|
|
2209
|
-
var import_yaml = __toESM(require_dist(), 1);
|
|
2210
|
-
import fs3 from "fs";
|
|
2211
|
-
import path4 from "path";
|
|
2212
|
-
import crypto from "crypto";
|
|
2213
|
-
var PREVIOUS_EXTRACT_OVERHEAD_TOKENS = 50;
|
|
2214
|
-
var CONTEXT_SAFETY_MARGIN = 0.7;
|
|
2215
|
-
var EXTRACT_TYPE = "extract";
|
|
2216
|
-
var DigestEngine = class {
|
|
2217
|
-
vaultDir;
|
|
2218
|
-
index;
|
|
2219
|
-
llm;
|
|
2220
|
-
config;
|
|
2221
|
-
log;
|
|
2222
|
-
lastCycleTimestampCache = void 0;
|
|
2223
|
-
cycleInProgress = false;
|
|
2224
|
-
modelReady = false;
|
|
2225
|
-
constructor(engineConfig) {
|
|
2226
|
-
this.vaultDir = engineConfig.vaultDir;
|
|
2227
|
-
this.index = engineConfig.index;
|
|
2228
|
-
this.llm = engineConfig.llmProvider;
|
|
2229
|
-
this.config = engineConfig.config;
|
|
2230
|
-
this.log = engineConfig.log ?? (() => {
|
|
2231
|
-
});
|
|
2232
|
-
}
|
|
2233
|
-
/**
|
|
2234
|
-
* Query index for recent vault notes to feed into the digest.
|
|
2235
|
-
* Filters out extract notes (our own output) and caps at max_notes_per_cycle.
|
|
2236
|
-
*/
|
|
2237
|
-
discoverSubstrate(lastCycleTimestamp) {
|
|
2238
|
-
const maxNotes = this.config.digest.substrate.max_notes_per_cycle;
|
|
2239
|
-
const notes = lastCycleTimestamp ? this.index.query({ updatedSince: lastCycleTimestamp, limit: maxNotes }) : this.index.query({ limit: maxNotes });
|
|
2240
|
-
const filtered = notes.filter((n) => n.type !== EXTRACT_TYPE);
|
|
2241
|
-
filtered.sort((a, b) => {
|
|
2242
|
-
const weightA = DIGEST_SUBSTRATE_TYPE_WEIGHTS[a.type] ?? 0;
|
|
2243
|
-
const weightB = DIGEST_SUBSTRATE_TYPE_WEIGHTS[b.type] ?? 0;
|
|
2244
|
-
if (weightB !== weightA) return weightB - weightA;
|
|
2245
|
-
return b.created.localeCompare(a.created);
|
|
2246
|
-
});
|
|
2247
|
-
return filtered.slice(0, maxNotes);
|
|
2248
|
-
}
|
|
2249
|
-
/**
|
|
2250
|
-
* Filter configured tiers by the context window available.
|
|
2251
|
-
* Only tiers whose minimum context requirement is met are eligible.
|
|
2252
|
-
*/
|
|
2253
|
-
getEligibleTiers() {
|
|
2254
|
-
const contextWindow = this.config.digest.intelligence.context_window;
|
|
2255
|
-
return this.config.digest.tiers.filter((tier) => {
|
|
2256
|
-
const minContext = DIGEST_TIER_MIN_CONTEXT[tier];
|
|
2257
|
-
return minContext !== void 0 && minContext <= contextWindow;
|
|
2258
|
-
});
|
|
2259
|
-
}
|
|
2260
|
-
/**
|
|
2261
|
-
* Format notes compactly for inclusion in the digest prompt.
|
|
2262
|
-
* Stops adding notes once the token budget is exceeded.
|
|
2263
|
-
*/
|
|
2264
|
-
formatSubstrate(notes, tokenBudget) {
|
|
2265
|
-
const charBudget = tokenBudget * CHARS_PER_TOKEN;
|
|
2266
|
-
const parts = [];
|
|
2267
|
-
let usedChars = 0;
|
|
2268
|
-
for (const note of notes) {
|
|
2269
|
-
const entry = `### [${note.type}] ${note.id} \u2014 "${note.title}"
|
|
2270
|
-
${note.content}`;
|
|
2271
|
-
if (usedChars + entry.length > charBudget && parts.length > 0) break;
|
|
2272
|
-
parts.push(entry);
|
|
2273
|
-
usedChars += entry.length;
|
|
2274
|
-
}
|
|
2275
|
-
return parts.join("\n\n");
|
|
2276
|
-
}
|
|
2277
|
-
/**
|
|
2278
|
-
* Read a previously generated extract for a given tier.
|
|
2279
|
-
* Returns the body (stripped of YAML frontmatter), or null if not found.
|
|
2280
|
-
*/
|
|
2281
|
-
readPreviousExtract(tier) {
|
|
2282
|
-
const extractPath = path4.join(this.vaultDir, "digest", `extract-${tier}.md`);
|
|
2283
|
-
let content;
|
|
2284
|
-
try {
|
|
2285
|
-
content = fs3.readFileSync(extractPath, "utf-8");
|
|
2286
|
-
} catch {
|
|
2287
|
-
return null;
|
|
2288
|
-
}
|
|
2289
|
-
return stripFrontmatter(content).body;
|
|
2290
|
-
}
|
|
2291
|
-
/**
|
|
2292
|
-
* Write a digest extract to the vault with YAML frontmatter.
|
|
2293
|
-
* Uses atomic write pattern (temp file + rename).
|
|
2294
|
-
*/
|
|
2295
|
-
writeExtract(tier, body, cycleId, model, substrateCount) {
|
|
2296
|
-
const digestDir = path4.join(this.vaultDir, "digest");
|
|
2297
|
-
fs3.mkdirSync(digestDir, { recursive: true });
|
|
2298
|
-
const frontmatter = {
|
|
2299
|
-
type: EXTRACT_TYPE,
|
|
2300
|
-
tier,
|
|
2301
|
-
generated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2302
|
-
cycle_id: cycleId,
|
|
2303
|
-
substrate_count: substrateCount,
|
|
2304
|
-
model
|
|
2305
|
-
};
|
|
2306
|
-
const fmYaml = import_yaml.default.stringify(frontmatter, {
|
|
2307
|
-
defaultStringType: "QUOTE_DOUBLE",
|
|
2308
|
-
defaultKeyType: "PLAIN"
|
|
2309
|
-
}).trim();
|
|
2310
|
-
const file = `---
|
|
2311
|
-
${fmYaml}
|
|
2312
|
-
---
|
|
2313
|
-
|
|
2314
|
-
${body}
|
|
2315
|
-
`;
|
|
2316
|
-
const fullPath = path4.join(digestDir, `extract-${tier}.md`);
|
|
2317
|
-
const tmpPath = `${fullPath}.tmp`;
|
|
2318
|
-
fs3.writeFileSync(tmpPath, file, "utf-8");
|
|
2319
|
-
fs3.renameSync(tmpPath, fullPath);
|
|
2320
|
-
}
|
|
2321
|
-
/**
|
|
2322
|
-
* Append a digest cycle result as a JSON line to trace.jsonl.
|
|
2323
|
-
*/
|
|
2324
|
-
appendTrace(record) {
|
|
2325
|
-
const digestDir = path4.join(this.vaultDir, "digest");
|
|
2326
|
-
fs3.mkdirSync(digestDir, { recursive: true });
|
|
2327
|
-
const tracePath = path4.join(digestDir, "trace.jsonl");
|
|
2328
|
-
fs3.appendFileSync(tracePath, JSON.stringify(record) + "\n", "utf-8");
|
|
2329
|
-
this.lastCycleTimestampCache = record.timestamp;
|
|
2330
|
-
}
|
|
2331
|
-
/**
|
|
2332
|
-
* Read the last cycle timestamp from trace.jsonl.
|
|
2333
|
-
* Cached in memory after first read — subsequent calls are O(1).
|
|
2334
|
-
*/
|
|
2335
|
-
getLastCycleTimestamp() {
|
|
2336
|
-
if (this.lastCycleTimestampCache !== void 0) return this.lastCycleTimestampCache;
|
|
2337
|
-
const tracePath = path4.join(this.vaultDir, "digest", "trace.jsonl");
|
|
2338
|
-
let content;
|
|
2339
|
-
try {
|
|
2340
|
-
content = fs3.readFileSync(tracePath, "utf-8").trim();
|
|
2341
|
-
} catch {
|
|
2342
|
-
this.lastCycleTimestampCache = null;
|
|
2343
|
-
return null;
|
|
2344
|
-
}
|
|
2345
|
-
if (!content) {
|
|
2346
|
-
this.lastCycleTimestampCache = null;
|
|
2347
|
-
return null;
|
|
2348
|
-
}
|
|
2349
|
-
const lines = content.split("\n");
|
|
2350
|
-
const lastLine = lines[lines.length - 1];
|
|
2351
|
-
try {
|
|
2352
|
-
const record = JSON.parse(lastLine);
|
|
2353
|
-
this.lastCycleTimestampCache = record.timestamp;
|
|
2354
|
-
return record.timestamp;
|
|
2355
|
-
} catch {
|
|
2356
|
-
this.lastCycleTimestampCache = null;
|
|
2357
|
-
return null;
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
/**
|
|
2361
|
-
* Run a full digest cycle: discover substrate, generate extracts for each tier.
|
|
2362
|
-
* Returns the cycle result, or null if no substrate was found.
|
|
2363
|
-
*/
|
|
2364
|
-
async runCycle() {
|
|
2365
|
-
if (this.cycleInProgress) {
|
|
2366
|
-
this.log("debug", "Cycle already in progress \u2014 skipping");
|
|
2367
|
-
return null;
|
|
2368
|
-
}
|
|
2369
|
-
this.cycleInProgress = true;
|
|
2370
|
-
try {
|
|
2371
|
-
return await this.runCycleInternal();
|
|
2372
|
-
} finally {
|
|
2373
|
-
this.cycleInProgress = false;
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
async runCycleInternal() {
|
|
2377
|
-
if (!this.modelReady && this.llm.ensureLoaded) {
|
|
2378
|
-
const { context_window: contextWindow, gpu_kv_cache: gpuKvCache } = this.config.digest.intelligence;
|
|
2379
|
-
this.log("info", "Loading digest model", { contextWindow, gpuKvCache });
|
|
2380
|
-
await this.llm.ensureLoaded(contextWindow, gpuKvCache);
|
|
2381
|
-
this.modelReady = true;
|
|
2382
|
-
}
|
|
2383
|
-
const startTime = Date.now();
|
|
2384
|
-
const lastTimestamp = this.getLastCycleTimestamp();
|
|
2385
|
-
const substrate = this.discoverSubstrate(lastTimestamp);
|
|
2386
|
-
this.log("debug", "Discovering substrate", { lastTimestamp: lastTimestamp ?? "cold start", substrateCount: substrate.length });
|
|
2387
|
-
if (substrate.length === 0) {
|
|
2388
|
-
this.log("debug", "No substrate found \u2014 skipping cycle");
|
|
2389
|
-
return null;
|
|
2390
|
-
}
|
|
2391
|
-
this.log("info", `Starting digest cycle`, { substrateCount: substrate.length });
|
|
2392
|
-
const cycleId = crypto.randomUUID();
|
|
2393
|
-
const eligibleTiers = this.getEligibleTiers();
|
|
2394
|
-
this.log("debug", `Eligible tiers: [${eligibleTiers.join(", ")}]`);
|
|
2395
|
-
const tiersGenerated = [];
|
|
2396
|
-
let totalTokensUsed = 0;
|
|
2397
|
-
let model = "";
|
|
2398
|
-
const typeToKey = {
|
|
2399
|
-
session: "sessions",
|
|
2400
|
-
spore: "spores",
|
|
2401
|
-
plan: "plans",
|
|
2402
|
-
artifact: "artifacts",
|
|
2403
|
-
"team-member": "team"
|
|
2404
|
-
};
|
|
2405
|
-
const substrateIndex = {
|
|
2406
|
-
sessions: [],
|
|
2407
|
-
spores: [],
|
|
2408
|
-
plans: [],
|
|
2409
|
-
artifacts: [],
|
|
2410
|
-
team: []
|
|
2411
|
-
};
|
|
2412
|
-
for (const note of substrate) {
|
|
2413
|
-
const key = typeToKey[note.type];
|
|
2414
|
-
if (key) {
|
|
2415
|
-
substrateIndex[key].push(note.id);
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
const systemPrompt = loadPrompt("digest-system");
|
|
2419
|
-
for (const tier of eligibleTiers) {
|
|
2420
|
-
const tierPrompt = loadPrompt(`digest-${tier}`);
|
|
2421
|
-
const previousExtract = this.readPreviousExtract(tier);
|
|
2422
|
-
const contextWindow = this.config.digest.intelligence.context_window;
|
|
2423
|
-
const systemPromptTokens = estimateTokens(systemPrompt);
|
|
2424
|
-
const tierPromptTokens = estimateTokens(tierPrompt);
|
|
2425
|
-
const previousExtractTokens = previousExtract ? estimateTokens(previousExtract) + PREVIOUS_EXTRACT_OVERHEAD_TOKENS : 0;
|
|
2426
|
-
const availableTokens = Math.floor(contextWindow * CONTEXT_SAFETY_MARGIN);
|
|
2427
|
-
const substrateBudget = availableTokens - tier - systemPromptTokens - tierPromptTokens - previousExtractTokens;
|
|
2428
|
-
if (substrateBudget <= 0) continue;
|
|
2429
|
-
const formattedSubstrate = this.formatSubstrate(substrate, substrateBudget);
|
|
2430
|
-
const promptParts = [tierPrompt];
|
|
2431
|
-
if (previousExtract) {
|
|
2432
|
-
promptParts.push("", "## Previous Synthesis", "", previousExtract);
|
|
2433
|
-
}
|
|
2434
|
-
promptParts.push("", "## New Substrate", "", formattedSubstrate);
|
|
2435
|
-
promptParts.push(
|
|
2436
|
-
"",
|
|
2437
|
-
"---",
|
|
2438
|
-
"Produce your updated synthesis now. Stay within the token budget specified above."
|
|
2439
|
-
);
|
|
2440
|
-
const userPrompt = promptParts.join("\n");
|
|
2441
|
-
const promptTokens = estimateTokens(systemPrompt + userPrompt);
|
|
2442
|
-
this.log("debug", `Tier ${tier}: sending LLM request`, { promptTokens, maxTokens: tier, substrateBudget });
|
|
2443
|
-
const tierStart = Date.now();
|
|
2444
|
-
const digestConfig = this.config.digest.intelligence;
|
|
2445
|
-
const opts = {
|
|
2446
|
-
maxTokens: tier,
|
|
2447
|
-
timeoutMs: DIGEST_LLM_REQUEST_TIMEOUT_MS,
|
|
2448
|
-
contextLength: contextWindow,
|
|
2449
|
-
reasoning: "off",
|
|
2450
|
-
systemPrompt,
|
|
2451
|
-
keepAlive: digestConfig.keep_alive ?? void 0
|
|
2452
|
-
};
|
|
2453
|
-
const response = await this.llm.summarize(userPrompt, opts);
|
|
2454
|
-
const tierDuration = Date.now() - tierStart;
|
|
2455
|
-
const extractText = stripReasoningTokens(response.text);
|
|
2456
|
-
model = response.model;
|
|
2457
|
-
const responseTokens = estimateTokens(extractText);
|
|
2458
|
-
totalTokensUsed += promptTokens + responseTokens;
|
|
2459
|
-
this.log("info", `Tier ${tier}: completed`, { durationMs: tierDuration, responseTokens, model: response.model });
|
|
2460
|
-
this.writeExtract(tier, extractText, cycleId, response.model, substrate.length);
|
|
2461
|
-
tiersGenerated.push(tier);
|
|
2462
|
-
}
|
|
2463
|
-
const result = {
|
|
2464
|
-
cycleId,
|
|
2465
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2466
|
-
substrate: substrateIndex,
|
|
2467
|
-
tiersGenerated,
|
|
2468
|
-
model,
|
|
2469
|
-
durationMs: Date.now() - startTime,
|
|
2470
|
-
tokensUsed: totalTokensUsed
|
|
2471
|
-
};
|
|
2472
|
-
this.appendTrace(result);
|
|
2473
|
-
return result;
|
|
2474
|
-
}
|
|
2475
|
-
};
|
|
2476
|
-
var MS_PER_SECOND2 = 1e3;
|
|
2477
|
-
var Metabolism = class {
|
|
2478
|
-
state = "active";
|
|
2479
|
-
currentIntervalMs;
|
|
2480
|
-
cooldownStep = 0;
|
|
2481
|
-
lastSubstrateTime;
|
|
2482
|
-
timer = null;
|
|
2483
|
-
activeIntervalMs;
|
|
2484
|
-
cooldownIntervalsMs;
|
|
2485
|
-
dormancyThresholdMs;
|
|
2486
|
-
constructor(config) {
|
|
2487
|
-
this.activeIntervalMs = config.active_interval * MS_PER_SECOND2;
|
|
2488
|
-
this.cooldownIntervalsMs = config.cooldown_intervals.map((s) => s * MS_PER_SECOND2);
|
|
2489
|
-
this.dormancyThresholdMs = config.dormancy_threshold * MS_PER_SECOND2;
|
|
2490
|
-
this.currentIntervalMs = this.activeIntervalMs;
|
|
2491
|
-
this.lastSubstrateTime = Date.now();
|
|
2492
|
-
}
|
|
2493
|
-
/** Reset to active state when new substrate is found. */
|
|
2494
|
-
onSubstrateFound() {
|
|
2495
|
-
this.state = "active";
|
|
2496
|
-
this.cooldownStep = 0;
|
|
2497
|
-
this.currentIntervalMs = this.activeIntervalMs;
|
|
2498
|
-
this.lastSubstrateTime = Date.now();
|
|
2499
|
-
}
|
|
2500
|
-
/** Advance cooldown when a cycle finds no new substrate. */
|
|
2501
|
-
onEmptyCycle() {
|
|
2502
|
-
if (this.state === "dormant") return;
|
|
2503
|
-
this.state = "cooling";
|
|
2504
|
-
if (this.cooldownStep < this.cooldownIntervalsMs.length) {
|
|
2505
|
-
this.currentIntervalMs = this.cooldownIntervalsMs[this.cooldownStep];
|
|
2506
|
-
this.cooldownStep++;
|
|
2507
|
-
}
|
|
2508
|
-
this.checkDormancy();
|
|
2509
|
-
}
|
|
2510
|
-
/** Enter dormant state if enough time has elapsed since last substrate. */
|
|
2511
|
-
checkDormancy() {
|
|
2512
|
-
const elapsed = Date.now() - this.lastSubstrateTime;
|
|
2513
|
-
if (elapsed >= this.dormancyThresholdMs) {
|
|
2514
|
-
this.state = "dormant";
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
/** Return to active from any state, resetting timers and rescheduling immediately. */
|
|
2518
|
-
activate() {
|
|
2519
|
-
this.onSubstrateFound();
|
|
2520
|
-
if (this.callback) {
|
|
2521
|
-
this.reschedule();
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
/** Set lastSubstrateTime explicitly (for testing). */
|
|
2525
|
-
markLastSubstrate(time) {
|
|
2526
|
-
this.lastSubstrateTime = time;
|
|
2527
|
-
}
|
|
2528
|
-
/** Begin scheduling digest cycles with adaptive intervals. */
|
|
2529
|
-
start(callback) {
|
|
2530
|
-
this.callback = callback;
|
|
2531
|
-
this.reschedule();
|
|
2532
|
-
}
|
|
2533
|
-
/** Stop the timer. */
|
|
2534
|
-
stop() {
|
|
2535
|
-
if (this.timer) {
|
|
2536
|
-
clearTimeout(this.timer);
|
|
2537
|
-
this.timer = null;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
callback = null;
|
|
2541
|
-
reschedule() {
|
|
2542
|
-
this.stop();
|
|
2543
|
-
if (!this.callback) return;
|
|
2544
|
-
const cb = this.callback;
|
|
2545
|
-
const schedule = () => {
|
|
2546
|
-
this.timer = setTimeout(async () => {
|
|
2547
|
-
await cb();
|
|
2548
|
-
schedule();
|
|
2549
|
-
}, this.currentIntervalMs);
|
|
2550
|
-
this.timer.unref();
|
|
2551
|
-
};
|
|
2552
|
-
schedule();
|
|
2553
|
-
}
|
|
2554
|
-
};
|
|
2555
|
-
|
|
2556
2207
|
// src/artifacts/candidates.ts
|
|
2557
2208
|
import { execFileSync } from "child_process";
|
|
2558
|
-
import
|
|
2559
|
-
import
|
|
2209
|
+
import fs3 from "fs";
|
|
2210
|
+
import path4 from "path";
|
|
2560
2211
|
var EXCLUDED_FILENAMES = /* @__PURE__ */ new Set([
|
|
2561
2212
|
"claude.md",
|
|
2562
2213
|
"agents.md",
|
|
@@ -2577,7 +2228,7 @@ var EXCLUDED_PREFIXES = [
|
|
|
2577
2228
|
".github/"
|
|
2578
2229
|
];
|
|
2579
2230
|
function isExcludedPath(relativePath) {
|
|
2580
|
-
const basename3 =
|
|
2231
|
+
const basename3 = path4.basename(relativePath).toLowerCase();
|
|
2581
2232
|
if (EXCLUDED_FILENAMES.has(basename3)) return true;
|
|
2582
2233
|
const normalized = relativePath.replace(/\\/g, "/");
|
|
2583
2234
|
return EXCLUDED_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
@@ -2585,7 +2236,7 @@ function isExcludedPath(relativePath) {
|
|
|
2585
2236
|
function collectArtifactCandidates(filePaths, config, projectRoot) {
|
|
2586
2237
|
if (filePaths.size === 0) return [];
|
|
2587
2238
|
const extFiltered = [...filePaths].filter(
|
|
2588
|
-
(absPath) => config.artifact_extensions.includes(
|
|
2239
|
+
(absPath) => config.artifact_extensions.includes(path4.extname(absPath))
|
|
2589
2240
|
);
|
|
2590
2241
|
if (extFiltered.length === 0) return [];
|
|
2591
2242
|
const ignoredSet = getGitIgnored(extFiltered, projectRoot);
|
|
@@ -2593,8 +2244,8 @@ function collectArtifactCandidates(filePaths, config, projectRoot) {
|
|
|
2593
2244
|
for (const absPath of extFiltered) {
|
|
2594
2245
|
if (ignoredSet.has(absPath)) continue;
|
|
2595
2246
|
try {
|
|
2596
|
-
const content =
|
|
2597
|
-
const relativePath =
|
|
2247
|
+
const content = fs3.readFileSync(absPath, "utf-8");
|
|
2248
|
+
const relativePath = path4.relative(projectRoot, absPath);
|
|
2598
2249
|
if (isExcludedPath(relativePath)) continue;
|
|
2599
2250
|
candidates.push({ path: relativePath, content });
|
|
2600
2251
|
} catch {
|
|
@@ -2616,23 +2267,23 @@ function getGitIgnored(filePaths, cwd) {
|
|
|
2616
2267
|
}
|
|
2617
2268
|
|
|
2618
2269
|
// src/artifacts/slugify.ts
|
|
2619
|
-
import
|
|
2620
|
-
import
|
|
2270
|
+
import crypto from "crypto";
|
|
2271
|
+
import path5 from "path";
|
|
2621
2272
|
function slugifyPath(relativePath) {
|
|
2622
|
-
const ext =
|
|
2273
|
+
const ext = path5.extname(relativePath);
|
|
2623
2274
|
const withoutExt = ext ? relativePath.slice(0, -ext.length) : relativePath;
|
|
2624
2275
|
let slug = withoutExt.replace(/[/\\]/g, "-").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
|
2625
2276
|
if (slug.length > MAX_SLUG_LENGTH) {
|
|
2626
|
-
const hash =
|
|
2277
|
+
const hash = crypto.createHash("sha256").update(relativePath).digest("hex").slice(0, 6);
|
|
2627
2278
|
slug = slug.slice(0, MAX_SLUG_LENGTH) + "-" + hash;
|
|
2628
2279
|
}
|
|
2629
2280
|
return slug;
|
|
2630
2281
|
}
|
|
2631
2282
|
|
|
2632
2283
|
// src/daemon/main.ts
|
|
2633
|
-
var
|
|
2634
|
-
import
|
|
2635
|
-
import
|
|
2284
|
+
var import_yaml = __toESM(require_dist(), 1);
|
|
2285
|
+
import fs4 from "fs";
|
|
2286
|
+
import path6 from "path";
|
|
2636
2287
|
function indexAndEmbed(relativePath, noteId, embeddingText, metadata, deps) {
|
|
2637
2288
|
indexNote(deps.index, deps.vaultDir, relativePath);
|
|
2638
2289
|
if (deps.vectorIndex && embeddingText) {
|
|
@@ -2685,28 +2336,28 @@ ${candidate.content}`,
|
|
|
2685
2336
|
}
|
|
2686
2337
|
}
|
|
2687
2338
|
function migrateSporeFiles(vaultDir) {
|
|
2688
|
-
const sporesDir =
|
|
2689
|
-
if (!
|
|
2339
|
+
const sporesDir = path6.join(vaultDir, "spores");
|
|
2340
|
+
if (!fs4.existsSync(sporesDir)) return 0;
|
|
2690
2341
|
let moved = 0;
|
|
2691
|
-
const entries =
|
|
2342
|
+
const entries = fs4.readdirSync(sporesDir);
|
|
2692
2343
|
for (const entry of entries) {
|
|
2693
|
-
const fullPath =
|
|
2344
|
+
const fullPath = path6.join(sporesDir, entry);
|
|
2694
2345
|
if (!entry.endsWith(".md")) continue;
|
|
2695
|
-
if (
|
|
2346
|
+
if (fs4.statSync(fullPath).isDirectory()) continue;
|
|
2696
2347
|
try {
|
|
2697
|
-
const content =
|
|
2348
|
+
const content = fs4.readFileSync(fullPath, "utf-8");
|
|
2698
2349
|
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
2699
2350
|
if (!fmMatch) continue;
|
|
2700
|
-
const parsed =
|
|
2351
|
+
const parsed = import_yaml.default.parse(fmMatch[1]);
|
|
2701
2352
|
const obsType = parsed.observation_type;
|
|
2702
2353
|
if (!obsType) continue;
|
|
2703
2354
|
const normalizedType = obsType.replace(/_/g, "-");
|
|
2704
|
-
const targetDir =
|
|
2705
|
-
|
|
2706
|
-
const targetPath =
|
|
2707
|
-
|
|
2355
|
+
const targetDir = path6.join(sporesDir, normalizedType);
|
|
2356
|
+
fs4.mkdirSync(targetDir, { recursive: true });
|
|
2357
|
+
const targetPath = path6.join(targetDir, entry);
|
|
2358
|
+
fs4.renameSync(fullPath, targetPath);
|
|
2708
2359
|
const now = /* @__PURE__ */ new Date();
|
|
2709
|
-
|
|
2360
|
+
fs4.utimesSync(targetPath, now, now);
|
|
2710
2361
|
moved++;
|
|
2711
2362
|
} catch {
|
|
2712
2363
|
}
|
|
@@ -2719,9 +2370,9 @@ async function main() {
|
|
|
2719
2370
|
process.stderr.write("Usage: mycod --vault <path>\n");
|
|
2720
2371
|
process.exit(1);
|
|
2721
2372
|
}
|
|
2722
|
-
const vaultDir =
|
|
2373
|
+
const vaultDir = path6.resolve(vaultArg);
|
|
2723
2374
|
const config = loadConfig(vaultDir);
|
|
2724
|
-
const logger = new DaemonLogger(
|
|
2375
|
+
const logger = new DaemonLogger(path6.join(vaultDir, "logs"), {
|
|
2725
2376
|
level: config.daemon.log_level,
|
|
2726
2377
|
maxSize: config.daemon.max_log_size
|
|
2727
2378
|
});
|
|
@@ -2744,14 +2395,14 @@ async function main() {
|
|
|
2744
2395
|
let vectorIndex = null;
|
|
2745
2396
|
try {
|
|
2746
2397
|
const testEmbed = await embeddingProvider.embed("test");
|
|
2747
|
-
vectorIndex = new VectorIndex(
|
|
2398
|
+
vectorIndex = new VectorIndex(path6.join(vaultDir, "vectors.db"), testEmbed.dimensions);
|
|
2748
2399
|
logger.info("embeddings", "Vector index initialized", { dimensions: testEmbed.dimensions });
|
|
2749
2400
|
} catch (error) {
|
|
2750
2401
|
logger.warn("embeddings", "Vector index unavailable", { error: error.message });
|
|
2751
2402
|
}
|
|
2752
2403
|
const processor = new BufferProcessor(llmProvider, config.intelligence.llm.context_window, config.capture);
|
|
2753
2404
|
const vault = new VaultWriter(vaultDir);
|
|
2754
|
-
const index = new MycoIndex(
|
|
2405
|
+
const index = new MycoIndex(path6.join(vaultDir, "index.db"));
|
|
2755
2406
|
const lineageGraph = new LineageGraph(vaultDir);
|
|
2756
2407
|
const transcriptMiner = new TranscriptMiner({
|
|
2757
2408
|
additionalAdapters: config.capture.transcript_paths.map(
|
|
@@ -2760,17 +2411,17 @@ async function main() {
|
|
|
2760
2411
|
});
|
|
2761
2412
|
let activeStopProcessing = null;
|
|
2762
2413
|
const indexDeps = { index, vaultDir, vectorIndex, embeddingProvider, logger };
|
|
2763
|
-
const bufferDir =
|
|
2414
|
+
const bufferDir = path6.join(vaultDir, "buffer");
|
|
2764
2415
|
const sessionBuffers = /* @__PURE__ */ new Map();
|
|
2765
2416
|
const sessionFilePaths = /* @__PURE__ */ new Map();
|
|
2766
2417
|
const capturedArtifactPaths = /* @__PURE__ */ new Map();
|
|
2767
|
-
if (
|
|
2418
|
+
if (fs4.existsSync(bufferDir)) {
|
|
2768
2419
|
const cutoff = Date.now() - STALE_BUFFER_MAX_AGE_MS;
|
|
2769
|
-
for (const file of
|
|
2770
|
-
const filePath =
|
|
2771
|
-
const stat4 =
|
|
2420
|
+
for (const file of fs4.readdirSync(bufferDir)) {
|
|
2421
|
+
const filePath = path6.join(bufferDir, file);
|
|
2422
|
+
const stat4 = fs4.statSync(filePath);
|
|
2772
2423
|
if (stat4.mtimeMs < cutoff) {
|
|
2773
|
-
|
|
2424
|
+
fs4.unlinkSync(filePath);
|
|
2774
2425
|
logger.debug("daemon", "Cleaned stale buffer", { file });
|
|
2775
2426
|
}
|
|
2776
2427
|
}
|
|
@@ -2807,10 +2458,10 @@ async function main() {
|
|
|
2807
2458
|
logger.info("watcher", "Plan detected", { source: event.source, file: event.filePath });
|
|
2808
2459
|
if (event.filePath) {
|
|
2809
2460
|
try {
|
|
2810
|
-
const content =
|
|
2811
|
-
const relativePath =
|
|
2812
|
-
const title = content.match(/^#\s+(.+)$/m)?.[1] ??
|
|
2813
|
-
const planId = `plan-${
|
|
2461
|
+
const content = fs4.readFileSync(event.filePath, "utf-8");
|
|
2462
|
+
const relativePath = path6.relative(vaultDir, event.filePath);
|
|
2463
|
+
const title = content.match(/^#\s+(.+)$/m)?.[1] ?? path6.basename(event.filePath);
|
|
2464
|
+
const planId = `plan-${path6.basename(event.filePath, ".md")}`;
|
|
2814
2465
|
indexAndEmbed(
|
|
2815
2466
|
relativePath,
|
|
2816
2467
|
planId,
|
|
@@ -2858,6 +2509,7 @@ ${content}`,
|
|
|
2858
2509
|
}
|
|
2859
2510
|
}).catch((err) => {
|
|
2860
2511
|
logger.warn("digest", "Initial digest cycle failed", { error: err.message });
|
|
2512
|
+
metabolism.onEmptyCycle();
|
|
2861
2513
|
});
|
|
2862
2514
|
metabolism.start(async () => {
|
|
2863
2515
|
try {
|
|
@@ -2906,7 +2558,7 @@ ${content}`,
|
|
|
2906
2558
|
}
|
|
2907
2559
|
const captured = capturedArtifactPaths.get(sessionId);
|
|
2908
2560
|
for (const c of candidates) {
|
|
2909
|
-
const absPath =
|
|
2561
|
+
const absPath = path6.resolve(process.cwd(), c.path);
|
|
2910
2562
|
captured.add(absPath);
|
|
2911
2563
|
}
|
|
2912
2564
|
}).catch((err) => logger.warn("processor", "Incremental artifact capture failed", {
|
|
@@ -2946,14 +2598,14 @@ ${content}`,
|
|
|
2946
2598
|
registry.unregister(session_id);
|
|
2947
2599
|
try {
|
|
2948
2600
|
const cutoff = Date.now() - STALE_BUFFER_MAX_AGE_MS;
|
|
2949
|
-
for (const file of
|
|
2601
|
+
for (const file of fs4.readdirSync(bufferDir)) {
|
|
2950
2602
|
if (!file.endsWith(".jsonl")) continue;
|
|
2951
2603
|
const bufferSessionId = file.replace(".jsonl", "");
|
|
2952
2604
|
if (bufferSessionId === session_id) continue;
|
|
2953
|
-
const filePath =
|
|
2954
|
-
const stat4 =
|
|
2605
|
+
const filePath = path6.join(bufferDir, file);
|
|
2606
|
+
const stat4 = fs4.statSync(filePath);
|
|
2955
2607
|
if (stat4.mtimeMs < cutoff) {
|
|
2956
|
-
|
|
2608
|
+
fs4.unlinkSync(filePath);
|
|
2957
2609
|
logger.debug("daemon", "Cleaned stale buffer", { file });
|
|
2958
2610
|
}
|
|
2959
2611
|
}
|
|
@@ -3048,15 +2700,15 @@ ${content}`,
|
|
|
3048
2700
|
}
|
|
3049
2701
|
const ended = (/* @__PURE__ */ new Date()).toISOString();
|
|
3050
2702
|
let started = allTurns.length > 0 && allTurns[0].timestamp ? allTurns[0].timestamp : ended;
|
|
3051
|
-
const sessionsDir =
|
|
2703
|
+
const sessionsDir = path6.join(vaultDir, "sessions");
|
|
3052
2704
|
const sessionFileName = `${sessionNoteId(sessionId)}.md`;
|
|
3053
2705
|
let existingContent;
|
|
3054
2706
|
const duplicatePaths = [];
|
|
3055
2707
|
try {
|
|
3056
|
-
for (const dateDir of
|
|
3057
|
-
const candidate =
|
|
2708
|
+
for (const dateDir of fs4.readdirSync(sessionsDir)) {
|
|
2709
|
+
const candidate = path6.join(sessionsDir, dateDir, sessionFileName);
|
|
3058
2710
|
try {
|
|
3059
|
-
const content =
|
|
2711
|
+
const content = fs4.readFileSync(candidate, "utf-8");
|
|
3060
2712
|
if (!existingContent || content.length > existingContent.length) {
|
|
3061
2713
|
existingContent = content;
|
|
3062
2714
|
}
|
|
@@ -3068,8 +2720,11 @@ ${content}`,
|
|
|
3068
2720
|
}
|
|
3069
2721
|
let existingTurnCount = 0;
|
|
3070
2722
|
if (existingContent) {
|
|
3071
|
-
const
|
|
3072
|
-
if (
|
|
2723
|
+
const fmMatch = existingContent.match(/^---\n([\s\S]*?)\n---/);
|
|
2724
|
+
if (fmMatch) {
|
|
2725
|
+
const parsed = import_yaml.default.parse(fmMatch[1]);
|
|
2726
|
+
if (typeof parsed.started === "string") started = parsed.started;
|
|
2727
|
+
}
|
|
3073
2728
|
const turnMatches = existingContent.match(/^### Turn \d+/gm);
|
|
3074
2729
|
existingTurnCount = turnMatches?.length ?? 0;
|
|
3075
2730
|
}
|
|
@@ -3116,20 +2771,20 @@ ${conversationText}`;
|
|
|
3116
2771
|
}
|
|
3117
2772
|
const date = started.slice(0, 10);
|
|
3118
2773
|
const relativePath = sessionRelativePath(sessionId, date);
|
|
3119
|
-
const targetFullPath =
|
|
2774
|
+
const targetFullPath = path6.join(vaultDir, relativePath);
|
|
3120
2775
|
for (const dup of duplicatePaths) {
|
|
3121
2776
|
if (dup !== targetFullPath) {
|
|
3122
2777
|
try {
|
|
3123
|
-
|
|
2778
|
+
fs4.unlinkSync(dup);
|
|
3124
2779
|
logger.debug("lifecycle", "Removed duplicate session file", { path: dup });
|
|
3125
2780
|
} catch {
|
|
3126
2781
|
}
|
|
3127
2782
|
}
|
|
3128
2783
|
}
|
|
3129
|
-
const attachmentsDir =
|
|
2784
|
+
const attachmentsDir = path6.join(vaultDir, "attachments");
|
|
3130
2785
|
const hasImages = allTurns.some((t) => t.images?.length);
|
|
3131
2786
|
if (hasImages) {
|
|
3132
|
-
|
|
2787
|
+
fs4.mkdirSync(attachmentsDir, { recursive: true });
|
|
3133
2788
|
}
|
|
3134
2789
|
const turnImageNames = /* @__PURE__ */ new Map();
|
|
3135
2790
|
for (let i = 0; i < allTurns.length; i++) {
|
|
@@ -3140,9 +2795,9 @@ ${conversationText}`;
|
|
|
3140
2795
|
const img = turn.images[j];
|
|
3141
2796
|
const ext = extensionForMimeType(img.mediaType);
|
|
3142
2797
|
const filename = `${bareSessionId(sessionId)}-t${i + 1}-${j + 1}.${ext}`;
|
|
3143
|
-
const filePath =
|
|
3144
|
-
if (!
|
|
3145
|
-
|
|
2798
|
+
const filePath = path6.join(attachmentsDir, filename);
|
|
2799
|
+
if (!fs4.existsSync(filePath)) {
|
|
2800
|
+
fs4.writeFileSync(filePath, Buffer.from(img.data, "base64"));
|
|
3146
2801
|
logger.debug("processor", "Image saved", { filename, turn: i + 1 });
|
|
3147
2802
|
}
|
|
3148
2803
|
names.push(filename);
|
|
@@ -3208,7 +2863,7 @@ ${conversationText}`;
|
|
|
3208
2863
|
if (!note) return { id: candidate.id, score: 0 };
|
|
3209
2864
|
try {
|
|
3210
2865
|
const prompt = buildSimilarityPrompt(narrative, note.content.slice(0, CANDIDATE_CONTENT_PREVIEW));
|
|
3211
|
-
const response = await llmProvider.summarize(prompt, { maxTokens: LINEAGE_SIMILARITY_MAX_TOKENS });
|
|
2866
|
+
const response = await llmProvider.summarize(prompt, { maxTokens: LINEAGE_SIMILARITY_MAX_TOKENS, reasoning: LLM_REASONING_MODE });
|
|
3212
2867
|
const score = extractNumber(response.text);
|
|
3213
2868
|
return { id: candidate.id, score: isNaN(score) ? 0 : score };
|
|
3214
2869
|
} catch {
|
|
@@ -3376,4 +3031,4 @@ export {
|
|
|
3376
3031
|
chokidar/index.js:
|
|
3377
3032
|
(*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
|
|
3378
3033
|
*/
|
|
3379
|
-
//# sourceMappingURL=main-
|
|
3034
|
+
//# sourceMappingURL=main-OGXH6XWO.js.map
|