@kyleparrott/where-was-i 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +89 -0
- package/README.md +167 -0
- package/dist/src/cli.js +423 -0
- package/dist/src/core/codex.js +303 -0
- package/dist/src/core/config.js +168 -0
- package/dist/src/core/database.js +432 -0
- package/dist/src/core/doctor.js +113 -0
- package/dist/src/core/embeddings.js +118 -0
- package/dist/src/core/indexer.js +60 -0
- package/dist/src/core/paths.js +20 -0
- package/dist/src/core/reset.js +18 -0
- package/dist/src/core/search-mode.js +17 -0
- package/dist/src/core/search.js +562 -0
- package/dist/src/core/semantic.js +220 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/core/vector.js +311 -0
- package/dist/src/mcp.js +345 -0
- package/dist/src/web-client.js +61 -0
- package/dist/src/web-settings.js +157 -0
- package/dist/src/web-style.js +797 -0
- package/dist/src/web-utils.js +81 -0
- package/dist/src/web-views.js +389 -0
- package/dist/src/web.js +512 -0
- package/docs/assets/web-ui.png +0 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work.
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on or derived from the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License.
|
|
30
|
+
|
|
31
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License.
|
|
34
|
+
|
|
35
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to patent claims licensable by such Contributor that are necessarily infringed by their Contribution alone or by combination of their Contribution with the Work to which such Contribution was submitted. If You institute patent litigation against any entity, including a cross-claim or counterclaim in a lawsuit, alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
36
|
+
|
|
37
|
+
4. Redistribution.
|
|
38
|
+
|
|
39
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
40
|
+
|
|
41
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
42
|
+
|
|
43
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
44
|
+
|
|
45
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
46
|
+
|
|
47
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
48
|
+
|
|
49
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
50
|
+
|
|
51
|
+
5. Submission of Contributions.
|
|
52
|
+
|
|
53
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
54
|
+
|
|
55
|
+
6. Trademarks.
|
|
56
|
+
|
|
57
|
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty.
|
|
60
|
+
|
|
61
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work, and each Contributor provides its Contributions, on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability.
|
|
64
|
+
|
|
65
|
+
In no event and under no legal theory, whether in tort, including negligence, contract, or otherwise, unless required by applicable law, such as deliberate and grossly negligent acts, or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work, including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such Contributor has been advised of the possibility of such damages.
|
|
66
|
+
|
|
67
|
+
9. Accepting Warranty or Additional Liability.
|
|
68
|
+
|
|
69
|
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
70
|
+
|
|
71
|
+
END OF TERMS AND CONDITIONS
|
|
72
|
+
|
|
73
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
74
|
+
|
|
75
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. Do not include the brackets. The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
76
|
+
|
|
77
|
+
Copyright 2026 Kyle Parrott
|
|
78
|
+
|
|
79
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
80
|
+
you may not use this file except in compliance with the License.
|
|
81
|
+
You may obtain a copy of the License at
|
|
82
|
+
|
|
83
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
84
|
+
|
|
85
|
+
Unless required by applicable law or agreed to in writing, software
|
|
86
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
87
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
88
|
+
See the License for the specific language governing permissions and
|
|
89
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Where Was I?
|
|
2
|
+
|
|
3
|
+
Local search for the Codex sessions you almost remember.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Where Was I is a local CLI, web UI, and MCP server for OpenAI Codex session history. It reads Codex JSONL transcripts from `~/.codex`, builds a derived SQLite index in `~/.where-was-i`, and helps you find old threads by phrase, clue, project path, or message content. It does not modify your original transcript files.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Requirements:
|
|
12
|
+
|
|
13
|
+
- Node.js 22+
|
|
14
|
+
- macOS or Linux
|
|
15
|
+
- OpenAI Codex session history in `~/.codex`
|
|
16
|
+
|
|
17
|
+
Install from npm:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @kyleparrott/where-was-i
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or run from source:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
git clone https://github.com/kyleparrott/where-was-i.git
|
|
27
|
+
cd where-was-i
|
|
28
|
+
npm install
|
|
29
|
+
npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
From source, replace `wwi` with `npm run cli --` in the examples below.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
wwi index --recent 100
|
|
38
|
+
wwi search "auth refactor" --group
|
|
39
|
+
wwi web --open
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`wwi index --recent 100` indexes the 100 most recently changed Codex session files. Use `wwi index` to index everything, or `wwi index --days 7` for a time window.
|
|
43
|
+
|
|
44
|
+
Search results include session IDs, message IDs, previews, source line locators, `codex://threads/<conversationId>` links, and copy-paste open commands.
|
|
45
|
+
|
|
46
|
+
Read more context from a hit:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
wwi open <message-id>
|
|
50
|
+
wwi context --message-id <message-id>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If Where Was I cannot find your Codex sessions or config, run `wwi doctor`.
|
|
54
|
+
|
|
55
|
+
## Web UI
|
|
56
|
+
|
|
57
|
+
Start the local web UI:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
wwi web --open
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The web UI binds to `127.0.0.1:8765` by default. Use `--port <number>` if that port is busy.
|
|
64
|
+
|
|
65
|
+
It includes:
|
|
66
|
+
|
|
67
|
+
- a recent-thread homepage
|
|
68
|
+
- grouped search results
|
|
69
|
+
- session detail pages with message context
|
|
70
|
+
- `Open in Codex` links for found threads
|
|
71
|
+
- buttons to refresh the index and regenerate configured embeddings with progress
|
|
72
|
+
- a settings page that edits the resolved JSON config file directly
|
|
73
|
+
|
|
74
|
+
The screenshot above uses synthetic demo sessions, not real transcript data.
|
|
75
|
+
|
|
76
|
+
## MCP
|
|
77
|
+
|
|
78
|
+
Point your MCP client at:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
where-was-i-mcp
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Example MCP config:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"mcpServers": {
|
|
89
|
+
"where-was-i": {
|
|
90
|
+
"command": "where-was-i-mcp"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
A good agent flow is:
|
|
97
|
+
|
|
98
|
+
1. `agent_session_status`
|
|
99
|
+
2. `index_agent_sessions` if the lexical index needs a refresh
|
|
100
|
+
3. `search_agent_sessions` with the user's clue
|
|
101
|
+
4. `read_agent_message_context` or `resolve_agent_session_message` for follow-up
|
|
102
|
+
|
|
103
|
+
`search_agent_sessions` defaults to `mode: "auto"`, which uses hybrid search when semantic vectors are usable and full-text search otherwise.
|
|
104
|
+
|
|
105
|
+
This repo does not currently ship a Codex plugin or standalone skill. The MCP server is the integration point today; a small Codex skill or plugin could later package this workflow so agents know when and how to use it.
|
|
106
|
+
|
|
107
|
+
## Future Direction
|
|
108
|
+
|
|
109
|
+
Where Was I is Codex-first today, but the core index is intentionally shaped around normalized sessions, messages, and chunks. Future adapters could add support for Claude Code or other local coding-agent transcript formats without changing the CLI, web UI, or MCP search surfaces.
|
|
110
|
+
|
|
111
|
+
Other likely follow-up areas:
|
|
112
|
+
|
|
113
|
+
- a small Codex skill or plugin that teaches agents when to use the MCP server
|
|
114
|
+
- better stale-index and stale-embedding indicators for large histories
|
|
115
|
+
- more scoped semantic indexing controls for slow local embedding providers
|
|
116
|
+
|
|
117
|
+
## Semantic Search
|
|
118
|
+
|
|
119
|
+
Full-text search stays local and needs no model. Semantic indexing sends canonical user and assistant message text to your configured embedding provider.
|
|
120
|
+
|
|
121
|
+
Local provider example:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
WHERE_WAS_I_EMBEDDING_BASE_URL=http://localhost:1234/v1
|
|
125
|
+
WHERE_WAS_I_EMBEDDING_MODEL=<your-local-embedding-model>
|
|
126
|
+
|
|
127
|
+
wwi index --semantic
|
|
128
|
+
wwi search "login problem with a joke" --mode hybrid --group
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
You can also regenerate configured embeddings from the web UI.
|
|
132
|
+
|
|
133
|
+
Cloud provider example:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
WHERE_WAS_I_EMBEDDING_BASE_URL=https://api.openai.com/v1
|
|
137
|
+
WHERE_WAS_I_EMBEDDING_MODEL=<embedding-model>
|
|
138
|
+
WHERE_WAS_I_EMBEDDING_API_KEY=...
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Changing embedding models requires clearing derived vectors:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
wwi embeddings clear --yes
|
|
145
|
+
wwi index --semantic
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Use `--semantic-max-chunks <count>` to limit how many missing chunks are embedded in one run.
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
Create or inspect config:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
wwi config init
|
|
156
|
+
wwi config show
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Default paths:
|
|
160
|
+
|
|
161
|
+
- Index: `~/.where-was-i/index.sqlite`
|
|
162
|
+
- Config: `~/.where-was-i/config.json`
|
|
163
|
+
- Codex home: `~/.codex`
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
5
|
+
import { defaultConfigPath, defaultConfigTemplate, loadWhereWasIConfig, mergeEmbeddingConfig } from "./core/config.js";
|
|
6
|
+
import { runDoctor } from "./core/doctor.js";
|
|
7
|
+
import { EmbeddingProviderUnavailableError, OpenAICompatibleEmbeddingProvider, isEmbeddingProviderConfigured } from "./core/embeddings.js";
|
|
8
|
+
import { indexCodexSessions } from "./core/indexer.js";
|
|
9
|
+
import { expandHome } from "./core/paths.js";
|
|
10
|
+
import { resetIndexFiles } from "./core/reset.js";
|
|
11
|
+
import { groupSearchResultsBySession, indexStats, readMessageContext, readSession, readTurn, resolveMessageLocator, searchSessions } from "./core/search.js";
|
|
12
|
+
import { clearSemanticEmbeddings, indexSemanticChunks, semanticFreshness } from "./core/semantic.js";
|
|
13
|
+
import { startWebServer } from "./web.js";
|
|
14
|
+
const program = new Command();
|
|
15
|
+
program
|
|
16
|
+
.name("where-was-i")
|
|
17
|
+
.description("Local-first search for coding-agent sessions you almost remember")
|
|
18
|
+
.option("--config <path>", "Config file path")
|
|
19
|
+
.option("--db <path>", "SQLite index path");
|
|
20
|
+
const configCommand = program.command("config").description("Inspect or initialize where-was-i configuration");
|
|
21
|
+
const embeddingsCommand = program.command("embeddings").description("Manage derived semantic embedding vectors");
|
|
22
|
+
configCommand
|
|
23
|
+
.command("show")
|
|
24
|
+
.description("Show the resolved configuration")
|
|
25
|
+
.action(() => {
|
|
26
|
+
const config = resolvedConfig();
|
|
27
|
+
console.log(JSON.stringify(redactConfig(config), null, 2));
|
|
28
|
+
});
|
|
29
|
+
configCommand
|
|
30
|
+
.command("init")
|
|
31
|
+
.description("Create a starter config file")
|
|
32
|
+
.option("--force", "Overwrite an existing config file", false)
|
|
33
|
+
.action((opts) => {
|
|
34
|
+
const root = program.opts();
|
|
35
|
+
const configPath = path.resolve(expandHome(root.config ?? defaultConfigPath()));
|
|
36
|
+
if (fs.existsSync(configPath) && !opts.force) {
|
|
37
|
+
throw new Error(`Config file already exists: ${configPath}`);
|
|
38
|
+
}
|
|
39
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
40
|
+
fs.writeFileSync(configPath, `${JSON.stringify(defaultConfigTemplate(), null, 2)}\n`, { mode: 0o600 });
|
|
41
|
+
fs.chmodSync(configPath, 0o600);
|
|
42
|
+
console.log(configPath);
|
|
43
|
+
});
|
|
44
|
+
embeddingsCommand
|
|
45
|
+
.command("clear")
|
|
46
|
+
.description("Delete all semantic embedding vectors and provider metadata")
|
|
47
|
+
.option("--yes", "Confirm deletion", false)
|
|
48
|
+
.option("--json", "Emit JSON", false)
|
|
49
|
+
.action((opts) => {
|
|
50
|
+
if (!opts.yes) {
|
|
51
|
+
throw new Error("Refusing to clear embeddings without --yes. This deletes derived semantic vectors but keeps the lexical index.");
|
|
52
|
+
}
|
|
53
|
+
const config = resolvedConfig();
|
|
54
|
+
const summary = clearSemanticEmbeddings(resolvedDbPath(config));
|
|
55
|
+
if (opts.json) {
|
|
56
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log(`Deleted ${summary.vectorsDeleted} semantic vectors and ${summary.providersDeleted} embedding provider records.`);
|
|
60
|
+
});
|
|
61
|
+
program
|
|
62
|
+
.command("reset")
|
|
63
|
+
.description("Delete the entire local index, including lexical and semantic stores")
|
|
64
|
+
.option("--yes", "Confirm deletion", false)
|
|
65
|
+
.option("--json", "Emit JSON", false)
|
|
66
|
+
.action((opts) => {
|
|
67
|
+
if (!opts.yes) {
|
|
68
|
+
throw new Error("Refusing to reset without --yes. This deletes the local index database but does not touch Codex transcripts.");
|
|
69
|
+
}
|
|
70
|
+
const config = resolvedConfig();
|
|
71
|
+
const summary = resetIndexFiles(resolvedDbPath(config));
|
|
72
|
+
if (opts.json) {
|
|
73
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
console.log(`Deleted ${summary.deleted.length} index file(s). Codex transcripts were not modified.`);
|
|
77
|
+
});
|
|
78
|
+
program
|
|
79
|
+
.command("index")
|
|
80
|
+
.description("Index Codex session history")
|
|
81
|
+
.option("--codex-home <path>", "Codex data directory")
|
|
82
|
+
.option("--include-archived", "Include archived Codex sessions", false)
|
|
83
|
+
.option("--days <number>", "Only index files changed in the last N days", parsePositiveIntegerOption("--days"))
|
|
84
|
+
.option("--recent <number>", "Only index the N most recently changed session files", parsePositiveIntegerOption("--recent"))
|
|
85
|
+
.option("--session <id...>", "Only index specific session IDs")
|
|
86
|
+
.option("--force", "Reindex files even when size and mtime are unchanged", false)
|
|
87
|
+
.option("--include-tools", "Index tool calls and tool output", false)
|
|
88
|
+
.option("--semantic", "Also refresh semantic embeddings", false)
|
|
89
|
+
.option("--semantic-max-chunks <number>", "Maximum semantic chunks to embed this run", parsePositiveIntegerOption("--semantic-max-chunks"))
|
|
90
|
+
.option("--semantic-session <id...>", "Only embed chunks for specific session IDs")
|
|
91
|
+
.option("--no-progress", "Disable semantic indexing progress output")
|
|
92
|
+
.option("--embedding-base-url <url>", "OpenAI-compatible embedding base URL")
|
|
93
|
+
.option("--embedding-model <model>", "Embedding model name")
|
|
94
|
+
.option("--embedding-timeout-ms <number>", "Embedding request timeout in milliseconds", parsePositiveIntegerOption("--embedding-timeout-ms"))
|
|
95
|
+
.action(async (opts) => {
|
|
96
|
+
const config = resolvedConfig();
|
|
97
|
+
const dbPath = resolvedDbPath(config);
|
|
98
|
+
const summary = indexCodexSessions({
|
|
99
|
+
dbPath,
|
|
100
|
+
codexHome: expandHome(opts.codexHome ?? config.codexHome),
|
|
101
|
+
includeArchived: opts.includeArchived,
|
|
102
|
+
days: opts.days,
|
|
103
|
+
recent: opts.recent,
|
|
104
|
+
force: opts.force,
|
|
105
|
+
includeTools: opts.includeTools,
|
|
106
|
+
sessionIds: opts.session
|
|
107
|
+
});
|
|
108
|
+
let semantic = null;
|
|
109
|
+
if (opts.semantic) {
|
|
110
|
+
try {
|
|
111
|
+
semantic = await indexSemanticChunks({
|
|
112
|
+
dbPath,
|
|
113
|
+
embedding: mergeEmbeddingConfig(config, {
|
|
114
|
+
baseUrl: opts.embeddingBaseUrl,
|
|
115
|
+
model: opts.embeddingModel,
|
|
116
|
+
timeoutMs: opts.embeddingTimeoutMs
|
|
117
|
+
}),
|
|
118
|
+
maxChunks: opts.semanticMaxChunks,
|
|
119
|
+
sessionIds: opts.semanticSession,
|
|
120
|
+
onProgress: opts.progress ? createSemanticProgressReporter() : undefined
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
handleFriendlyError(error);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
console.log(JSON.stringify({ lexical: summary, semantic }, null, 2));
|
|
129
|
+
});
|
|
130
|
+
program
|
|
131
|
+
.command("search")
|
|
132
|
+
.description("Full-text search indexed sessions")
|
|
133
|
+
.argument("<query>", "Search query")
|
|
134
|
+
.option("-l, --limit <number>", "Maximum results", parsePositiveIntegerOption("--limit"), 10)
|
|
135
|
+
.option("--content", "Include full chunk text in results", false)
|
|
136
|
+
.option("--mode <mode>", "Search mode: fts, semantic, or hybrid", "fts")
|
|
137
|
+
.option("--embedding-base-url <url>", "OpenAI-compatible embedding base URL")
|
|
138
|
+
.option("--embedding-model <model>", "Embedding model name")
|
|
139
|
+
.option("--embedding-timeout-ms <number>", "Embedding request timeout in milliseconds", parsePositiveIntegerOption("--embedding-timeout-ms"))
|
|
140
|
+
.option("--group", "Group hits by session", false)
|
|
141
|
+
.option("--json", "Emit JSON", false)
|
|
142
|
+
.action(async (query, opts) => {
|
|
143
|
+
const config = resolvedConfig();
|
|
144
|
+
let results;
|
|
145
|
+
try {
|
|
146
|
+
results = await searchSessions({
|
|
147
|
+
dbPath: resolvedDbPath(config),
|
|
148
|
+
query,
|
|
149
|
+
limit: opts.limit,
|
|
150
|
+
includeText: opts.content,
|
|
151
|
+
mode: parseSearchMode(opts.mode),
|
|
152
|
+
embedding: mergeEmbeddingConfig(config, {
|
|
153
|
+
baseUrl: opts.embeddingBaseUrl,
|
|
154
|
+
model: opts.embeddingModel,
|
|
155
|
+
timeoutMs: opts.embeddingTimeoutMs
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
handleFriendlyError(error);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const output = opts.group ? groupSearchResultsBySession(results) : results;
|
|
164
|
+
if (opts.json) {
|
|
165
|
+
console.log(JSON.stringify(output, null, 2));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (opts.group) {
|
|
169
|
+
for (const result of groupSearchResultsBySession(results)) {
|
|
170
|
+
const sources = result.match.sources.join("+");
|
|
171
|
+
console.log(`${result.session.id} ${result.bestMessage.timestamp ?? "unknown"} score=${result.score.toFixed(3)} match=${sources}`);
|
|
172
|
+
console.log(` ${result.bestMessage.preview}`);
|
|
173
|
+
console.log(` source ${result.bestMessage.links.source}`);
|
|
174
|
+
console.log(` codex ${result.bestMessage.links.codex ?? "(unavailable)"}`);
|
|
175
|
+
console.log(` command ${result.bestMessage.links.openCommand ?? "(unavailable)"}`);
|
|
176
|
+
for (const hit of result.hits) {
|
|
177
|
+
console.log(` - ${hit.role} ${hit.messageId} [${hit.match.sources.join("+")}]: ${hit.preview}`);
|
|
178
|
+
}
|
|
179
|
+
console.log("");
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
for (const result of results) {
|
|
184
|
+
console.log(`${result.sessionId} ${result.role} ${result.timestamp ?? "unknown"}`);
|
|
185
|
+
console.log(` ${result.title ?? "(untitled)"}`);
|
|
186
|
+
console.log(` ${result.snippet}`);
|
|
187
|
+
console.log("");
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
program
|
|
191
|
+
.command("open")
|
|
192
|
+
.description("Resolve a message ID to Codex/source locators")
|
|
193
|
+
.argument("<message-id>", "Message ID")
|
|
194
|
+
.option("--json", "Emit JSON", false)
|
|
195
|
+
.action((messageId, opts) => {
|
|
196
|
+
const config = resolvedConfig();
|
|
197
|
+
const resolved = resolveMessageLocator(resolvedDbPath(config), messageId);
|
|
198
|
+
if (!resolved) {
|
|
199
|
+
throw new Error(`Message not found: ${messageId}`);
|
|
200
|
+
}
|
|
201
|
+
if (opts.json) {
|
|
202
|
+
console.log(JSON.stringify(resolved, null, 2));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
console.log(`${resolved.sessionId} ${resolved.role} ${resolved.timestamp ?? "unknown"}`);
|
|
206
|
+
console.log(` ${resolved.preview}`);
|
|
207
|
+
console.log(` source ${resolved.links.source}`);
|
|
208
|
+
console.log(` codex ${resolved.links.codex ?? "(unavailable)"}`);
|
|
209
|
+
console.log(` command ${resolved.links.openCommand ?? "(unavailable)"}`);
|
|
210
|
+
});
|
|
211
|
+
program
|
|
212
|
+
.command("show")
|
|
213
|
+
.description("Show indexed messages for a session")
|
|
214
|
+
.argument("<session-id>", "Session ID")
|
|
215
|
+
.option("-l, --limit <number>", "Maximum messages", parsePositiveIntegerOption("--limit"), 200)
|
|
216
|
+
.action((sessionId, opts) => {
|
|
217
|
+
const config = resolvedConfig();
|
|
218
|
+
const messages = readSession(resolvedDbPath(config), sessionId, opts.limit);
|
|
219
|
+
for (const message of messages) {
|
|
220
|
+
console.log(`[${message.timestamp ?? "unknown"}] ${message.role.toUpperCase()} ${message.kind}`);
|
|
221
|
+
console.log(message.text);
|
|
222
|
+
console.log("");
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
program
|
|
226
|
+
.command("context")
|
|
227
|
+
.description("Show messages around a message hit or all messages in a turn")
|
|
228
|
+
.option("--message-id <id>", "Message ID to center context around")
|
|
229
|
+
.option("--turn-id <id>", "Turn ID to read")
|
|
230
|
+
.option("--before <number>", "Messages before a message ID", parseNonNegativeIntegerOption("--before"), 2)
|
|
231
|
+
.option("--after <number>", "Messages after a message ID", parseNonNegativeIntegerOption("--after"), 2)
|
|
232
|
+
.option("-l, --limit <number>", "Maximum turn messages", parsePositiveIntegerOption("--limit"), 50)
|
|
233
|
+
.option("--json", "Emit JSON", false)
|
|
234
|
+
.action((opts) => {
|
|
235
|
+
const config = resolvedConfig();
|
|
236
|
+
if (!opts.messageId && !opts.turnId) {
|
|
237
|
+
throw new Error("Provide --message-id or --turn-id.");
|
|
238
|
+
}
|
|
239
|
+
if (opts.messageId && opts.turnId) {
|
|
240
|
+
throw new Error("Provide only one of --message-id or --turn-id.");
|
|
241
|
+
}
|
|
242
|
+
const result = opts.messageId
|
|
243
|
+
? readMessageContext(resolvedDbPath(config), opts.messageId, opts.before, opts.after)
|
|
244
|
+
: readTurn(resolvedDbPath(config), opts.turnId, opts.limit);
|
|
245
|
+
if (opts.json) {
|
|
246
|
+
console.log(JSON.stringify(result, null, 2));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(result)) {
|
|
250
|
+
for (const message of result) {
|
|
251
|
+
console.log(`[${message.timestamp ?? "unknown"}] ${message.role.toUpperCase()} ${message.id}`);
|
|
252
|
+
console.log(message.text);
|
|
253
|
+
console.log("");
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
for (const message of [...result.before, ...(result.target ? [result.target] : []), ...result.after]) {
|
|
258
|
+
console.log(`[${message.timestamp ?? "unknown"}] ${message.role.toUpperCase()} ${message.id}`);
|
|
259
|
+
console.log(message.text);
|
|
260
|
+
console.log("");
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
program
|
|
264
|
+
.command("status")
|
|
265
|
+
.description("Show index status")
|
|
266
|
+
.action(async () => {
|
|
267
|
+
const config = resolvedConfig();
|
|
268
|
+
const dbPath = resolvedDbPath(config);
|
|
269
|
+
console.log(JSON.stringify({
|
|
270
|
+
...indexStats(dbPath),
|
|
271
|
+
semantic: await semanticFreshness({
|
|
272
|
+
dbPath,
|
|
273
|
+
embedding: mergeEmbeddingConfig(config),
|
|
274
|
+
probeProvider: false
|
|
275
|
+
})
|
|
276
|
+
}, null, 2));
|
|
277
|
+
});
|
|
278
|
+
program
|
|
279
|
+
.command("doctor")
|
|
280
|
+
.description("Check Codex paths, index health, vectors, and embedding provider status")
|
|
281
|
+
.option("--codex-home <path>", "Codex data directory")
|
|
282
|
+
.option("--embedding-base-url <url>", "OpenAI-compatible embedding base URL")
|
|
283
|
+
.option("--embedding-model <model>", "Embedding model name")
|
|
284
|
+
.option("--embedding-timeout-ms <number>", "Embedding request timeout in milliseconds", parsePositiveIntegerOption("--embedding-timeout-ms"))
|
|
285
|
+
.action(async (opts) => {
|
|
286
|
+
const config = resolvedConfig();
|
|
287
|
+
const report = await runDoctor({
|
|
288
|
+
dbPath: resolvedDbPath(config),
|
|
289
|
+
codexHome: expandHome(opts.codexHome ?? config.codexHome),
|
|
290
|
+
embedding: mergeEmbeddingConfig(config, {
|
|
291
|
+
baseUrl: opts.embeddingBaseUrl,
|
|
292
|
+
model: opts.embeddingModel,
|
|
293
|
+
timeoutMs: opts.embeddingTimeoutMs
|
|
294
|
+
})
|
|
295
|
+
});
|
|
296
|
+
console.log(JSON.stringify(report, null, 2));
|
|
297
|
+
if (!report.ok) {
|
|
298
|
+
process.exitCode = 1;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
program
|
|
302
|
+
.command("web")
|
|
303
|
+
.description("Start the local Where Was I web UI")
|
|
304
|
+
.option("-p, --port <number>", "Port to bind", parsePortOption("--port"), 8765)
|
|
305
|
+
.option("--open", "Open the web UI in your default browser", false)
|
|
306
|
+
.action(async (opts) => {
|
|
307
|
+
const root = program.opts();
|
|
308
|
+
const running = await startWebServer({
|
|
309
|
+
configPath: root.config,
|
|
310
|
+
dbPath: root.db,
|
|
311
|
+
port: opts.port,
|
|
312
|
+
openBrowser: opts.open
|
|
313
|
+
});
|
|
314
|
+
console.log(`Where Was I web UI: ${running.url}`);
|
|
315
|
+
console.log("Press Ctrl-C to stop.");
|
|
316
|
+
process.on("SIGINT", () => {
|
|
317
|
+
void running.close().finally(() => process.exit(0));
|
|
318
|
+
});
|
|
319
|
+
process.on("SIGTERM", () => {
|
|
320
|
+
void running.close().finally(() => process.exit(0));
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
program.parse();
|
|
324
|
+
function parseSearchMode(value) {
|
|
325
|
+
if (value === "fts" || value === "semantic" || value === "hybrid") {
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
throw new Error('Search mode must be "fts", "semantic", or "hybrid".');
|
|
329
|
+
}
|
|
330
|
+
function parsePositiveIntegerOption(optionName) {
|
|
331
|
+
return (value) => parseIntegerOption(value, optionName, 1);
|
|
332
|
+
}
|
|
333
|
+
function parseNonNegativeIntegerOption(optionName) {
|
|
334
|
+
return (value) => parseIntegerOption(value, optionName, 0);
|
|
335
|
+
}
|
|
336
|
+
function parsePortOption(optionName) {
|
|
337
|
+
return (value) => parseIntegerOption(value, optionName, 1, 65535);
|
|
338
|
+
}
|
|
339
|
+
function parseIntegerOption(value, optionName, minimum, maximum = Number.MAX_SAFE_INTEGER) {
|
|
340
|
+
const parsed = Number(value);
|
|
341
|
+
if (!Number.isInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
342
|
+
const description = minimum === 0 ? "a non-negative integer" : "a positive integer";
|
|
343
|
+
throw new InvalidArgumentError(`${optionName} must be ${description}.`);
|
|
344
|
+
}
|
|
345
|
+
return parsed;
|
|
346
|
+
}
|
|
347
|
+
function resolvedConfig() {
|
|
348
|
+
const root = program.opts();
|
|
349
|
+
return loadWhereWasIConfig(root.config);
|
|
350
|
+
}
|
|
351
|
+
function resolvedDbPath(config) {
|
|
352
|
+
const root = program.opts();
|
|
353
|
+
return expandHome(root.db ?? config.dbPath);
|
|
354
|
+
}
|
|
355
|
+
function redactConfig(config) {
|
|
356
|
+
const embedding = new OpenAICompatibleEmbeddingProvider(config.semantic.embedding).config;
|
|
357
|
+
const embeddingForDisplay = isEmbeddingProviderConfigured(embedding)
|
|
358
|
+
? embedding
|
|
359
|
+
: { ...embedding, id: undefined, baseUrl: undefined, model: undefined };
|
|
360
|
+
return {
|
|
361
|
+
...config,
|
|
362
|
+
semantic: {
|
|
363
|
+
...config.semantic,
|
|
364
|
+
embedding: {
|
|
365
|
+
...embeddingForDisplay,
|
|
366
|
+
apiKey: embedding.apiKey ? "[redacted]" : undefined
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function handleFriendlyError(error) {
|
|
372
|
+
if (error instanceof EmbeddingProviderUnavailableError || isRecoverableSemanticError(error)) {
|
|
373
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
374
|
+
process.exitCode = 1;
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
function isRecoverableSemanticError(error) {
|
|
380
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
381
|
+
return (message.includes("Existing vector store dimensions") ||
|
|
382
|
+
message.includes("Existing vector_chunks table") ||
|
|
383
|
+
message.includes("stored vector(s) for a different embedding provider"));
|
|
384
|
+
}
|
|
385
|
+
function createSemanticProgressReporter() {
|
|
386
|
+
const animate = process.stderr.isTTY;
|
|
387
|
+
let lastLength = 0;
|
|
388
|
+
return (progress) => {
|
|
389
|
+
const line = formatSemanticProgress(progress);
|
|
390
|
+
if (!line) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (animate) {
|
|
394
|
+
const padding = " ".repeat(Math.max(0, lastLength - line.length));
|
|
395
|
+
process.stderr.write(`\r${line}${padding}`);
|
|
396
|
+
lastLength = line.length;
|
|
397
|
+
if (progress.phase === "complete" || progress.phase === "unavailable") {
|
|
398
|
+
process.stderr.write("\n");
|
|
399
|
+
lastLength = 0;
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
process.stderr.write(`${line}\n`);
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function formatSemanticProgress(progress) {
|
|
407
|
+
if (progress.phase === "probing") {
|
|
408
|
+
return `Preparing semantic embeddings with ${progress.model}...`;
|
|
409
|
+
}
|
|
410
|
+
if (progress.phase === "unavailable") {
|
|
411
|
+
return `Semantic embeddings unavailable: ${progress.failed ?? "embedding provider failed"}`;
|
|
412
|
+
}
|
|
413
|
+
const total = progress.total ?? 0;
|
|
414
|
+
const percent = total > 0 ? Math.floor((progress.indexed / total) * 100) : 100;
|
|
415
|
+
const base = `Embedding chunks ${progress.indexed}/${total} (${percent}%)`;
|
|
416
|
+
if (progress.phase === "batch" && progress.batchSize) {
|
|
417
|
+
return `${base} - requesting ${progress.batchSize}`;
|
|
418
|
+
}
|
|
419
|
+
if (progress.phase === "complete") {
|
|
420
|
+
return `Semantic embeddings complete: ${progress.indexed}/${total} chunks`;
|
|
421
|
+
}
|
|
422
|
+
return base;
|
|
423
|
+
}
|