homegraph 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +305 -305
- package/dist/bin/command-supervision.d.ts.map +1 -1
- package/dist/bin/command-supervision.js +7 -4
- package/dist/bin/command-supervision.js.map +1 -1
- package/dist/bin/homegraph.js +9 -9
- package/dist/db/index.js +36 -36
- package/dist/db/migrations.js +37 -37
- package/dist/db/queries.js +156 -156
- package/dist/db/schema.sql +203 -203
- package/dist/directory.js +5 -5
- package/dist/extraction/languages/arkts-viewtree.d.ts +2 -4
- package/dist/extraction/languages/arkts-viewtree.d.ts.map +1 -1
- package/dist/extraction/languages/arkts-viewtree.js +6 -21
- package/dist/extraction/languages/arkts-viewtree.js.map +1 -1
- package/dist/extraction/languages/arkts.d.ts +16 -6
- package/dist/extraction/languages/arkts.d.ts.map +1 -1
- package/dist/extraction/languages/arkts.js +174 -21
- package/dist/extraction/languages/arkts.js.map +1 -1
- package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/dist/installer/instructions-template.js +9 -9
- package/dist/mcp/liveness-watchdog.d.ts +18 -0
- package/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/dist/mcp/liveness-watchdog.js +185 -73
- package/dist/mcp/liveness-watchdog.js.map +1 -1
- package/dist/mcp/server-instructions.js +47 -47
- package/dist/reasoning/reasoner.js +32 -32
- package/dist/spec/db/commit-node.js +4 -4
- package/dist/spec/db/fragment-node.js +10 -10
- package/dist/spec/db/fts.js +8 -8
- package/dist/spec/db/relations.js +88 -88
- package/dist/spec/db/schema.js +6 -6
- package/dist/spec/db/schema.sql +121 -121
- package/dist/spec/db/spec-node.js +4 -4
- package/dist/spec/llm/prompts.js +53 -53
- package/dist/spec/utils.d.ts +16 -4
- package/dist/spec/utils.d.ts.map +1 -1
- package/dist/spec/utils.js +58 -6
- package/dist/spec/utils.js.map +1 -1
- package/package.json +62 -62
- package/scripts/_tmp-cfwk-resolve.log +0 -0
- package/scripts/_tmp-cfwk-sig.log +0 -0
- package/scripts/_tmp-cfwk-vt.log +0 -0
- package/scripts/add-lang/bench.sh +60 -60
- package/scripts/add-lang/check-grammar.mjs +75 -75
- package/scripts/add-lang/dump-ast.mjs +103 -103
- package/scripts/add-lang/verify-extraction.mjs +70 -70
- package/scripts/agent-eval/ab-adoption.sh +91 -91
- package/scripts/agent-eval/ab-hook.sh +86 -86
- package/scripts/agent-eval/ab-impl.sh +78 -78
- package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -102
- package/scripts/agent-eval/ab-sufficiency.sh +78 -78
- package/scripts/agent-eval/arms-F.sh +21 -21
- package/scripts/agent-eval/arms-matrix.sh +37 -37
- package/scripts/agent-eval/audit.sh +68 -68
- package/scripts/agent-eval/bench-readme.sh +28 -28
- package/scripts/agent-eval/bench-why-repo.sh +22 -22
- package/scripts/agent-eval/block-read-hook.sh +19 -19
- package/scripts/agent-eval/hook-settings.json +15 -15
- package/scripts/agent-eval/itrun.sh +120 -120
- package/scripts/agent-eval/offload-eval-3arm.sh +72 -72
- package/scripts/agent-eval/offload-eval-cost.mjs +133 -133
- package/scripts/agent-eval/offload-eval-effort.mjs +108 -108
- package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -25
- package/scripts/agent-eval/offload-eval-frontload.sh +47 -47
- package/scripts/agent-eval/offload-eval-ground-truth.json +18 -18
- package/scripts/agent-eval/offload-eval-hook.mjs +84 -84
- package/scripts/agent-eval/offload-eval-judge.mjs +103 -103
- package/scripts/agent-eval/offload-eval-matrix.sh +20 -20
- package/scripts/agent-eval/offload-eval-metrics.mjs +94 -94
- package/scripts/agent-eval/offload-eval-refs1.sh +50 -50
- package/scripts/agent-eval/offload-eval-setup.sh +24 -24
- package/scripts/agent-eval/offload-eval-styles.sh +71 -71
- package/scripts/agent-eval/offload-eval-summarize.mjs +68 -68
- package/scripts/agent-eval/offload-eval.md +76 -76
- package/scripts/agent-eval/parse-arms.mjs +116 -116
- package/scripts/agent-eval/parse-bench-readme.mjs +84 -84
- package/scripts/agent-eval/parse-run.mjs +45 -45
- package/scripts/agent-eval/parse-session.mjs +93 -93
- package/scripts/agent-eval/probe-context.mjs +21 -21
- package/scripts/agent-eval/probe-explore.mjs +40 -40
- package/scripts/agent-eval/probe-node.mjs +20 -20
- package/scripts/agent-eval/probe-sweep.mjs +119 -119
- package/scripts/agent-eval/probe-trace.mjs +20 -20
- package/scripts/agent-eval/redirect-read-hook.sh +38 -38
- package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -119
- package/scripts/agent-eval/repro-daemon-clients.mjs +125 -125
- package/scripts/agent-eval/run-agent.sh +34 -34
- package/scripts/agent-eval/run-all.sh +75 -75
- package/scripts/agent-eval/run-arms.sh +56 -56
- package/scripts/agent-eval/seq-matrix.mjs +137 -137
- package/scripts/bench-arkts-init-rss.log +0 -0
- package/scripts/build-bundle.sh +123 -123
- package/scripts/exp_boundary_eval/README.md +247 -247
- package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/deveco_arm.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_all.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_all.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/setup.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/setup.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/win_mcp_launcher.cpython-38.pyc +0 -0
- package/scripts/exp_boundary_eval/_test_mcp_chain.py +78 -78
- package/scripts/exp_boundary_eval/_test_stdin.py +8 -8
- package/scripts/exp_boundary_eval/_utils.py +1116 -1116
- package/scripts/exp_boundary_eval/analyze.py +1313 -1313
- package/scripts/exp_boundary_eval/deveco_arm.py +519 -519
- package/scripts/exp_boundary_eval/run_all.py +378 -378
- package/scripts/exp_boundary_eval/run_one.py +165 -165
- package/scripts/exp_boundary_eval/run_session.py +158 -158
- package/scripts/exp_boundary_eval/setup.py +120 -120
- package/scripts/exp_boundary_eval/win_mcp_launcher.py +73 -73
- package/scripts/exp_boundary_eval/win_mcp_stdio_wrap.js +36 -36
- package/scripts/exp_boundary_eval/win_node_launcher.py +24 -24
- package/scripts/extract-release-notes.mjs +130 -130
- package/scripts/local-install.sh +41 -41
- package/scripts/npm-sdk.js +75 -75
- package/scripts/npm-shim.js +275 -275
- package/scripts/ohos-sdk-publish.mjs +133 -133
- package/scripts/pack-npm.sh +119 -119
- package/scripts/prepare-release.mjs +270 -270
- package/scripts/probe-arkts-mem-why-run.log +0 -0
- package/scripts/probe-banner-livecard-ir.log +0 -0
- package/scripts/probe-cfwk-ast.stderr.log +0 -0
- package/scripts/probe-cfwk-ast.stdout.log +0 -0
- package/scripts/probe-cfwk-attr-shape.log +0 -0
- package/scripts/probe-cfwk-cfgdump.stderr.log +0 -0
- package/scripts/probe-cfwk-cfgdump.stdout.log +0 -0
- package/scripts/probe-cfwk-cvc.stderr.log +0 -0
- package/scripts/probe-cfwk-cvc.stdout.log +0 -0
- package/scripts/probe-cfwk-diag2.log +0 -0
- package/scripts/probe-cfwk-diag3.log +0 -0
- package/scripts/probe-cfwk-fedbg.stderr.log +0 -0
- package/scripts/probe-cfwk-fedbg.stdout.log +0 -0
- package/scripts/probe-cfwk-fileresult.log +0 -0
- package/scripts/probe-cfwk-fix.stderr.log +0 -0
- package/scripts/probe-cfwk-fix.stdout.log +0 -0
- package/scripts/probe-cfwk-fix2.stderr.log +0 -0
- package/scripts/probe-cfwk-fix2.stdout.log +0 -0
- package/scripts/probe-cfwk-fix3.stderr.log +0 -0
- package/scripts/probe-cfwk-fix3.stdout.log +0 -0
- package/scripts/probe-cfwk-foreach.log +0 -0
- package/scripts/probe-cfwk-getmethod-throw.log +0 -0
- package/scripts/probe-cfwk-hg-extract.log +0 -0
- package/scripts/probe-cfwk-pr1003-noprior.stderr.log +0 -0
- package/scripts/probe-cfwk-pr1003-noprior.stdout.log +0 -0
- package/scripts/probe-cfwk-pr1003.stderr.log +0 -0
- package/scripts/probe-cfwk-pr1003.stdout.log +0 -0
- package/scripts/probe-cfwk-preroot-noprior.stderr.log +0 -0
- package/scripts/probe-cfwk-preroot-noprior.stdout.log +0 -0
- package/scripts/probe-cfwk-preroot-prior.stderr.log +0 -0
- package/scripts/probe-cfwk-preroot-prior.stdout.log +0 -0
- package/scripts/probe-cfwk-preroot-skipstate.stderr.log +0 -0
- package/scripts/probe-cfwk-preroot-skipstate.stdout.log +0 -0
- package/scripts/probe-cfwk-resolve-sim.log +0 -0
- package/scripts/probe-cfwk-tree-shape.log +0 -0
- package/scripts/probe-cfwk-walk-abort.log +0 -0
- package/scripts/probe-cfwk.log +0 -0
- package/scripts/probe-force-index.log +0 -0
- package/scripts/probe-no-force-index.log +0 -0
- package/scripts/probe-samefile-ir.stderr.log +0 -0
- package/scripts/probe-samefile-ir.stdout.log +224 -0
- package/scripts/probe-sdk-vs-project.log +0 -0
- package/scripts/probe-viewtree-downgrade.log +0 -0
- package/dist/arkts/ohos-api-index.d.ts +0 -15
- package/dist/arkts/ohos-api-index.d.ts.map +0 -1
- package/dist/arkts/ohos-api-index.js +0 -190
- package/dist/arkts/ohos-api-index.js.map +0 -1
- package/dist/arkts/ohos-sdk-input.d.ts +0 -36
- package/dist/arkts/ohos-sdk-input.d.ts.map +0 -1
- package/dist/arkts/ohos-sdk-input.js +0 -214
- package/dist/arkts/ohos-sdk-input.js.map +0 -1
- package/dist/extraction/languages/arkts-state-decorators.d.ts +0 -13
- package/dist/extraction/languages/arkts-state-decorators.d.ts.map +0 -1
- package/dist/extraction/languages/arkts-state-decorators.js +0 -26
- package/dist/extraction/languages/arkts-state-decorators.js.map +0 -1
- package/dist/extraction/languages/ohos-api-consumer.d.ts +0 -34
- package/dist/extraction/languages/ohos-api-consumer.d.ts.map +0 -1
- package/dist/extraction/languages/ohos-api-consumer.js +0 -283
- package/dist/extraction/languages/ohos-api-consumer.js.map +0 -1
- package/dist/spec/build/git-scanner.d.ts +0 -93
- package/dist/spec/build/git-scanner.d.ts.map +0 -1
- package/dist/spec/build/git-scanner.js +0 -254
- package/dist/spec/build/git-scanner.js.map +0 -1
- package/dist/spec/git-utils.d.ts +0 -8
- package/dist/spec/git-utils.d.ts.map +0 -1
- package/dist/spec/git-utils.js +0 -14
- package/dist/spec/git-utils.js.map +0 -1
- package/dist/spec/mine/clusterer.d.ts +0 -63
- package/dist/spec/mine/clusterer.d.ts.map +0 -1
- package/dist/spec/mine/clusterer.js +0 -904
- package/dist/spec/mine/clusterer.js.map +0 -1
- package/dist/spec/mine/progress-handler.d.ts +0 -22
- package/dist/spec/mine/progress-handler.d.ts.map +0 -1
- package/dist/spec/mine/progress-handler.js +0 -108
- package/dist/spec/mine/progress-handler.js.map +0 -1
- package/dist/spec/mine/progress.d.ts +0 -23
- package/dist/spec/mine/progress.d.ts.map +0 -1
- package/dist/spec/mine/progress.js +0 -12
- package/dist/spec/mine/progress.js.map +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -40,14 +40,14 @@ exports.HOMEGRAPH_SECTION_END = '<!-- HOMEGRAPH_END -->';
|
|
|
40
40
|
* indexed" claim would send subagents into failing homegraph calls (the
|
|
41
41
|
* noise the unindexed-session policy exists to prevent).
|
|
42
42
|
*/
|
|
43
|
-
exports.HOMEGRAPH_INSTRUCTIONS_BLOCK = `${exports.HOMEGRAPH_SECTION_START}
|
|
44
|
-
## HomeGraph
|
|
45
|
-
|
|
46
|
-
In repositories indexed by HomeGraph (a \`.homegraph/\` directory exists at the repo root), reach for it BEFORE grep/find or reading files when you need to understand or locate code:
|
|
47
|
-
|
|
48
|
-
- **MCP tool** (when available): \`homegraph_explore\` answers most code questions in one call — the relevant symbols' verbatim source plus the call paths between them, including dynamic-dispatch hops grep can't follow. Name a file or symbol in the query to read its current line-numbered source. If it's listed but deferred, load it by name via tool search.
|
|
49
|
-
- **Shell** (always works): \`homegraph explore "<symbol names or question>"\` prints the same output.
|
|
50
|
-
|
|
51
|
-
If there is no \`.homegraph/\` directory, skip HomeGraph entirely — indexing is the user's decision.
|
|
43
|
+
exports.HOMEGRAPH_INSTRUCTIONS_BLOCK = `${exports.HOMEGRAPH_SECTION_START}
|
|
44
|
+
## HomeGraph
|
|
45
|
+
|
|
46
|
+
In repositories indexed by HomeGraph (a \`.homegraph/\` directory exists at the repo root), reach for it BEFORE grep/find or reading files when you need to understand or locate code:
|
|
47
|
+
|
|
48
|
+
- **MCP tool** (when available): \`homegraph_explore\` answers most code questions in one call — the relevant symbols' verbatim source plus the call paths between them, including dynamic-dispatch hops grep can't follow. Name a file or symbol in the query to read its current line-numbered source. If it's listed but deferred, load it by name via tool search.
|
|
49
|
+
- **Shell** (always works): \`homegraph explore "<symbol names or question>"\` prints the same output.
|
|
50
|
+
|
|
51
|
+
If there is no \`.homegraph/\` directory, skip HomeGraph entirely — indexing is the user's decision.
|
|
52
52
|
${exports.HOMEGRAPH_SECTION_END}`;
|
|
53
53
|
//# sourceMappingURL=instructions-template.js.map
|
|
@@ -30,6 +30,24 @@ export interface WatchdogOptions {
|
|
|
30
30
|
* handle to stop it, or `null` when disabled or when the child can't be spawned
|
|
31
31
|
* (degraded, never throws — a missing watchdog must never keep a process from
|
|
32
32
|
* starting).
|
|
33
|
+
*
|
|
34
|
+
* The returned handle is process-wide and stable across
|
|
35
|
+
* {@link suspendLivenessWatchdog} re-arms — `stop()` always tears down the
|
|
36
|
+
* current generation.
|
|
33
37
|
*/
|
|
34
38
|
export declare function installMainThreadWatchdog(options?: WatchdogOptions): WatchdogHandle | null;
|
|
39
|
+
/**
|
|
40
|
+
* Suspend the armed liveness watchdog for an opaque synchronous span that
|
|
41
|
+
* cannot cooperatively yield (ArkAnalyzer Scene builds). Returns an idempotent
|
|
42
|
+
* resume function. Nested calls refcount; a `stop()` while suspended cancels
|
|
43
|
+
* the pending re-arm.
|
|
44
|
+
*
|
|
45
|
+
* No-op when nothing is armed (tests, `HOMEGRAPH_NO_WATCHDOG`, library embeds).
|
|
46
|
+
*/
|
|
47
|
+
export declare function suspendLivenessWatchdog(): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Run `fn` with the liveness watchdog suspended, then resume. Use for native
|
|
50
|
+
* spans with no JS yield points; prefer cooperative yielding for JS-owned loops.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runWithoutLivenessWatchdog<T>(fn: () => T): T;
|
|
35
53
|
//# sourceMappingURL=liveness-watchdog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveness-watchdog.d.ts","sourceRoot":"","sources":["../../src/mcp/liveness-watchdog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"liveness-watchdog.d.ts","sourceRoot":"","sources":["../../src/mcp/liveness-watchdog.ts"],"names":[],"mappings":"AAiEA,uGAAuG;AACvG,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAQ1C,qFAAqF;AACrF,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,QAAQ,GAAE,MAAoC,GAC7C,MAAM,CAIR;AAED,qFAAqF;AACrF,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE/D;AASD,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,IAAI,IAAI,CAAC;CACd;AA8DD,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAkHD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAE,eAAoB,GAAG,cAAc,GAAG,IAAI,CAY9F;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,IAAI,CAqBpD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAO5D"}
|
|
@@ -37,6 +37,8 @@ exports.PROGRESS_CAP_MULTIPLIER = exports.DEFAULT_WATCHDOG_TIMEOUT_MS = void 0;
|
|
|
37
37
|
exports.parseWatchdogTimeoutMs = parseWatchdogTimeoutMs;
|
|
38
38
|
exports.deriveCheckIntervalMs = deriveCheckIntervalMs;
|
|
39
39
|
exports.installMainThreadWatchdog = installMainThreadWatchdog;
|
|
40
|
+
exports.suspendLivenessWatchdog = suspendLivenessWatchdog;
|
|
41
|
+
exports.runWithoutLivenessWatchdog = runWithoutLivenessWatchdog;
|
|
40
42
|
/**
|
|
41
43
|
* Main-thread liveness watchdog — belt-and-suspenders for #850.
|
|
42
44
|
*
|
|
@@ -88,6 +90,15 @@ exports.installMainThreadWatchdog = installMainThreadWatchdog;
|
|
|
88
90
|
* coinciding with unrelated file activity — or I/O hung beyond all reason —
|
|
89
91
|
* still dies. A true wedge with no disk progress dies at the base timeout,
|
|
90
92
|
* exactly as before.
|
|
93
|
+
*
|
|
94
|
+
* **Opaque native spans (`suspendLivenessWatchdog` / `runWithoutLivenessWatchdog`).**
|
|
95
|
+
* ArkAnalyzer Scene builds (`analyseByModule` / full Scene) run synchronous
|
|
96
|
+
* native work on this thread with no JS yield points — a single module's BODIES
|
|
97
|
+
* load can exceed the 60s window while the process is healthy. Cooperative
|
|
98
|
+
* yielding can't help (the stall is between callbacks, inside native code), and
|
|
99
|
+
* disk-progress deferral's hard cap is too short for multi-module Harmony
|
|
100
|
+
* indexes. Those spans suspend the watchdog for the duration and re-arm after;
|
|
101
|
+
* prefer yielding for any JS-owned loop.
|
|
91
102
|
*/
|
|
92
103
|
const fs = __importStar(require("fs"));
|
|
93
104
|
const os = __importStar(require("os"));
|
|
@@ -134,67 +145,95 @@ function debug(msg) {
|
|
|
134
145
|
* target pid + timeout from argv; an MSG built once at startup (the child is
|
|
135
146
|
* never wedged, so allocation here is fine).
|
|
136
147
|
*/
|
|
137
|
-
const CHILD_SOURCE = `
|
|
138
|
-
const fs = require('fs');
|
|
139
|
-
const parentPid = Number(process.argv[1]);
|
|
140
|
-
const timeoutMs = Number(process.argv[2]);
|
|
141
|
-
const capMs = Number(process.argv[3]);
|
|
142
|
-
const progressPaths = process.argv.slice(4);
|
|
143
|
-
const secs = Math.round(timeoutMs / 1000);
|
|
144
|
-
function kill(extra) {
|
|
145
|
-
try { fs.writeSync(2, Buffer.from('[HomeGraph] Main thread unresponsive for ~' + secs + 's' + (extra || '') + ' — killing the wedged process so a fresh one can start (#850). Disable with HOMEGRAPH_NO_WATCHDOG=1.\\n')); } catch (e) {}
|
|
146
|
-
try { process.kill(parentPid, 'SIGKILL'); } catch (e) {}
|
|
147
|
-
process.exit(0);
|
|
148
|
-
}
|
|
149
|
-
// Fingerprint of the watched files (size + mtime). A change between checks is
|
|
150
|
-
// forward disk progress — a slow synchronous SQLite statement, not a wedge.
|
|
151
|
-
function snap() {
|
|
152
|
-
let s = '';
|
|
153
|
-
for (const p of progressPaths) {
|
|
154
|
-
try { const st = fs.statSync(p); s += st.size + ':' + st.mtimeMs + ';'; } catch (e) { s += 'x;'; }
|
|
155
|
-
}
|
|
156
|
-
return s;
|
|
157
|
-
}
|
|
158
|
-
let lastSnap = progressPaths.length ? snap() : '';
|
|
159
|
-
let lastSnapAt = Date.now();
|
|
160
|
-
let silentSince = null; // start of the current continuous-silence episode
|
|
161
|
-
function onTimeout() {
|
|
162
|
-
if (!progressPaths.length) return kill('');
|
|
163
|
-
const now = Date.now();
|
|
164
|
-
if (silentSince === null) silentSince = now - timeoutMs; // silence began ~one timeout ago
|
|
165
|
-
const cur = snap();
|
|
166
|
-
if (cur !== lastSnap && now - silentSince < capMs) {
|
|
167
|
-
// The event loop is blocked but the DB files are advancing: a legitimate
|
|
168
|
-
// long store on slow storage. Defer, re-baseline, keep watching.
|
|
169
|
-
lastSnap = cur;
|
|
170
|
-
timer = setTimeout(onTimeout, timeoutMs);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
kill(cur !== lastSnap ? ' despite ongoing disk activity (hard cap ' + Math.round(capMs / 1000) + 's reached)' : '');
|
|
174
|
-
}
|
|
175
|
-
let timer = setTimeout(onTimeout, timeoutMs);
|
|
176
|
-
process.stdin.on('data', () => {
|
|
177
|
-
silentSince = null;
|
|
178
|
-
// Keep the baseline fresh while healthy (throttled — a stat per second).
|
|
179
|
-
if (progressPaths.length) {
|
|
180
|
-
const t = Date.now();
|
|
181
|
-
if (t - lastSnapAt >= 1000) { lastSnap = snap(); lastSnapAt = t; }
|
|
182
|
-
}
|
|
183
|
-
clearTimeout(timer); timer = setTimeout(onTimeout, timeoutMs);
|
|
184
|
-
});
|
|
185
|
-
process.stdin.on('end', () => process.exit(0)); // parent closed the pipe (exited) -> no orphan
|
|
186
|
-
process.stdin.on('error', () => process.exit(0)); // pipe broke -> parent gone
|
|
187
|
-
process.stdin.resume();
|
|
148
|
+
const CHILD_SOURCE = `
|
|
149
|
+
const fs = require('fs');
|
|
150
|
+
const parentPid = Number(process.argv[1]);
|
|
151
|
+
const timeoutMs = Number(process.argv[2]);
|
|
152
|
+
const capMs = Number(process.argv[3]);
|
|
153
|
+
const progressPaths = process.argv.slice(4);
|
|
154
|
+
const secs = Math.round(timeoutMs / 1000);
|
|
155
|
+
function kill(extra) {
|
|
156
|
+
try { fs.writeSync(2, Buffer.from('[HomeGraph] Main thread unresponsive for ~' + secs + 's' + (extra || '') + ' — killing the wedged process so a fresh one can start (#850). Disable with HOMEGRAPH_NO_WATCHDOG=1.\\n')); } catch (e) {}
|
|
157
|
+
try { process.kill(parentPid, 'SIGKILL'); } catch (e) {}
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
// Fingerprint of the watched files (size + mtime). A change between checks is
|
|
161
|
+
// forward disk progress — a slow synchronous SQLite statement, not a wedge.
|
|
162
|
+
function snap() {
|
|
163
|
+
let s = '';
|
|
164
|
+
for (const p of progressPaths) {
|
|
165
|
+
try { const st = fs.statSync(p); s += st.size + ':' + st.mtimeMs + ';'; } catch (e) { s += 'x;'; }
|
|
166
|
+
}
|
|
167
|
+
return s;
|
|
168
|
+
}
|
|
169
|
+
let lastSnap = progressPaths.length ? snap() : '';
|
|
170
|
+
let lastSnapAt = Date.now();
|
|
171
|
+
let silentSince = null; // start of the current continuous-silence episode
|
|
172
|
+
function onTimeout() {
|
|
173
|
+
if (!progressPaths.length) return kill('');
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
if (silentSince === null) silentSince = now - timeoutMs; // silence began ~one timeout ago
|
|
176
|
+
const cur = snap();
|
|
177
|
+
if (cur !== lastSnap && now - silentSince < capMs) {
|
|
178
|
+
// The event loop is blocked but the DB files are advancing: a legitimate
|
|
179
|
+
// long store on slow storage. Defer, re-baseline, keep watching.
|
|
180
|
+
lastSnap = cur;
|
|
181
|
+
timer = setTimeout(onTimeout, timeoutMs);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
kill(cur !== lastSnap ? ' despite ongoing disk activity (hard cap ' + Math.round(capMs / 1000) + 's reached)' : '');
|
|
185
|
+
}
|
|
186
|
+
let timer = setTimeout(onTimeout, timeoutMs);
|
|
187
|
+
process.stdin.on('data', () => {
|
|
188
|
+
silentSince = null;
|
|
189
|
+
// Keep the baseline fresh while healthy (throttled — a stat per second).
|
|
190
|
+
if (progressPaths.length) {
|
|
191
|
+
const t = Date.now();
|
|
192
|
+
if (t - lastSnapAt >= 1000) { lastSnap = snap(); lastSnapAt = t; }
|
|
193
|
+
}
|
|
194
|
+
clearTimeout(timer); timer = setTimeout(onTimeout, timeoutMs);
|
|
195
|
+
});
|
|
196
|
+
process.stdin.on('end', () => process.exit(0)); // parent closed the pipe (exited) -> no orphan
|
|
197
|
+
process.stdin.on('error', () => process.exit(0)); // pipe broke -> parent gone
|
|
198
|
+
process.stdin.resume();
|
|
188
199
|
`;
|
|
189
200
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* (
|
|
193
|
-
*
|
|
201
|
+
* Process-wide armed watchdog. `install` / `suspend` / `stop` all mutate this
|
|
202
|
+
* so a handle returned before a suspend+re-arm still stops the *current*
|
|
203
|
+
* generation (CLI supervision and the MCP server hold the handle across
|
|
204
|
+
* ArkTS Scene builds that suspend).
|
|
194
205
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
let active = null;
|
|
207
|
+
/** Nested `suspendLivenessWatchdog` depth; disarm only at 0→1, re-arm at 1→0. */
|
|
208
|
+
let suspendDepth = 0;
|
|
209
|
+
/** Options to re-arm with after the outermost resume; cleared by `stop()`. */
|
|
210
|
+
let optionsWhileSuspended = null;
|
|
211
|
+
/** Stable handle: always stops whatever generation is current (or pending re-arm). */
|
|
212
|
+
const SHARED_HANDLE = {
|
|
213
|
+
stop() {
|
|
214
|
+
suspendDepth = 0;
|
|
215
|
+
optionsWhileSuspended = null;
|
|
216
|
+
disarmActive();
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
function copyOptions(options) {
|
|
220
|
+
return {
|
|
221
|
+
progressPaths: options.progressPaths ? [...options.progressPaths] : undefined,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function disarmActive() {
|
|
225
|
+
if (!active)
|
|
226
|
+
return;
|
|
227
|
+
try {
|
|
228
|
+
active.disarm();
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
/* best-effort teardown */
|
|
232
|
+
}
|
|
233
|
+
active = null;
|
|
234
|
+
}
|
|
235
|
+
/** Spawn the watchdog child; returns a disarm fn, or null on spawn failure. */
|
|
236
|
+
function armWatchdog(options) {
|
|
198
237
|
const timeoutMs = parseWatchdogTimeoutMs(process.env.HOMEGRAPH_WATCHDOG_TIMEOUT_MS);
|
|
199
238
|
const checkMs = deriveCheckIntervalMs(timeoutMs);
|
|
200
239
|
const capMs = timeoutMs * exports.PROGRESS_CAP_MULTIPLIER;
|
|
@@ -247,21 +286,94 @@ function installMainThreadWatchdog(options = {}) {
|
|
|
247
286
|
catch { /* ignore */ }
|
|
248
287
|
debug(`armed (child pid ${child.pid ?? '?'}): timeoutMs=${timeoutMs} checkMs=${checkMs} progressPaths=${progressPaths.length}`);
|
|
249
288
|
let stopped = false;
|
|
250
|
-
return {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
catch { /* ignore */ } // belt-and-suspenders
|
|
264
|
-
},
|
|
289
|
+
return () => {
|
|
290
|
+
if (stopped)
|
|
291
|
+
return;
|
|
292
|
+
stopped = true;
|
|
293
|
+
clearInterval(heartbeat);
|
|
294
|
+
try {
|
|
295
|
+
stdin.end();
|
|
296
|
+
}
|
|
297
|
+
catch { /* ignore */ } // EOF -> child exits cleanly
|
|
298
|
+
try {
|
|
299
|
+
child.kill();
|
|
300
|
+
}
|
|
301
|
+
catch { /* ignore */ } // belt-and-suspenders
|
|
265
302
|
};
|
|
266
303
|
}
|
|
304
|
+
function rearmFromOptions(options) {
|
|
305
|
+
const disarm = armWatchdog(options);
|
|
306
|
+
if (!disarm)
|
|
307
|
+
return;
|
|
308
|
+
active = { disarm, options: copyOptions(options) };
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Install the main-thread liveness watchdog for a long-lived process. Returns a
|
|
312
|
+
* handle to stop it, or `null` when disabled or when the child can't be spawned
|
|
313
|
+
* (degraded, never throws — a missing watchdog must never keep a process from
|
|
314
|
+
* starting).
|
|
315
|
+
*
|
|
316
|
+
* The returned handle is process-wide and stable across
|
|
317
|
+
* {@link suspendLivenessWatchdog} re-arms — `stop()` always tears down the
|
|
318
|
+
* current generation.
|
|
319
|
+
*/
|
|
320
|
+
function installMainThreadWatchdog(options = {}) {
|
|
321
|
+
if (isEnvTruthy(process.env.HOMEGRAPH_NO_WATCHDOG))
|
|
322
|
+
return null;
|
|
323
|
+
// Replace any prior generation (including a mid-suspend pending re-arm).
|
|
324
|
+
suspendDepth = 0;
|
|
325
|
+
optionsWhileSuspended = null;
|
|
326
|
+
disarmActive();
|
|
327
|
+
const disarm = armWatchdog(options);
|
|
328
|
+
if (!disarm)
|
|
329
|
+
return null;
|
|
330
|
+
active = { disarm, options: copyOptions(options) };
|
|
331
|
+
return SHARED_HANDLE;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Suspend the armed liveness watchdog for an opaque synchronous span that
|
|
335
|
+
* cannot cooperatively yield (ArkAnalyzer Scene builds). Returns an idempotent
|
|
336
|
+
* resume function. Nested calls refcount; a `stop()` while suspended cancels
|
|
337
|
+
* the pending re-arm.
|
|
338
|
+
*
|
|
339
|
+
* No-op when nothing is armed (tests, `HOMEGRAPH_NO_WATCHDOG`, library embeds).
|
|
340
|
+
*/
|
|
341
|
+
function suspendLivenessWatchdog() {
|
|
342
|
+
suspendDepth++;
|
|
343
|
+
if (suspendDepth === 1 && active) {
|
|
344
|
+
optionsWhileSuspended = active.options;
|
|
345
|
+
disarmActive();
|
|
346
|
+
debug('suspended for opaque sync span');
|
|
347
|
+
}
|
|
348
|
+
let resumed = false;
|
|
349
|
+
return () => {
|
|
350
|
+
if (resumed)
|
|
351
|
+
return;
|
|
352
|
+
resumed = true;
|
|
353
|
+
if (suspendDepth <= 0)
|
|
354
|
+
return;
|
|
355
|
+
suspendDepth--;
|
|
356
|
+
if (suspendDepth > 0)
|
|
357
|
+
return;
|
|
358
|
+
if (optionsWhileSuspended) {
|
|
359
|
+
const opts = optionsWhileSuspended;
|
|
360
|
+
optionsWhileSuspended = null;
|
|
361
|
+
rearmFromOptions(opts);
|
|
362
|
+
debug('resumed after opaque sync span');
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Run `fn` with the liveness watchdog suspended, then resume. Use for native
|
|
368
|
+
* spans with no JS yield points; prefer cooperative yielding for JS-owned loops.
|
|
369
|
+
*/
|
|
370
|
+
function runWithoutLivenessWatchdog(fn) {
|
|
371
|
+
const resume = suspendLivenessWatchdog();
|
|
372
|
+
try {
|
|
373
|
+
return fn();
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
resume();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
267
379
|
//# sourceMappingURL=liveness-watchdog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveness-watchdog.js","sourceRoot":"","sources":["../../src/mcp/liveness-watchdog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"liveness-watchdog.js","sourceRoot":"","sources":["../../src/mcp/liveness-watchdog.ts"],"names":[],"mappings":";;;;;;;;;;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MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;IACzC,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -7,53 +7,53 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = exports.SERVER_INSTRUCTIONS = void 0;
|
|
10
|
-
exports.SERVER_INSTRUCTIONS = `# HomeGraph — when to call
|
|
11
|
-
|
|
12
|
-
HomeGraph is a **local structural index of THIS repo**: symbols + call/import/extends edges + files. Use it only when the answer needs that graph.
|
|
13
|
-
|
|
14
|
-
## Call HomeGraph (closed set)
|
|
15
|
-
|
|
16
|
-
Use \`homegraph_explore\` (primary) when **all** of these hold:
|
|
17
|
-
|
|
18
|
-
1. The evidence lives **in this repository's source** (not an external SDK manual).
|
|
19
|
-
2. You need **structure**: definition location, who calls whom, how A reaches B, multi-file wiring, or in-repo import/usage of a named API/\`@kit\` module.
|
|
20
|
-
3. You can put **concrete names** in \`query\` — symbol, \`Type.member\`, file basename, or \`@kit…\` (skip \`homegraph_search\` when names are already known).
|
|
21
|
-
|
|
22
|
-
Typical fits:
|
|
23
|
-
|
|
24
|
-
- How a **feature in this repo** is wired (mechanism / cross-file / click→handler flow)
|
|
25
|
-
- Callers / callees / blast radius of a **named** symbol
|
|
26
|
-
- What a **named component/method** does (include the name; one explore is enough)
|
|
27
|
-
- In-repo usages of an imported API (not the official feature catalog)
|
|
28
|
-
|
|
29
|
-
**One explore with names** beats search→explore→node→grep→read. Treat returned line-numbered source as already Read. After a full explore — **answer**; do not re-verify with grep/read/node for the same symbols. Busy/partial → retry that **same** explore once.
|
|
30
|
-
|
|
31
|
-
## Do not call HomeGraph otherwise
|
|
32
|
-
|
|
33
|
-
If the question is **outside the set above**, do **not** open any \`homegraph_*\` tool — use Read / Grep / Glob / SDK docs. HomeGraph is not a general Q&A layer; forcing it on the wrong shape costs time and tokens and often lowers quality.
|
|
34
|
-
|
|
35
|
-
## Tool roles
|
|
36
|
-
|
|
37
|
-
| Tool | Role |
|
|
38
|
-
|------|------|
|
|
39
|
-
| **homegraph_explore** | Primary for the closed set above |
|
|
40
|
-
| homegraph_node | One known symbol body (or indexed file) after explore named it |
|
|
41
|
-
| homegraph_callers / callees | Compact edge lists for a named symbol |
|
|
42
|
-
| homegraph_search | Rare — unknown spelling only |
|
|
43
|
-
| homegraph_files | Folder tree only |
|
|
44
|
-
|
|
45
|
-
## Tips
|
|
46
|
-
|
|
47
|
-
- **Deadline / partial** — success-shaped; retry ONE explore with the same names. Do not abandon to grep for those symbols.
|
|
48
|
-
- **Staleness banner** — Read only the listed edited files.
|
|
49
|
-
- **Not indexed** — built-in tools; user runs \`homegraph init\` — you do not.
|
|
10
|
+
exports.SERVER_INSTRUCTIONS = `# HomeGraph — when to call
|
|
11
|
+
|
|
12
|
+
HomeGraph is a **local structural index of THIS repo**: symbols + call/import/extends edges + files. Use it only when the answer needs that graph.
|
|
13
|
+
|
|
14
|
+
## Call HomeGraph (closed set)
|
|
15
|
+
|
|
16
|
+
Use \`homegraph_explore\` (primary) when **all** of these hold:
|
|
17
|
+
|
|
18
|
+
1. The evidence lives **in this repository's source** (not an external SDK manual).
|
|
19
|
+
2. You need **structure**: definition location, who calls whom, how A reaches B, multi-file wiring, or in-repo import/usage of a named API/\`@kit\` module.
|
|
20
|
+
3. You can put **concrete names** in \`query\` — symbol, \`Type.member\`, file basename, or \`@kit…\` (skip \`homegraph_search\` when names are already known).
|
|
21
|
+
|
|
22
|
+
Typical fits:
|
|
23
|
+
|
|
24
|
+
- How a **feature in this repo** is wired (mechanism / cross-file / click→handler flow)
|
|
25
|
+
- Callers / callees / blast radius of a **named** symbol
|
|
26
|
+
- What a **named component/method** does (include the name; one explore is enough)
|
|
27
|
+
- In-repo usages of an imported API (not the official feature catalog)
|
|
28
|
+
|
|
29
|
+
**One explore with names** beats search→explore→node→grep→read. Treat returned line-numbered source as already Read. After a full explore — **answer**; do not re-verify with grep/read/node for the same symbols. Busy/partial → retry that **same** explore once.
|
|
30
|
+
|
|
31
|
+
## Do not call HomeGraph otherwise
|
|
32
|
+
|
|
33
|
+
If the question is **outside the set above**, do **not** open any \`homegraph_*\` tool — use Read / Grep / Glob / SDK docs. HomeGraph is not a general Q&A layer; forcing it on the wrong shape costs time and tokens and often lowers quality.
|
|
34
|
+
|
|
35
|
+
## Tool roles
|
|
36
|
+
|
|
37
|
+
| Tool | Role |
|
|
38
|
+
|------|------|
|
|
39
|
+
| **homegraph_explore** | Primary for the closed set above |
|
|
40
|
+
| homegraph_node | One known symbol body (or indexed file) after explore named it |
|
|
41
|
+
| homegraph_callers / callees | Compact edge lists for a named symbol |
|
|
42
|
+
| homegraph_search | Rare — unknown spelling only |
|
|
43
|
+
| homegraph_files | Folder tree only |
|
|
44
|
+
|
|
45
|
+
## Tips
|
|
46
|
+
|
|
47
|
+
- **Deadline / partial** — success-shaped; retry ONE explore with the same names. Do not abandon to grep for those symbols.
|
|
48
|
+
- **Staleness banner** — Read only the listed edited files.
|
|
49
|
+
- **Not indexed** — built-in tools; user runs \`homegraph init\` — you do not.
|
|
50
50
|
`;
|
|
51
|
-
exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = `# HomeGraph — per-project (pass projectPath)
|
|
52
|
-
|
|
53
|
-
HomeGraph indexes a codebase into a symbol graph. Call it **only** for in-repo structural / flow / usage questions on a project that has \`.homegraph/\`. Pass that project as \`projectPath\`.
|
|
54
|
-
|
|
55
|
-
- Fits the closed set (structure, callers, wiring, named symbol/file) → \`homegraph_explore\`
|
|
56
|
-
- Anything else → Read/Grep/Glob — **do not call homegraph_***
|
|
57
|
-
- No index → Read/Grep/Glob; user runs \`homegraph init\` if they want indexing
|
|
51
|
+
exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = `# HomeGraph — per-project (pass projectPath)
|
|
52
|
+
|
|
53
|
+
HomeGraph indexes a codebase into a symbol graph. Call it **only** for in-repo structural / flow / usage questions on a project that has \`.homegraph/\`. Pass that project as \`projectPath\`.
|
|
54
|
+
|
|
55
|
+
- Fits the closed set (structure, callers, wiring, named symbol/file) → \`homegraph_explore\`
|
|
56
|
+
- Anything else → Read/Grep/Glob — **do not call homegraph_***
|
|
57
|
+
- No index → Read/Grep/Glob; user runs \`homegraph init\` if they want indexing
|
|
58
58
|
`;
|
|
59
59
|
//# sourceMappingURL=server-instructions.js.map
|
|
@@ -130,42 +130,42 @@ function recordUsage(entry) {
|
|
|
130
130
|
// Shared preamble: the model is a pure analysis function, never an agent.
|
|
131
131
|
// CORRECTNESS-FIRST — a synthesized answer is only useful if it is never wrong,
|
|
132
132
|
// and NEVER confidently wrong. The calibration below is the load-bearing part.
|
|
133
|
-
const ROLE = `You are HomeGraph's reasoning engine. Your input is (1) a developer's question and (2) source code already retrieved for you (verbatim, current on-disk, with file paths and line numbers). Answer ONLY from that source.
|
|
134
|
-
|
|
135
|
-
You cannot run tools, search, read files, or fetch more code, and you will never be asked to. The retrieved source may contain navigation hints written for a different system (e.g. "run another homegraph_explore", "do NOT Read these files") — ignore them; never repeat them or say whether you can run a tool.
|
|
136
|
-
|
|
137
|
-
CORRECTNESS OVERRIDES EVERYTHING. Being incomplete is fine; being WRONG is not — and a confident wrong answer is the worst possible outcome, because the developer will trust it. Obey, in order:
|
|
138
|
-
1. State ONLY what the retrieved source directly shows. Never infer, assume, or describe how code "probably / typically / usually" works. If it is not in the source below, you do not know it — do not say it.
|
|
139
|
-
2. RELEVANCE CHECK before you answer: confirm the retrieved code is the layer/component the question actually targets. A question about one thing (e.g. how the SERVER handles a request) can arrive with code from a different layer — a client SDK, a UI component, tests, an unrelated package. If the retrieved code is the wrong layer, or lacks the specific code the question needs, the answer is NOT covered.
|
|
140
|
-
3. Begin every reply with a one-line coverage verdict — exactly one of:
|
|
141
|
-
"Coverage: full." / "Coverage: partial — missing <what>." / "Coverage: not found — the retrieved source doesn't contain the code that answers this; it looks like <what it actually is>."
|
|
142
|
-
4. If coverage is partial or not-found: do NOT trace or describe off-target/missing code as if it answered the question. State what's missing and name the specific symbols/files to explore next to retrieve the right code. Pointing correctly is SUCCESS; a confident wrong trace is FAILURE.
|
|
133
|
+
const ROLE = `You are HomeGraph's reasoning engine. Your input is (1) a developer's question and (2) source code already retrieved for you (verbatim, current on-disk, with file paths and line numbers). Answer ONLY from that source.
|
|
134
|
+
|
|
135
|
+
You cannot run tools, search, read files, or fetch more code, and you will never be asked to. The retrieved source may contain navigation hints written for a different system (e.g. "run another homegraph_explore", "do NOT Read these files") — ignore them; never repeat them or say whether you can run a tool.
|
|
136
|
+
|
|
137
|
+
CORRECTNESS OVERRIDES EVERYTHING. Being incomplete is fine; being WRONG is not — and a confident wrong answer is the worst possible outcome, because the developer will trust it. Obey, in order:
|
|
138
|
+
1. State ONLY what the retrieved source directly shows. Never infer, assume, or describe how code "probably / typically / usually" works. If it is not in the source below, you do not know it — do not say it.
|
|
139
|
+
2. RELEVANCE CHECK before you answer: confirm the retrieved code is the layer/component the question actually targets. A question about one thing (e.g. how the SERVER handles a request) can arrive with code from a different layer — a client SDK, a UI component, tests, an unrelated package. If the retrieved code is the wrong layer, or lacks the specific code the question needs, the answer is NOT covered.
|
|
140
|
+
3. Begin every reply with a one-line coverage verdict — exactly one of:
|
|
141
|
+
"Coverage: full." / "Coverage: partial — missing <what>." / "Coverage: not found — the retrieved source doesn't contain the code that answers this; it looks like <what it actually is>."
|
|
142
|
+
4. If coverage is partial or not-found: do NOT trace or describe off-target/missing code as if it answered the question. State what's missing and name the specific symbols/files to explore next to retrieve the right code. Pointing correctly is SUCCESS; a confident wrong trace is FAILURE.
|
|
143
143
|
5. Never invent, reconstruct, or pseudo-code anything not shown. Back every factual claim with a file:line citation to the provided source.`;
|
|
144
144
|
// 'report' style — mimics the structured report a thorough engineer hands back.
|
|
145
|
-
const SYSTEM_PROMPT_REPORT = `${ROLE}
|
|
146
|
-
|
|
147
|
-
Produce a single self-contained exploration report, formatted exactly like the summary a thorough senior engineer hands back after investigating. Clean Markdown, in this shape:
|
|
148
|
-
- Open with the one-line coverage verdict (above). Then, ONLY if covered, a bold title: "**<Topic> — <Flow / Trace / Overview>**". If coverage is not-found, the verdict + the names to explore next is the entire reply. NO preamble ("Here is", "Now I understand"). Use bold labels for headers, never Markdown ATX headings (\`#\`/\`##\`) — they render oversized in some clients.
|
|
149
|
-
- Body is numbered sections with bold headers: "**1. <step or aspect>**", "**2. <...>**", …
|
|
150
|
-
- Cite every location inline and in bold as **\`path/to/file.ts:line\`** (or a line range), exactly as given in the source. Bold key classes, methods, and symbols.
|
|
151
|
-
- For a flow/path question, include a call-chain diagram in a fenced code block using down-arrows:
|
|
152
|
-
\`\`\`
|
|
153
|
-
funcA() path/to/a.ts:120
|
|
154
|
-
↓
|
|
155
|
-
funcB() path/to/b.ts:44
|
|
156
|
-
\`\`\`
|
|
157
|
-
- Quote only the code lines that carry the logic, in fenced code blocks, keeping their line numbers. Keep snippets tight.
|
|
158
|
-
- Separate major sections with a "---" rule.
|
|
159
|
-
- End with "**Summary**" — the end-to-end chain in one compact block.
|
|
160
|
-
|
|
145
|
+
const SYSTEM_PROMPT_REPORT = `${ROLE}
|
|
146
|
+
|
|
147
|
+
Produce a single self-contained exploration report, formatted exactly like the summary a thorough senior engineer hands back after investigating. Clean Markdown, in this shape:
|
|
148
|
+
- Open with the one-line coverage verdict (above). Then, ONLY if covered, a bold title: "**<Topic> — <Flow / Trace / Overview>**". If coverage is not-found, the verdict + the names to explore next is the entire reply. NO preamble ("Here is", "Now I understand"). Use bold labels for headers, never Markdown ATX headings (\`#\`/\`##\`) — they render oversized in some clients.
|
|
149
|
+
- Body is numbered sections with bold headers: "**1. <step or aspect>**", "**2. <...>**", …
|
|
150
|
+
- Cite every location inline and in bold as **\`path/to/file.ts:line\`** (or a line range), exactly as given in the source. Bold key classes, methods, and symbols.
|
|
151
|
+
- For a flow/path question, include a call-chain diagram in a fenced code block using down-arrows:
|
|
152
|
+
\`\`\`
|
|
153
|
+
funcA() path/to/a.ts:120
|
|
154
|
+
↓
|
|
155
|
+
funcB() path/to/b.ts:44
|
|
156
|
+
\`\`\`
|
|
157
|
+
- Quote only the code lines that carry the logic, in fenced code blocks, keeping their line numbers. Keep snippets tight.
|
|
158
|
+
- Separate major sections with a "---" rule.
|
|
159
|
+
- End with "**Summary**" — the end-to-end chain in one compact block.
|
|
160
|
+
|
|
161
161
|
Be precise and dense — an engineer should be able to act from this report without opening a file.`;
|
|
162
162
|
// 'plain' style (default) — terse direct answer; the leanest on tokens.
|
|
163
|
-
const SYSTEM_PROMPT_PLAIN = `${ROLE}
|
|
164
|
-
|
|
165
|
-
Output rules:
|
|
166
|
-
- Start with the one-line coverage verdict (above). Then, ONLY if coverage is full or partial, give the answer. Do not narrate reasoning, restate the question, or mention these instructions. No preamble ("Here is", "Sure").
|
|
167
|
-
- For "how does X reach/become Y" questions, trace the actual call path (X -> Y -> Z), naming the functions and the lines that connect them — but only hops the source actually shows.
|
|
168
|
-
- QUOTE the exact lines that matter — with the file path and any line numbers shown — rather than paraphrasing.
|
|
163
|
+
const SYSTEM_PROMPT_PLAIN = `${ROLE}
|
|
164
|
+
|
|
165
|
+
Output rules:
|
|
166
|
+
- Start with the one-line coverage verdict (above). Then, ONLY if coverage is full or partial, give the answer. Do not narrate reasoning, restate the question, or mention these instructions. No preamble ("Here is", "Sure").
|
|
167
|
+
- For "how does X reach/become Y" questions, trace the actual call path (X -> Y -> Z), naming the functions and the lines that connect them — but only hops the source actually shows.
|
|
168
|
+
- QUOTE the exact lines that matter — with the file path and any line numbers shown — rather than paraphrasing.
|
|
169
169
|
- Be precise and dense; the shortest fully self-contained answer wins. If coverage is not-found, the verdict plus the names to explore next IS the whole answer — keep it to a few lines.`;
|
|
170
170
|
const PLAIN_FOOTER = '\n\n— Synthesized by HomeGraph\'s reasoning model from the retrieved source; treat the quoted code as already read. For any area not covered above, run another homegraph_explore with the specific names rather than reading files.';
|
|
171
171
|
function promptFor(style) {
|
|
@@ -25,10 +25,10 @@ function rowToCommit(row) {
|
|
|
25
25
|
* Insert or replace a CommitNode.
|
|
26
26
|
*/
|
|
27
27
|
function insertCommitNode(db, node) {
|
|
28
|
-
db.prepare(`
|
|
29
|
-
INSERT OR REPLACE INTO commit_nodes
|
|
30
|
-
(hash, message, author, timestamp)
|
|
31
|
-
VALUES (@hash, @message, @author, @timestamp)
|
|
28
|
+
db.prepare(`
|
|
29
|
+
INSERT OR REPLACE INTO commit_nodes
|
|
30
|
+
(hash, message, author, timestamp)
|
|
31
|
+
VALUES (@hash, @message, @author, @timestamp)
|
|
32
32
|
`).run({
|
|
33
33
|
hash: node.hash,
|
|
34
34
|
message: node.message,
|
|
@@ -76,10 +76,10 @@ function insertCodeFragment(db, node) {
|
|
|
76
76
|
if (!fragment.id) {
|
|
77
77
|
fragment.id = makeId();
|
|
78
78
|
}
|
|
79
|
-
db.prepare(`
|
|
80
|
-
INSERT OR REPLACE INTO code_fragment_nodes
|
|
81
|
-
(id, change_type, file_path, start_line, end_line, code_diff)
|
|
82
|
-
VALUES (@id, @changeType, @filePath, @startLine, @endLine, @codeDiff)
|
|
79
|
+
db.prepare(`
|
|
80
|
+
INSERT OR REPLACE INTO code_fragment_nodes
|
|
81
|
+
(id, change_type, file_path, start_line, end_line, code_diff)
|
|
82
|
+
VALUES (@id, @changeType, @filePath, @startLine, @endLine, @codeDiff)
|
|
83
83
|
`).run({
|
|
84
84
|
id: fragment.id,
|
|
85
85
|
changeType: fragment.changeType,
|
|
@@ -109,12 +109,12 @@ function findFragmentById(db, fragmentId) {
|
|
|
109
109
|
* Find all fragments for a given commit hash, via the join table.
|
|
110
110
|
*/
|
|
111
111
|
function findFragmentsByCommit(db, commitHash) {
|
|
112
|
-
const rows = db.prepare(`
|
|
113
|
-
SELECT f.id, f.change_type, f.file_path, f.start_line, f.end_line, f.code_diff
|
|
114
|
-
FROM code_fragment_nodes f
|
|
115
|
-
JOIN commit_fragment_relations r ON r.fragment_id = f.id
|
|
116
|
-
WHERE r.commit_hash = ?
|
|
117
|
-
ORDER BY f.file_path, f.start_line
|
|
112
|
+
const rows = db.prepare(`
|
|
113
|
+
SELECT f.id, f.change_type, f.file_path, f.start_line, f.end_line, f.code_diff
|
|
114
|
+
FROM code_fragment_nodes f
|
|
115
|
+
JOIN commit_fragment_relations r ON r.fragment_id = f.id
|
|
116
|
+
WHERE r.commit_hash = ?
|
|
117
|
+
ORDER BY f.file_path, f.start_line
|
|
118
118
|
`).all(commitHash);
|
|
119
119
|
return rows.map(rowToFragment);
|
|
120
120
|
}
|