pantheon-opencode 1.6.0-beta.15 → 1.6.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -1
- package/README.md +95 -26
- package/README.pt-BR.md +14 -14
- package/package.json +3 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/_pantheon_paths.py +24 -0
- package/scripts/doctor.mjs +7 -2
- package/scripts/install-mcp.mjs +1 -1
- package/scripts/mcp_persistence.py +1489 -1039
- package/scripts/memory_mcp.py +12 -843
- package/scripts/test-opencode-v2-sandbox.sh +2 -115
- package/skills-lock.json +3 -3
- package/src/agents/apollo.md +1 -2
- package/src/agents/athena.md +1 -2
- package/src/agents/gaia.md +0 -1
- package/src/agents/hermes.md +1 -1
- package/src/agents/iris.md +0 -1
- package/src/agents/mnemosyne.md +3 -2
- package/src/agents/zeus.md +1 -1
- package/src/mcp/_pantheon_paths.py +24 -0
- package/src/mcp/mcp_codemap_module.py +86 -18
- package/src/mcp/mcp_persistence.py +1489 -1039
- package/src/mcp/memory_mcp.py +101 -57
- package/src/pantheon/goal-loop.ts +11 -8
- package/src/pantheon/task-result-guard.ts +38 -2
- package/src/pantheon/v2-execute-after.ts +117 -20
- package/src/pantheon/v2-tools.ts +10 -1
- package/src/plugin-v2.ts +6 -4
- package/src/plugin.ts +3 -2
- package/src/plugins/tui/dist/tui-v2.js +2 -2
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/routing.yml +4 -4
- package/src/skills/codemap/SKILL.md +1 -1
- package/src/skills/memory-bank/SKILL.md +17 -13
- package/src/skills/session-goal/SKILL.md +12 -22
- package/scripts/probe-context-rehydrate.mjs +0 -263
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
# `@opencode/plugin@2.0.18` SDK contract or compatibility across the full 2.x
|
|
16
16
|
# line. This project is V2-exclusive, so there is a single host leg to validate.
|
|
17
17
|
#
|
|
18
|
-
# Modes (
|
|
18
|
+
# Modes (run sequentially; a failure stops later checks):
|
|
19
19
|
# --prepare Build tarball, install pantheon-opencode + the OpenCode V2
|
|
20
20
|
# binary in the sandbox prefix, headless init, and generate
|
|
21
21
|
# the project config and sandbox run-test.sh.
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
# regenerated first).
|
|
24
24
|
# --prompts Prompt battery via `opencode run --format json`.
|
|
25
25
|
# --cost Offline pantheon_cost probe.
|
|
26
|
-
# --rehydrate Offline context_rehydrate + context_session_summary probe.
|
|
27
26
|
# --hooks V2 hook canary: proves hook callbacks FIRE through the
|
|
28
27
|
# sandbox's V2 binary (not merely that a plugin loaded).
|
|
29
28
|
# This does not test transform callback effects or Pantheon
|
|
@@ -88,14 +87,12 @@ TARGET_VERSION="v2"
|
|
|
88
87
|
|
|
89
88
|
REPORT_FILE="$SANDBOX_ROOT/prompts-report.md"
|
|
90
89
|
COST_REPORT_FILE="$SANDBOX_ROOT/pantheon-cost-report.md"
|
|
91
|
-
REHYDRATE_REPORT_FILE="$SANDBOX_ROOT/context-rehydrate-report.md"
|
|
92
90
|
EXTRACT_PY="$SANDBOX_ROOT/.prompt-extract-json.py"
|
|
93
91
|
|
|
94
92
|
MODE_PREPARE=0
|
|
95
93
|
MODE_RESET=0
|
|
96
94
|
MODE_PROMPTS=0
|
|
97
95
|
MODE_COST=0
|
|
98
|
-
MODE_REHYDRATE=0
|
|
99
96
|
MODE_HOOKS=0
|
|
100
97
|
RUN_VERSION=""
|
|
101
98
|
|
|
@@ -1538,45 +1535,6 @@ run_cost_probe() { # v
|
|
|
1538
1535
|
record "$v" "pantheon-cost" "$status" "$detail"
|
|
1539
1536
|
}
|
|
1540
1537
|
|
|
1541
|
-
run_rehydrate_probe() { # v
|
|
1542
|
-
local v="$1" package_root probe raw status detail
|
|
1543
|
-
if ! package_root="$(installed_package_root)"; then
|
|
1544
|
-
record "$v" "context-rehydrate" "FAIL" "sandbox package is not installed"
|
|
1545
|
-
return 0
|
|
1546
|
-
fi
|
|
1547
|
-
probe="$package_root/scripts/probe-context-rehydrate.mjs"
|
|
1548
|
-
if [ ! -f "$probe" ]; then
|
|
1549
|
-
record "$v" "context-rehydrate" "FAIL" "installed package has no offline context probe"
|
|
1550
|
-
return 0
|
|
1551
|
-
fi
|
|
1552
|
-
if ! command -v node >/dev/null 2>&1; then
|
|
1553
|
-
record "$v" "context-rehydrate" "FAIL" "node runtime is not available"
|
|
1554
|
-
return 0
|
|
1555
|
-
fi
|
|
1556
|
-
set +e
|
|
1557
|
-
raw="$(timeout 30 node "$probe" --version "$v" --json 2>&1)"
|
|
1558
|
-
local rc=$?
|
|
1559
|
-
set -e
|
|
1560
|
-
case "$raw" in
|
|
1561
|
-
*'"status":"PASS"'*) status="PASS" ;;
|
|
1562
|
-
*'"status":"NOT_TESTED"'*) status="FAIL" ;;
|
|
1563
|
-
*'"status":"AMBIENTAL"'*) status="FAIL" ;;
|
|
1564
|
-
*) status="FAIL" ;;
|
|
1565
|
-
esac
|
|
1566
|
-
detail="$(printf '%s' "$raw" | tr '\n' ' ' | cut -c1-400)"
|
|
1567
|
-
if [ "$rc" -eq 124 ]; then
|
|
1568
|
-
status="FAIL"
|
|
1569
|
-
detail="context probe timed out after 30s"
|
|
1570
|
-
elif [ "$rc" -ne 0 ] && [ "$status" = "PASS" ]; then
|
|
1571
|
-
# A non-zero probe exit must never be reported as PASS.
|
|
1572
|
-
status="FAIL"
|
|
1573
|
-
detail="$detail (probe exit $rc)"
|
|
1574
|
-
elif [ "$rc" -ne 0 ] && [ "$status" != "FAIL" ]; then
|
|
1575
|
-
detail="$detail (probe exit $rc)"
|
|
1576
|
-
fi
|
|
1577
|
-
record "$v" "context-rehydrate" "$status" "$detail"
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
1538
|
run_version_prompts() { # v
|
|
1581
1539
|
local v="$1" bin
|
|
1582
1540
|
if ! bin="$(sandbox_bin)"; then
|
|
@@ -1669,31 +1627,6 @@ write_cost_report() { # versions...
|
|
|
1669
1627
|
log "Cost probe report written to $COST_REPORT_FILE"
|
|
1670
1628
|
}
|
|
1671
1629
|
|
|
1672
|
-
write_rehydrate_report() { # versions...
|
|
1673
|
-
local versions=("$@") total_fail=0 total_pass=0
|
|
1674
|
-
{
|
|
1675
|
-
printf '# Pantheon Context Rehydration Probe Report\n\n'
|
|
1676
|
-
printf -- '- **Date:** %s\n' "$(date -u '+%Y-%m-%d %H:%M UTC')"
|
|
1677
|
-
printf -- '- **Sandbox:** %s\n\n' "$SANDBOX_ROOT"
|
|
1678
|
-
printf '| Version | Probe | Result | Detail |\n|---|---|---|---|\n'
|
|
1679
|
-
local v result
|
|
1680
|
-
for v in "${versions[@]}"; do
|
|
1681
|
-
result="${RESULTS["$v:context-rehydrate"]:-NOT_TESTED}"
|
|
1682
|
-
case "$result" in
|
|
1683
|
-
PASS) total_pass=$((total_pass + 1)) ;;
|
|
1684
|
-
*) total_fail=$((total_fail + 1)) ;;
|
|
1685
|
-
esac
|
|
1686
|
-
printf '| %s | context_rehydrate + context_session_summary | %s | %s |\n' \
|
|
1687
|
-
"$v" "$result" "${DETAILS["$v:context-rehydrate"]:-—}"
|
|
1688
|
-
done
|
|
1689
|
-
printf '\n## Summary\n\n'
|
|
1690
|
-
printf -- '- PASS: %d\n- Not PASS (blocking): %d\n\n' \
|
|
1691
|
-
"$total_pass" "$total_fail"
|
|
1692
|
-
printf '**Verdict: %s**\n' "$(probe_verdict "$total_pass" "$((total_pass + total_fail))")"
|
|
1693
|
-
} > "$REHYDRATE_REPORT_FILE"
|
|
1694
|
-
log "Context probe report written to $REHYDRATE_REPORT_FILE"
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
1630
|
run_cost() { # versions...
|
|
1698
1631
|
local versions=("$@") v fail=0
|
|
1699
1632
|
mkdir -p "$SANDBOX_ROOT"
|
|
@@ -1713,25 +1646,6 @@ run_cost() { # versions...
|
|
|
1713
1646
|
log "Cost probe: PASS."
|
|
1714
1647
|
}
|
|
1715
1648
|
|
|
1716
|
-
run_rehydrate() { # versions...
|
|
1717
|
-
local versions=("$@") v fail=0
|
|
1718
|
-
mkdir -p "$SANDBOX_ROOT"
|
|
1719
|
-
for v in "${versions[@]}"; do
|
|
1720
|
-
log "[$v] context_rehydrate/session_summary offline probe ..."
|
|
1721
|
-
run_rehydrate_probe "$v"
|
|
1722
|
-
log "[$v] context probe → ${RESULTS["$v:context-rehydrate"]}"
|
|
1723
|
-
done
|
|
1724
|
-
write_rehydrate_report "${versions[@]}"
|
|
1725
|
-
for v in "${versions[@]}"; do
|
|
1726
|
-
[ "${RESULTS["$v:context-rehydrate"]:-}" = "PASS" ] || fail=$((fail + 1))
|
|
1727
|
-
done
|
|
1728
|
-
if [ "$fail" -gt 0 ]; then
|
|
1729
|
-
log "Context probe: $fail check(s) without explicit PASS."
|
|
1730
|
-
exit 1
|
|
1731
|
-
fi
|
|
1732
|
-
log "Context probe: PASS."
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
1649
|
# ── Hook canary (proves callbacks FIRE, not just that a plugin loaded) ────────
|
|
1736
1650
|
|
|
1737
1651
|
run_hooks() {
|
|
@@ -1816,7 +1730,6 @@ while [ $# -gt 0 ]; do
|
|
|
1816
1730
|
--reset) MODE_RESET=1 ;;
|
|
1817
1731
|
--prompts) MODE_PROMPTS=1 ;;
|
|
1818
1732
|
--cost) MODE_COST=1 ;;
|
|
1819
|
-
--rehydrate) MODE_REHYDRATE=1 ;;
|
|
1820
1733
|
--hooks) MODE_HOOKS=1 ;;
|
|
1821
1734
|
--run)
|
|
1822
1735
|
shift
|
|
@@ -1842,7 +1755,7 @@ fi
|
|
|
1842
1755
|
|
|
1843
1756
|
if [ "$MODE_PREPARE" -eq 0 ] && [ -z "$RUN_VERSION" ] \
|
|
1844
1757
|
&& [ "$MODE_PROMPTS" -eq 0 ] && [ "$MODE_COST" -eq 0 ] \
|
|
1845
|
-
&& [ "$
|
|
1758
|
+
&& [ "$MODE_HOOKS" -eq 0 ]; then
|
|
1846
1759
|
usage
|
|
1847
1760
|
fi
|
|
1848
1761
|
|
|
@@ -1862,10 +1775,6 @@ if [ -n "$RUN_VERSION" ]; then
|
|
|
1862
1775
|
sandbox_env
|
|
1863
1776
|
run_cost "$RUN_VERSION"
|
|
1864
1777
|
fi
|
|
1865
|
-
if [ "$MODE_REHYDRATE" -eq 1 ]; then
|
|
1866
|
-
sandbox_env
|
|
1867
|
-
run_rehydrate "$RUN_VERSION"
|
|
1868
|
-
fi
|
|
1869
1778
|
if [ "$MODE_HOOKS" -eq 1 ]; then
|
|
1870
1779
|
sandbox_env
|
|
1871
1780
|
run_hooks
|
|
@@ -1876,37 +1785,15 @@ elif [ "$MODE_PROMPTS" -eq 1 ]; then
|
|
|
1876
1785
|
if [ "$MODE_COST" -eq 1 ]; then
|
|
1877
1786
|
run_cost "$TARGET_VERSION"
|
|
1878
1787
|
fi
|
|
1879
|
-
if [ "$MODE_REHYDRATE" -eq 1 ]; then
|
|
1880
|
-
run_rehydrate "$TARGET_VERSION"
|
|
1881
|
-
fi
|
|
1882
1788
|
if [ "$MODE_HOOKS" -eq 1 ]; then
|
|
1883
1789
|
run_hooks
|
|
1884
1790
|
fi
|
|
1885
1791
|
elif [ "$MODE_COST" -eq 1 ]; then
|
|
1886
1792
|
sandbox_env
|
|
1887
1793
|
run_cost "$TARGET_VERSION"
|
|
1888
|
-
if [ "$MODE_REHYDRATE" -eq 1 ]; then
|
|
1889
|
-
run_rehydrate "$TARGET_VERSION"
|
|
1890
|
-
fi
|
|
1891
1794
|
if [ "$MODE_HOOKS" -eq 1 ]; then
|
|
1892
1795
|
run_hooks
|
|
1893
1796
|
fi
|
|
1894
|
-
elif [ "$MODE_REHYDRATE" -eq 1 ]; then
|
|
1895
|
-
sandbox_env
|
|
1896
|
-
rehydrate_status=0
|
|
1897
|
-
# run_rehydrate exits when its check fails; isolate it so the separately
|
|
1898
|
-
# requested hook canary still runs, then return a failing status afterward.
|
|
1899
|
-
(run_rehydrate "$TARGET_VERSION") || rehydrate_status=$?
|
|
1900
|
-
hooks_status=0
|
|
1901
|
-
if [ "$MODE_HOOKS" -eq 1 ]; then
|
|
1902
|
-
(run_hooks) || hooks_status=$?
|
|
1903
|
-
fi
|
|
1904
|
-
if [ "$rehydrate_status" -ne 0 ]; then
|
|
1905
|
-
exit "$rehydrate_status"
|
|
1906
|
-
fi
|
|
1907
|
-
if [ "$hooks_status" -ne 0 ]; then
|
|
1908
|
-
exit "$hooks_status"
|
|
1909
|
-
fi
|
|
1910
1797
|
elif [ "$MODE_HOOKS" -eq 1 ]; then
|
|
1911
1798
|
sandbox_env
|
|
1912
1799
|
run_hooks
|
package/skills-lock.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"src/skills/auto-continue/SKILL.md": "3fd4167b2e015510aec428098d27bb15854ba239c4dc7a064177d62e2353af86",
|
|
5
5
|
"src/skills/clonedeps/SKILL.md": "3e0b43cf96da98c83699dc48db3fd58fbfda84b9022bb70d3747875c81c3e124",
|
|
6
6
|
"src/skills/code-review-checklist/SKILL.md": "6445513ab880efdb1005861ae13cb9a215f80b9d260f6278499f60771e07858c",
|
|
7
|
-
"src/skills/codemap/SKILL.md": "
|
|
7
|
+
"src/skills/codemap/SKILL.md": "d21b3fa66b931b29dcf1ec0f0fcf1ec28514642a9f33f96e4b2901a0be74c72d",
|
|
8
8
|
"src/skills/context-compression/SKILL.md": "346ed8697b8db42cc49403ee3dd38f9b775fe93cb55395d73c81b55cc77442d6",
|
|
9
9
|
"src/skills/git-workflow-and-versioning/SKILL.md": "685a94041f1b4ce2a430301f517b89102055696267c369a7e8fb191606659276",
|
|
10
10
|
"src/skills/incremental-implementation/SKILL.md": "7065ddb45da3c6b6751de07f290e92e6cb072e949a2e3aaae13ee7762f0a70fc",
|
|
11
11
|
"src/skills/loop-engineering/SKILL.md": "f804e545821b9cca8fe0ec517307ed902446f28c2ca8ff9194c0f987cf7229e3",
|
|
12
|
-
"src/skills/memory-bank/SKILL.md": "
|
|
12
|
+
"src/skills/memory-bank/SKILL.md": "28bffa0f18cac99488d21563a544c1ade4319053621a6d846c2d7d623ffd79ba",
|
|
13
13
|
"src/skills/reflect/SKILL.md": "4c7608c2a55cb8a50ac90fc0e2446bdf25e7914b1748cb7731c311d13c29dfdd",
|
|
14
14
|
"src/skills/security-hardening/SKILL.md": "6d637e122421f7bc3b751f04854ad343a5a5d35249458bc8939233138fd3f20d",
|
|
15
|
-
"src/skills/session-goal/SKILL.md": "
|
|
15
|
+
"src/skills/session-goal/SKILL.md": "08d2e3876e330207eebba065345b51e585d5363b596b7b71132dbf40b077efc4",
|
|
16
16
|
"src/skills/simplify/SKILL.md": "aa739e9f75962a77d6574557d674ea01b5aea95e580b721d66c058753161b053",
|
|
17
17
|
"src/skills/spec-driven-development/SKILL.md": "ccfbc0c32116a1d144f5c12a4187c053322ed31625a622a58c59739a57a86743",
|
|
18
18
|
"src/skills/tdd-with-agents/SKILL.md": "9d20607ea34fc3e02c7e3ef5186b103d84196bd9a13aaadd55a44f41339125da",
|
package/src/agents/apollo.md
CHANGED
package/src/agents/athena.md
CHANGED
package/src/agents/gaia.md
CHANGED
package/src/agents/hermes.md
CHANGED
|
@@ -138,7 +138,7 @@ See `skill: tdd-with-agents` for the full TDD cycle.
|
|
|
138
138
|
|
|
139
139
|
## Project Context
|
|
140
140
|
|
|
141
|
-
> **Adopt this agent for your product:** Replace this section with your project's specific routers, services, and models. Store
|
|
141
|
+
> **Adopt this agent for your product:** Replace this section with your project's specific routers, services, and models. Store durable reusable facts through `pantheon-memory` when warranted and when the tool is granted, or reference project documentation under `.pantheon/memory-bank/`, which is read on demand rather than auto-loaded.
|
|
142
142
|
|
|
143
143
|
## Implementation Process
|
|
144
144
|
|
package/src/agents/iris.md
CHANGED
package/src/agents/mnemosyne.md
CHANGED
|
@@ -64,8 +64,9 @@ If asked to edit code, refuse and redirect to the appropriate implementation age
|
|
|
64
64
|
- Write task records to .pantheon/memory-bank/_tasks/
|
|
65
65
|
|
|
66
66
|
### 3. Documentation Standards
|
|
67
|
-
-
|
|
68
|
-
-
|
|
67
|
+
- Durable facts and decisions go to `pantheon-memory` with `memory_store` only when retention is warranted; this is not auto-loaded.
|
|
68
|
+
- Project context and plans that should be reviewable as files go under `.pantheon/memory-bank/` on explicit request.
|
|
69
|
+
- Project Memory Bank files can be read on demand through `pantheon://memory-bank/{path}`; `/memories/repo/` and `/memories/session/` are not implemented Pantheon stores.
|
|
69
70
|
- ADRs only for significant decisions
|
|
70
71
|
- Never create .md files outside .pantheon/memory-bank/
|
|
71
72
|
|
package/src/agents/zeus.md
CHANGED
|
@@ -14,7 +14,7 @@ temperature: 0.2
|
|
|
14
14
|
mcp_tools:
|
|
15
15
|
pantheon-resources: all
|
|
16
16
|
pantheon-memory: [memory_search]
|
|
17
|
-
pantheon-persistence: [context_save, context_get]
|
|
17
|
+
pantheon-persistence: [context_save, context_get, goal_create, goal_get, goal_update, goal_done]
|
|
18
18
|
pantheon-vision: [vision_describe]
|
|
19
19
|
skills:
|
|
20
20
|
- agent-coordination
|
|
@@ -72,6 +72,30 @@ def pantheon_project() -> Path | None:
|
|
|
72
72
|
return None
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
def trusted_project_root() -> Path | None:
|
|
76
|
+
"""Return an explicitly host-bound project root, or ``None``.
|
|
77
|
+
|
|
78
|
+
The globally launched Memory MCP commonly runs with its working directory
|
|
79
|
+
set to the installed runtime, not the active project. Therefore this
|
|
80
|
+
security-sensitive lookup deliberately accepts only an absolute
|
|
81
|
+
``PANTHEON_PROJECT`` binding and never falls back to ``PWD`` or cwd.
|
|
82
|
+
"""
|
|
83
|
+
configured_root = os.environ.get("PANTHEON_PROJECT")
|
|
84
|
+
if not configured_root:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
candidate = Path(configured_root)
|
|
88
|
+
if not candidate.is_absolute():
|
|
89
|
+
return None
|
|
90
|
+
try:
|
|
91
|
+
root = candidate.resolve(strict=True)
|
|
92
|
+
except (OSError, RuntimeError):
|
|
93
|
+
return None
|
|
94
|
+
if not root.is_dir() or root == Path(root.anchor):
|
|
95
|
+
return None
|
|
96
|
+
return root
|
|
97
|
+
|
|
98
|
+
|
|
75
99
|
def _is_valid_logical_cwd(logical_cwd: str, physical_cwd: str) -> bool:
|
|
76
100
|
"""Validate a launcher-provided logical cwd without resolving its result.
|
|
77
101
|
|
|
@@ -415,65 +415,133 @@ def _insert_entities_and_relations(
|
|
|
415
415
|
)
|
|
416
416
|
|
|
417
417
|
|
|
418
|
+
def _resolve_trusted_project_root(
|
|
419
|
+
project_root: str | Path | None,
|
|
420
|
+
) -> tuple[Path | None, str | None]:
|
|
421
|
+
"""Resolve and validate the trusted root used by code indexing."""
|
|
422
|
+
if project_root is None:
|
|
423
|
+
return None, "Trusted project root unavailable; code_index is disabled"
|
|
424
|
+
|
|
425
|
+
root_candidate = Path(project_root)
|
|
426
|
+
if not root_candidate.is_absolute():
|
|
427
|
+
return None, "Trusted project root must be absolute"
|
|
428
|
+
try:
|
|
429
|
+
root = root_candidate.resolve(strict=True)
|
|
430
|
+
except (OSError, RuntimeError, ValueError):
|
|
431
|
+
return None, "Trusted project root is missing or invalid"
|
|
432
|
+
if not root.is_dir() or root == Path(root.anchor):
|
|
433
|
+
return None, "Trusted project root must be a directory"
|
|
434
|
+
return root, None
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _resolve_index_target(
|
|
438
|
+
root: Path, path: str | Path | None
|
|
439
|
+
) -> tuple[Path | None, str | None]:
|
|
440
|
+
"""Resolve an index target and require canonical containment in its root."""
|
|
441
|
+
target = root if path is None else Path(path)
|
|
442
|
+
if ".." in target.parts:
|
|
443
|
+
return None, "Index path must not contain parent traversal"
|
|
444
|
+
candidate = target if target.is_absolute() else root / target
|
|
445
|
+
try:
|
|
446
|
+
base = candidate.resolve(strict=True)
|
|
447
|
+
except (OSError, RuntimeError, ValueError):
|
|
448
|
+
return None, "Index path does not exist or is invalid"
|
|
449
|
+
if not base.is_relative_to(root):
|
|
450
|
+
return None, "Index path must resolve within the trusted project root"
|
|
451
|
+
if not base.is_file() and not base.is_dir():
|
|
452
|
+
return None, "Index path must be a file or directory"
|
|
453
|
+
return base, None
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def _resolve_index_base(
|
|
457
|
+
project_root: str | Path | None, path: str | Path | None
|
|
458
|
+
) -> tuple[Path | None, Path | None, str | None]:
|
|
459
|
+
"""Resolve an index target under its validated project root."""
|
|
460
|
+
root, error = _resolve_trusted_project_root(project_root)
|
|
461
|
+
if error or root is None:
|
|
462
|
+
return root, None, error
|
|
463
|
+
base, error = _resolve_index_target(root, path)
|
|
464
|
+
return root, base, error
|
|
465
|
+
|
|
466
|
+
|
|
418
467
|
def code_index( # noqa: C901, PLR0912, PLR0915
|
|
419
|
-
conn: sqlite3.Connection,
|
|
468
|
+
conn: sqlite3.Connection,
|
|
469
|
+
path: str | Path | None = None,
|
|
470
|
+
force: bool = False,
|
|
471
|
+
*,
|
|
472
|
+
project_root: str | Path | None = None,
|
|
420
473
|
) -> dict[str, Any]:
|
|
474
|
+
root, base, error = _resolve_index_base(project_root, path)
|
|
475
|
+
if error or root is None or base is None:
|
|
476
|
+
return {
|
|
477
|
+
"error": error or "Index path is invalid",
|
|
478
|
+
"indexed": 0,
|
|
479
|
+
"skipped": 0,
|
|
480
|
+
}
|
|
481
|
+
|
|
421
482
|
ensure_codemap_schema(conn)
|
|
422
|
-
base = Path(path) if path else Path.cwd()
|
|
423
|
-
if not base.exists():
|
|
424
|
-
return {"error": f"Path not found: {base}", "indexed": 0, "skipped": 0}
|
|
425
483
|
files: list[Path] = (
|
|
426
484
|
[base]
|
|
427
485
|
if base.is_file()
|
|
428
486
|
else [p for ext in SUPPORTED_EXTS for p in base.rglob(f"*{ext}")]
|
|
429
487
|
)
|
|
430
488
|
indexed = skipped = errors = large_skipped = unsupported = 0
|
|
431
|
-
for
|
|
489
|
+
for candidate in files:
|
|
490
|
+
try:
|
|
491
|
+
file_path = candidate.resolve(strict=True)
|
|
492
|
+
except (OSError, RuntimeError, ValueError):
|
|
493
|
+
continue
|
|
494
|
+
if not file_path.is_relative_to(root):
|
|
495
|
+
continue
|
|
432
496
|
if (
|
|
433
|
-
any(p.startswith(".") for p in
|
|
434
|
-
and ".pantheon" not in str(
|
|
435
|
-
and (".git" in
|
|
497
|
+
any(p.startswith(".") for p in file_path.parts)
|
|
498
|
+
and ".pantheon" not in str(file_path)
|
|
499
|
+
and (".git" in file_path.parts or "__pycache__" in file_path.parts)
|
|
436
500
|
):
|
|
437
501
|
continue
|
|
438
|
-
if
|
|
502
|
+
if (
|
|
503
|
+
"node_modules" in file_path.parts
|
|
504
|
+
or ".venv" in file_path.parts
|
|
505
|
+
or "venv" in file_path.parts
|
|
506
|
+
):
|
|
439
507
|
continue
|
|
440
|
-
ext =
|
|
508
|
+
ext = file_path.suffix.lower()
|
|
441
509
|
lang = SUPPORTED_EXTS.get(ext)
|
|
442
510
|
if not lang:
|
|
443
511
|
unsupported += 1
|
|
444
512
|
continue
|
|
445
513
|
try:
|
|
446
|
-
if
|
|
514
|
+
if file_path.stat().st_size > LARGE_FILE_THRESHOLD:
|
|
447
515
|
large_skipped += 1
|
|
448
516
|
continue
|
|
449
|
-
content =
|
|
517
|
+
content = file_path.read_text(encoding="utf-8", errors="ignore")
|
|
450
518
|
if not content.strip():
|
|
451
519
|
h = _hash_content(content)
|
|
452
520
|
conn.execute(
|
|
453
521
|
"INSERT OR REPLACE INTO code_files "
|
|
454
522
|
"(path, hash, language) VALUES (?,?,?)",
|
|
455
|
-
[str(
|
|
523
|
+
[str(file_path), h, lang],
|
|
456
524
|
)
|
|
457
525
|
conn.commit()
|
|
458
526
|
skipped += 1
|
|
459
527
|
continue
|
|
460
528
|
h = _hash_content(content)
|
|
461
529
|
row = conn.execute(
|
|
462
|
-
"SELECT hash FROM code_files WHERE path=?", [str(
|
|
530
|
+
"SELECT hash FROM code_files WHERE path=?", [str(file_path)]
|
|
463
531
|
).fetchone()
|
|
464
532
|
if row and row[0] == h and not force:
|
|
465
533
|
skipped += 1
|
|
466
534
|
continue
|
|
467
535
|
ents, rels = (
|
|
468
|
-
_parse_python_entities(str(
|
|
536
|
+
_parse_python_entities(str(file_path), content)
|
|
469
537
|
if lang == "python"
|
|
470
|
-
else _parse_typescript_entities(str(
|
|
538
|
+
else _parse_typescript_entities(str(file_path), content)
|
|
471
539
|
)
|
|
472
540
|
if not ents and not rels:
|
|
473
541
|
conn.execute(
|
|
474
542
|
"INSERT OR REPLACE INTO code_files "
|
|
475
543
|
"(path, hash, language) VALUES (?,?,?)",
|
|
476
|
-
[str(
|
|
544
|
+
[str(file_path), h, lang],
|
|
477
545
|
)
|
|
478
546
|
conn.commit()
|
|
479
547
|
try:
|
|
@@ -486,7 +554,7 @@ def code_index( # noqa: C901, PLR0912, PLR0915
|
|
|
486
554
|
_insert_entities_and_relations(conn, ents, rels)
|
|
487
555
|
conn.execute(
|
|
488
556
|
"INSERT OR REPLACE INTO code_files (path,hash,language) VALUES (?,?,?)",
|
|
489
|
-
[str(
|
|
557
|
+
[str(file_path), h, lang],
|
|
490
558
|
)
|
|
491
559
|
conn.commit()
|
|
492
560
|
indexed += 1
|