@alextis59/athena 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +147 -0
  3. package/dist/agent/ask.d.ts +7 -0
  4. package/dist/agent/ask.d.ts.map +1 -0
  5. package/dist/agent/ask.js +35 -0
  6. package/dist/agent/ask.js.map +1 -0
  7. package/dist/agent/citations.d.ts +27 -0
  8. package/dist/agent/citations.d.ts.map +1 -0
  9. package/dist/agent/citations.js +190 -0
  10. package/dist/agent/citations.js.map +1 -0
  11. package/dist/agent/fake-provider.d.ts +9 -0
  12. package/dist/agent/fake-provider.d.ts.map +1 -0
  13. package/dist/agent/fake-provider.js +51 -0
  14. package/dist/agent/fake-provider.js.map +1 -0
  15. package/dist/agent/index.d.ts +10 -0
  16. package/dist/agent/index.d.ts.map +1 -0
  17. package/dist/agent/index.js +6 -0
  18. package/dist/agent/index.js.map +1 -0
  19. package/dist/agent/loop.d.ts +11 -0
  20. package/dist/agent/loop.d.ts.map +1 -0
  21. package/dist/agent/loop.js +156 -0
  22. package/dist/agent/loop.js.map +1 -0
  23. package/dist/agent/providers.d.ts +17 -0
  24. package/dist/agent/providers.d.ts.map +1 -0
  25. package/dist/agent/providers.js +171 -0
  26. package/dist/agent/providers.js.map +1 -0
  27. package/dist/agent/tools.d.ts +8 -0
  28. package/dist/agent/tools.d.ts.map +1 -0
  29. package/dist/agent/tools.js +233 -0
  30. package/dist/agent/tools.js.map +1 -0
  31. package/dist/agent/types.d.ts +84 -0
  32. package/dist/agent/types.d.ts.map +1 -0
  33. package/dist/agent/types.js +2 -0
  34. package/dist/agent/types.js.map +1 -0
  35. package/dist/cli/help.d.ts +2 -0
  36. package/dist/cli/help.d.ts.map +1 -0
  37. package/dist/cli/help.js +28 -0
  38. package/dist/cli/help.js.map +1 -0
  39. package/dist/cli/main.d.ts +3 -0
  40. package/dist/cli/main.d.ts.map +1 -0
  41. package/dist/cli/main.js +5 -0
  42. package/dist/cli/main.js.map +1 -0
  43. package/dist/cli/options.d.ts +21 -0
  44. package/dist/cli/options.d.ts.map +1 -0
  45. package/dist/cli/options.js +97 -0
  46. package/dist/cli/options.js.map +1 -0
  47. package/dist/cli/run.d.ts +21 -0
  48. package/dist/cli/run.d.ts.map +1 -0
  49. package/dist/cli/run.js +144 -0
  50. package/dist/cli/run.js.map +1 -0
  51. package/dist/config/index.d.ts +4 -0
  52. package/dist/config/index.d.ts.map +1 -0
  53. package/dist/config/index.js +3 -0
  54. package/dist/config/index.js.map +1 -0
  55. package/dist/config/loader.d.ts +14 -0
  56. package/dist/config/loader.d.ts.map +1 -0
  57. package/dist/config/loader.js +352 -0
  58. package/dist/config/loader.js.map +1 -0
  59. package/dist/config/schema.d.ts +6 -0
  60. package/dist/config/schema.d.ts.map +1 -0
  61. package/dist/config/schema.js +72 -0
  62. package/dist/config/schema.js.map +1 -0
  63. package/dist/config/types.d.ts +53 -0
  64. package/dist/config/types.d.ts.map +1 -0
  65. package/dist/config/types.js +2 -0
  66. package/dist/config/types.js.map +1 -0
  67. package/dist/doctor/doctor.d.ts +47 -0
  68. package/dist/doctor/doctor.d.ts.map +1 -0
  69. package/dist/doctor/doctor.js +159 -0
  70. package/dist/doctor/doctor.js.map +1 -0
  71. package/dist/embeddings/index.d.ts +117 -0
  72. package/dist/embeddings/index.d.ts.map +1 -0
  73. package/dist/embeddings/index.js +515 -0
  74. package/dist/embeddings/index.js.map +1 -0
  75. package/dist/errors.d.ts +19 -0
  76. package/dist/errors.d.ts.map +1 -0
  77. package/dist/errors.js +37 -0
  78. package/dist/errors.js.map +1 -0
  79. package/dist/index.d.ts +17 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +9 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/indexer/discovery.d.ts +10 -0
  84. package/dist/indexer/discovery.d.ts.map +1 -0
  85. package/dist/indexer/discovery.js +38 -0
  86. package/dist/indexer/discovery.js.map +1 -0
  87. package/dist/indexer/hash.d.ts +3 -0
  88. package/dist/indexer/hash.d.ts.map +1 -0
  89. package/dist/indexer/hash.js +11 -0
  90. package/dist/indexer/hash.js.map +1 -0
  91. package/dist/indexer/index.d.ts +7 -0
  92. package/dist/indexer/index.d.ts.map +1 -0
  93. package/dist/indexer/index.js +5 -0
  94. package/dist/indexer/index.js.map +1 -0
  95. package/dist/indexer/kinds.d.ts +4 -0
  96. package/dist/indexer/kinds.d.ts.map +1 -0
  97. package/dist/indexer/kinds.js +38 -0
  98. package/dist/indexer/kinds.js.map +1 -0
  99. package/dist/indexer/run.d.ts +42 -0
  100. package/dist/indexer/run.d.ts.map +1 -0
  101. package/dist/indexer/run.js +563 -0
  102. package/dist/indexer/run.js.map +1 -0
  103. package/dist/logging/logger.d.ts +11 -0
  104. package/dist/logging/logger.d.ts.map +1 -0
  105. package/dist/logging/logger.js +18 -0
  106. package/dist/logging/logger.js.map +1 -0
  107. package/dist/mcp/index.d.ts +35 -0
  108. package/dist/mcp/index.d.ts.map +1 -0
  109. package/dist/mcp/index.js +392 -0
  110. package/dist/mcp/index.js.map +1 -0
  111. package/dist/parsers/chunking.d.ts +4 -0
  112. package/dist/parsers/chunking.d.ts.map +1 -0
  113. package/dist/parsers/chunking.js +112 -0
  114. package/dist/parsers/chunking.js.map +1 -0
  115. package/dist/parsers/index.d.ts +8 -0
  116. package/dist/parsers/index.d.ts.map +1 -0
  117. package/dist/parsers/index.js +5 -0
  118. package/dist/parsers/index.js.map +1 -0
  119. package/dist/parsers/line-parser.d.ts +13 -0
  120. package/dist/parsers/line-parser.d.ts.map +1 -0
  121. package/dist/parsers/line-parser.js +242 -0
  122. package/dist/parsers/line-parser.js.map +1 -0
  123. package/dist/parsers/normalize.d.ts +4 -0
  124. package/dist/parsers/normalize.d.ts.map +1 -0
  125. package/dist/parsers/normalize.js +17 -0
  126. package/dist/parsers/normalize.js.map +1 -0
  127. package/dist/parsers/parser.d.ts +14 -0
  128. package/dist/parsers/parser.d.ts.map +1 -0
  129. package/dist/parsers/parser.js +77 -0
  130. package/dist/parsers/parser.js.map +1 -0
  131. package/dist/parsers/pdf2llm.d.ts +14 -0
  132. package/dist/parsers/pdf2llm.d.ts.map +1 -0
  133. package/dist/parsers/pdf2llm.js +215 -0
  134. package/dist/parsers/pdf2llm.js.map +1 -0
  135. package/dist/parsers/types.d.ts +48 -0
  136. package/dist/parsers/types.d.ts.map +1 -0
  137. package/dist/parsers/types.js +2 -0
  138. package/dist/parsers/types.js.map +1 -0
  139. package/dist/retrieval/index.d.ts +4 -0
  140. package/dist/retrieval/index.d.ts.map +1 -0
  141. package/dist/retrieval/index.js +3 -0
  142. package/dist/retrieval/index.js.map +1 -0
  143. package/dist/retrieval/schemas.d.ts +127 -0
  144. package/dist/retrieval/schemas.d.ts.map +1 -0
  145. package/dist/retrieval/schemas.js +65 -0
  146. package/dist/retrieval/schemas.js.map +1 -0
  147. package/dist/retrieval/tools.d.ts +31 -0
  148. package/dist/retrieval/tools.d.ts.map +1 -0
  149. package/dist/retrieval/tools.js +803 -0
  150. package/dist/retrieval/tools.js.map +1 -0
  151. package/dist/retrieval/types.d.ts +104 -0
  152. package/dist/retrieval/types.d.ts.map +1 -0
  153. package/dist/retrieval/types.js +2 -0
  154. package/dist/retrieval/types.js.map +1 -0
  155. package/dist/server/index.d.ts +3 -0
  156. package/dist/server/index.d.ts.map +1 -0
  157. package/dist/server/index.js +2 -0
  158. package/dist/server/index.js.map +1 -0
  159. package/dist/server/server.d.ts +49 -0
  160. package/dist/server/server.d.ts.map +1 -0
  161. package/dist/server/server.js +517 -0
  162. package/dist/server/server.js.map +1 -0
  163. package/dist/shared/types.d.ts +98 -0
  164. package/dist/shared/types.d.ts.map +1 -0
  165. package/dist/shared/types.js +2 -0
  166. package/dist/shared/types.js.map +1 -0
  167. package/dist/storage/database.d.ts +18 -0
  168. package/dist/storage/database.d.ts.map +1 -0
  169. package/dist/storage/database.js +66 -0
  170. package/dist/storage/database.js.map +1 -0
  171. package/dist/storage/index.d.ts +8 -0
  172. package/dist/storage/index.d.ts.map +1 -0
  173. package/dist/storage/index.js +5 -0
  174. package/dist/storage/index.js.map +1 -0
  175. package/dist/storage/migrations.d.ts +15 -0
  176. package/dist/storage/migrations.d.ts.map +1 -0
  177. package/dist/storage/migrations.js +170 -0
  178. package/dist/storage/migrations.js.map +1 -0
  179. package/dist/storage/paths.d.ts +15 -0
  180. package/dist/storage/paths.d.ts.map +1 -0
  181. package/dist/storage/paths.js +27 -0
  182. package/dist/storage/paths.js.map +1 -0
  183. package/dist/storage/schema.d.ts +11 -0
  184. package/dist/storage/schema.d.ts.map +1 -0
  185. package/dist/storage/schema.js +40 -0
  186. package/dist/storage/schema.js.map +1 -0
  187. package/dist/ui/index.d.ts +2 -0
  188. package/dist/ui/index.d.ts.map +1 -0
  189. package/dist/ui/index.js +2 -0
  190. package/dist/ui/index.js.map +1 -0
  191. package/dist/ui/static-app.d.ts +2 -0
  192. package/dist/ui/static-app.d.ts.map +1 -0
  193. package/dist/ui/static-app.js +735 -0
  194. package/dist/ui/static-app.js.map +1 -0
  195. package/docs/adr/0001-sqlite-driver.md +23 -0
  196. package/docs/agentic-rag-specifications.md +659 -0
  197. package/docs/agentic-rag-study.md +1056 -0
  198. package/docs/implementation-plan.md +1425 -0
  199. package/docs/mcp-integration.md +154 -0
  200. package/docs/validation-corpus.md +71 -0
  201. package/package.json +79 -0
@@ -0,0 +1,154 @@
1
+ # Athena MCP Integration
2
+
3
+ Athena exposes a read-only Model Context Protocol server through `athena mcp`.
4
+ Use it when an external coding agent needs citation-aware project
5
+ documentation retrieval without taking over Athena's own agent loop.
6
+
7
+ ## Preconditions
8
+
9
+ Build or install Athena, then index the documentation project that the external
10
+ agent should read:
11
+
12
+ ```sh
13
+ npm run build
14
+ node dist/cli/main.js index --root /absolute/path/to/project
15
+ ```
16
+
17
+ For an installed package, replace `node dist/cli/main.js` with `athena` or
18
+ `npx @alextis59/athena`.
19
+
20
+ ## OpenCode
21
+
22
+ OpenCode configures MCP servers under the `mcp` key. A local MCP entry uses
23
+ `type: "local"` and a `command` array, with optional `cwd`, `environment`,
24
+ `enabled`, and `timeout` fields.
25
+
26
+ Development checkout example:
27
+
28
+ ```json
29
+ {
30
+ "$schema": "https://opencode.ai/config.json",
31
+ "mcp": {
32
+ "athena": {
33
+ "type": "local",
34
+ "command": [
35
+ "node",
36
+ "/absolute/path/to/athena/dist/cli/main.js",
37
+ "mcp",
38
+ "--root",
39
+ "."
40
+ ],
41
+ "cwd": "/absolute/path/to/project",
42
+ "enabled": true,
43
+ "timeout": 10000
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ Installed package example:
50
+
51
+ ```json
52
+ {
53
+ "$schema": "https://opencode.ai/config.json",
54
+ "mcp": {
55
+ "athena": {
56
+ "type": "local",
57
+ "command": ["npx", "--yes", "@alextis59/athena", "mcp", "--root", "."],
58
+ "cwd": "/absolute/path/to/project",
59
+ "enabled": true,
60
+ "timeout": 10000
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ After saving the config, run `opencode mcp list` to check that OpenCode can
67
+ start the server and discover its tools.
68
+
69
+ ## Exposed Tools
70
+
71
+ Athena exposes only read-only retrieval tools:
72
+
73
+ - `searchDocs`
74
+ - `readSourceRange`
75
+ - `readPdfSource`
76
+ - `grepDocs`
77
+ - `listDocs`
78
+ - `relatedChunks`
79
+
80
+ It does not expose write, edit, delete, shell, indexing, chat, or package
81
+ management tools through MCP. External agents can retrieve context, but they do
82
+ not own Athena's model loop. Use `athena ask` or the local UI when you want
83
+ Athena itself to plan tool calls and validate final answer citations.
84
+
85
+ ## Citation And Trace Shape
86
+
87
+ MCP tool results are returned as text content containing JSON:
88
+
89
+ ```json
90
+ {
91
+ "result": {},
92
+ "trace": {
93
+ "seenChunkIds": [],
94
+ "readLocators": [],
95
+ "searchScores": []
96
+ }
97
+ }
98
+ ```
99
+
100
+ `result` is the normal Athena retrieval payload. Search results include chunk
101
+ IDs, paths, snippets, score details, and text or PDF locators. Source-read
102
+ tools return exact line or PDF page/region locators.
103
+
104
+ `trace` mirrors the runtime trace shape used by the UI and Athena's internal
105
+ agent loop. Use it to inspect which chunks were surfaced, which source locators
106
+ were read, and how retrieval scores were assigned during the MCP session.
107
+
108
+ ## Manual Smoke Test
109
+
110
+ From this repository, build and index a small fixture project:
111
+
112
+ ```sh
113
+ tmpdir="$(mktemp -d)"
114
+ mkdir -p "$tmpdir/docs"
115
+ cat > "$tmpdir/docs/admin-guide.md" <<'EOF'
116
+ # Admin Guide
117
+
118
+ ## Indexing
119
+
120
+ Set `ATHENA_INDEX_BATCH_SIZE=64` before indexing large docsets.
121
+ EOF
122
+
123
+ npm run build
124
+ node dist/cli/main.js index --root "$tmpdir" --json
125
+ ```
126
+
127
+ Then send a finite stdio MCP session:
128
+
129
+ ```sh
130
+ printf '%s\n' \
131
+ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"manual-smoke","version":"1.0.0"}}}' \
132
+ '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
133
+ '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
134
+ '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"searchDocs","arguments":{"query":"ATHENA_INDEX_BATCH_SIZE","pathPrefix":"docs/"}}}' \
135
+ '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"readSourceRange","arguments":{"path":"docs/admin-guide.md","startLine":3,"endLine":5}}}' \
136
+ | node dist/cli/main.js mcp --root "$tmpdir"
137
+ ```
138
+
139
+ Expected output:
140
+
141
+ - one `initialize` response with `serverInfo.name` set to `athena`;
142
+ - one `tools/list` response with the six read-only retrieval tools;
143
+ - one `searchDocs` response whose JSON text has
144
+ `result[0].path == "docs/admin-guide.md"` and non-empty
145
+ `trace.seenChunkIds`;
146
+ - one `readSourceRange` response whose JSON text includes
147
+ `ATHENA_INDEX_BATCH_SIZE` and a `trace.readLocators` entry for
148
+ `docs/admin-guide.md`.
149
+
150
+ ## References
151
+
152
+ - [MCP 2025-03-26 transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports)
153
+ - [MCP 2025-03-26 tools](https://modelcontextprotocol.io/specification/2025-03-26/server/tools)
154
+ - [OpenCode MCP servers](https://opencode.ai/docs/mcp-servers)
@@ -0,0 +1,71 @@
1
+ # Athena Validation Corpus
2
+
3
+ Date: 2026-07-03
4
+
5
+ ## Purpose
6
+
7
+ The validation corpus gives Athena realistic documents early in the
8
+ implementation. It is used to validate discovery, parsing, chunking, retrieval,
9
+ citations, PDF extraction, UI source previews, and later evaluation runs.
10
+
11
+ ## Directory Layout
12
+
13
+ - `test/corpus/manifest.json` is the locked corpus manifest.
14
+ - `test/corpus/manifest.schema.json` documents the manifest shape.
15
+ - `test/corpus/ground-truth.json` contains deterministic validation questions.
16
+ - `test/corpus/synthetic/` contains committed synthetic controls.
17
+ - `test/corpus/cache/` contains downloaded third-party artifacts and is ignored
18
+ by git.
19
+
20
+ The cache is intentionally outside `.athena/` so tests can distinguish the
21
+ validation corpus from runtime indexes. The script still treats the cache as
22
+ local runtime state, not source code.
23
+
24
+ ## Licensing and Redistribution
25
+
26
+ Synthetic controls are committed under this project's license-compatible test
27
+ fixture policy and are marked `redistribution: "committed"`.
28
+
29
+ Third-party documents are marked `redistribution: "download-only"`. Athena
30
+ commits their URL, license metadata, retrieval date, expected size, and SHA-256
31
+ hash, but it does not commit the downloaded artifacts. This avoids copying
32
+ third-party documentation into the repository while keeping the validation set
33
+ reproducible.
34
+
35
+ ## Retrieval
36
+
37
+ Download or refresh the corpus:
38
+
39
+ ```bash
40
+ npm run corpus:retrieve
41
+ ```
42
+
43
+ Verify an already-cached corpus without network access:
44
+
45
+ ```bash
46
+ npm run corpus:health
47
+ ```
48
+
49
+ The retrieval script refuses changed downloads. If an upstream document changes
50
+ intentionally, refresh the cache, review the changed file, update the manifest
51
+ hash and size in the same commit, and describe why the change is acceptable.
52
+
53
+ ## Coverage
54
+
55
+ The manifest covers:
56
+
57
+ - Markdown README, API reference, and changelog samples;
58
+ - MDX with imports, exports, and embedded JSX that must not execute;
59
+ - plain text and extensionless documentation;
60
+ - reStructuredText;
61
+ - AsciiDoc;
62
+ - HTML with navigation and visible documentation content;
63
+ - born-digital PDF;
64
+ - table-heavy PDF;
65
+ - encrypted hard-PDF warning behavior;
66
+ - synthetic exact-citation, ambiguous-heading, exact-symbol, semantic-only,
67
+ hybrid-comparison, and stale-document controls.
68
+
69
+ Every required document type has at least one ground-truth question. Negative
70
+ questions require Athena to refuse or mark an answer unsupported when the corpus
71
+ does not contain the requested fact.
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@alextis59/athena",
3
+ "version": "1.0.0",
4
+ "description": "Local-first agentic documentation RAG command.",
5
+ "type": "module",
6
+ "private": false,
7
+ "bin": {
8
+ "athena": "dist/cli/main.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE",
14
+ "docs"
15
+ ],
16
+ "keywords": [
17
+ "rag",
18
+ "documentation",
19
+ "search",
20
+ "sqlite",
21
+ "mcp",
22
+ "pdf"
23
+ ],
24
+ "homepage": "https://github.com/alextis59/athena#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/alextis59/athena/issues"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/alextis59/athena.git"
31
+ },
32
+ "license": "ISC",
33
+ "author": "Athena contributors",
34
+ "engines": {
35
+ "node": ">=22.0.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "main": "./dist/index.js",
41
+ "types": "./dist/index.d.ts",
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "import": "./dist/index.js"
46
+ }
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.json",
50
+ "check": "npm run format:check && npm run lint && npm run typecheck && npm test",
51
+ "check:publish": "npm run check && npm run eval && npm run build",
52
+ "corpus:health": "tsx scripts/corpus.ts health --offline",
53
+ "corpus:retrieve": "tsx scripts/corpus.ts retrieve",
54
+ "eval": "tsx scripts/eval.ts validate --offline",
55
+ "format:check": "prettier --check .",
56
+ "lint": "eslint .",
57
+ "prepack": "npm run build",
58
+ "prepublishOnly": "npm run check:publish",
59
+ "test": "node --import tsx --test \"test/**/*.test.ts\"",
60
+ "typecheck": "tsc -p tsconfig.test.json --noEmit"
61
+ },
62
+ "devDependencies": {
63
+ "@eslint/js": "^10.0.1",
64
+ "@types/better-sqlite3": "^7.6.13",
65
+ "@types/node": "^26.1.0",
66
+ "eslint": "^10.6.0",
67
+ "prettier": "^3.9.4",
68
+ "tsx": "^4.23.0",
69
+ "typescript": "^6.0.3",
70
+ "typescript-eslint": "^8.62.1"
71
+ },
72
+ "dependencies": {
73
+ "@huggingface/transformers": "^4.2.0",
74
+ "better-sqlite3": "^12.11.1",
75
+ "fast-glob": "^3.3.3",
76
+ "jiti": "^2.7.0",
77
+ "pdf-2-llm": "^1.1.0"
78
+ }
79
+ }