mirror of
https://github.com/mksglu/context-mode.git
synced 2026-11-23 13:11:14 +08:00
fix: ctx_search treats a blank source as absent (#1354)
The #1354 payload holds source:"" next to offset:0/after:0. With the cursors fixed, the blank source still filtered on a source named "" and the search found nothing. A blank or whitespace-only source now counts as absent, the same rule as ctx_resume's blank session (D-1353-RESUME-BLANK-1). ADR-0009 §8.1 rule 6 (line 168) now matches §8.4: a non-zero cursor conflicts, 0 is the first page, and a blank source names no source. The D-R54-SEARCH-ZERO-1 row cites line 168 and the blank-source reason. Profile, handler, median of 50 runs, 20 indexed rows, before -> after (ms): bare call 1.830 -> 1.943 blank source 1.774 -> 1.851 named source 1.722 -> 1.817 (3 runs after stay in 1.7-2.1 ms: noise) Tests: 0009 + 0007 157/157; GP5 + GP6 e2e 45/45; tsc clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3648b8087
commit
548c305516
3 files changed
+7
-2
No files matched your search
@@ -165,7 +165,7 @@ Rules, in order:
|
||||
3. **Fetch.** Fetch up to `limit` rows from each source on its own (≤ 3·limit candidates). Never clip one source before the merge.
|
||||
4. **Normalize.** Convert every timestamp to ISO-8601 UTC `YYYY-MM-DDTHH:MM:SS.sssZ` before any compare. Fixes v1's `9de1c658` bug (SQLite and ISO shapes mixed).
|
||||
5. **Order.** Ascending by normalized timestamp (oldest first). Ties break by `seq` ascending. Rows with no `seq` (auto-memory files) sort after journal rows at the same timestamp, then by path ascending. Same input, same order.
|
||||
6. **Page.** `after` is an epoch-ms timestamp cursor (M18), not `seq`: drop rows with normalized timestamp ≤ `after`, then cut to `limit` — except a page never ends inside a group of rows sharing one timestamp; it extends to the end of that group so no row is skipped between pages. Reply ends with `more: ctx_search({…, sort:"timeline", after:<ms>})` when rows remain (M22). `offset` with `sort:"timeline"` returns `isError` `INVALID_ARGS`; `after` with `"relevance"` returns the same error.
|
||||
6. **Page.** `after` is an epoch-ms timestamp cursor (M18), not `seq`: drop rows with normalized timestamp ≤ `after`, then cut to `limit` — except a page never ends inside a group of rows sharing one timestamp; it extends to the end of that group so no row is skipped between pages. Reply ends with `more: ctx_search({…, sort:"timeline", after:<ms>})` when rows remain (M22). A non-zero `offset` with `sort:"timeline"` returns `isError` `INVALID_ARGS`; a non-zero `after` with `"relevance"` returns the same error. `0` is the first page of either cursor and is accepted, and a blank `source` names no source (#1354, D-R54-SEARCH-ZERO-1).
|
||||
7. **Empty.** Empty `queries` is allowed in timeline mode; it returns the newest page in scope.
|
||||
8. **Output.** Each line: `[<iso time>] <source> #<seq> <first line of row>`, cut by `capBytes(text, OUTPUT_CAP)`.
|
||||
|
||||
|
||||
@@ -683,5 +683,5 @@ One row per deviation found while implementing or verifying against the design.
|
||||
| 2026-11-08 | `src/core/ops/doctor-config.ts` (`checkHostConfig` host arg, `isAntigravityHost`), `src/core/tools/doctor.ts` (D3 call), `src/core/contracts/constants.ts` (`ANTIGRAVITY_*`, `D3_ANTIGRAVITY_DETAIL`), `tests/0010-doctor-upgrade.test.mjs` (D-1340-AGY-D3-1), `tickets/host-research/antigravity.md` (lead worktree) | #1340 (nahiarhd, Antigravity agent): "D3 host config FAIL: wrong: MCP entry, hook entries ... The suggested fix `context-mode setup --agents gemini` would write Gemini CLI entries that are useless here and risk double registration." What does D3 say when the gemini-mode server runs inside Google Antigravity (not a supported host)? | When clientInfo.name is antigravity / antigravity-cli / antigravity-client / agy, or the bundle sits under `~/.gemini/{config,antigravity,antigravity-cli,antigravity-ide}/plugins/`, D3 is one WARN row: "Antigravity is not a supported host yet; the MCP server runs (see D6); hooks are not checked there; supported agents: docs/install/README.md", with no fix command. No Antigravity adapter added. Gemini CLI keeps the real D3 verdict. | The reporter's D5, D6, D8 passed and every ctx_* tool worked; D3 read `~/.gemini/settings.json` and `extensions/context-mode`, which Antigravity never uses, so FAIL and `gemini extensions install` were false. Doctor now tells the truth. Profiling (median of 50, D3 call): Antigravity path 0.064 ms to 0.006 ms; Gemini CLI path 0.059 ms to 0.074 ms (noise, one string compare added). |
|
||||
| 2026-11-08 | `src/core/contracts/constants.ts` (`UNSUPPORTED_HOSTS`, `UNSUPPORTED_HOST_LINE`, `UNSUPPORTED_SETUP_LINE`, `SUPPORTED_AGENTS_LINE`; replaces the one-off `ANTIGRAVITY_*` constants), `src/core/ops/unsupported-host.ts`, `src/core/tools/doctor.ts` (D3 and D5 rows), `src/core/ops/doctor-issue.ts` (title and summary), `src/cli/args.ts` (`setup --agents` and `--print`), `src/cli/commands.ts` (`context-mode doctor`), tests 0010 and 0019 (D-UNSUPPORTED-HOSTS-1) | Owner: "Sadece Antigravity icin degil desteklemediklerimize desteklemiyoruz diye desin." One list of known unsupported hosts (Antigravity, Cursor, OMP, OpenClaw, Kimi, Kilo, Zed, JetBrains Copilot) with signals from v1.0.169. Doctor D3 and D5 say "<Host> is not a supported host today. The MCP server runs here; hooks are not checked. Supported agents: ..." (WARN, no fix command). `setup --agents <name>` and `--print` give the same line, exit 2, write nothing. Unknown names keep the usage error and now list the supported agents. | A host that sends a clientInfo of a supported agent is never reclassified by an inherited env var. Profiling (median of 20, runDoctorChecks): 0.39-0.45 ms before, 0.40-0.42 ms after (noise). |
|
||||
| 2026-11-11 | `src/entries/pi.ts` (tool_result, `excludedTools`), `src/adapters/pi.ts` (readResult `keep`), `docs/install/pi.md`, `tests/0020-plugins.test.mjs`, `tests/0020-adapters.test.mjs`, `e2e/cases/GP3-hooks.e2e.mjs` (D-R54-PI-META-1, amends D-M5-P1-1) | #1352 (xz-dev, hoho51): a large Pi extension result (fetch_content, session_search) lost its continuation metadata: the replace sent `details: {text}` and no `structuredContent`, and Pi >= 1.4 drops `structuredContent` on a content-only patch (types.d.ts ToolResultEventResult, runner.js emitToolResult). ADR-0016:48 Pi row says "set `content` AND `structuredContent` together post-call"; 12-plugins §3.5 says the same. Archaeology: 526e1c57 (M5-P1) mapped structuredContent to `details` because Pi 0.73.1 had no structuredContent; Pi 1.4/1.5 added it and documents `details` as extension state, so that premise is gone. v1.0.169 returned nothing from tool_result. No per-tool opt-out existed. | A case-C replace returns `{content}` plus the event's `structuredContent` when it has one, and no `details` key (Pi keeps the tool's value). `contextMode.excludeTools` in Pi settings (exact names, read through optional `pi.getSettings` per call; missing, malformed, absent API or a throw means the default) sends `keep: true`; the pi adapter copies it to `result.keep` and dispatch returns ALLOW at the D-M2-MCP-1 point, journal rows still written. Profile (23 KB result, median of 50): replace 7.14-8.02 ms before, 7.44-7.64 ms after; excluded tool 0.04 ms. | ADR-0016:48 names both fields; NO-LOSSY-CUT keeps a replace lossless, so a user opt-out breaks no rule. Bash and Read on Pi stay compressed by default. |
|
||||
| 2026-11-11 | `src/core/tools/search.ts` (handler cross-mode guard), `docs/architecture/adr/0009-compaction-and-memory.md` (§8.4 line 215), `docs/architecture/modules/00-architecture.md` (`INVALID_ARGS` row), `tests/0009-compaction-memory.test.mjs`, `tests/0007-mcp-server.test.mjs`, `e2e/cases/GP5-index-search.e2e.mjs` | #1354: Pi with a whole-schema model sends `offset:0, after:0` on every `ctx_search`; both sort modes then return `Invalid argument offset/after`, so the tool never answers. Repro is the same on npm 2.1.7 and main f681b458. (D-R54-SEARCH-ZERO-1) | Only a non-zero cursor pages: the guard checks `(input.offset ?? 0) !== 0` with timeline and `(input.after ?? 0) !== 0` with relevance. `0` is the first page of either cursor and answers as if the field were absent. Every non-zero conflict keeps its exact error line. The zod schema stays as it is. | ADR-0009:168 and :215, DECISIONS-r9 M23 (with M18, M22). Archaeology: `git log -S` and `git blame` on the guard show only dfac356e (2026-10-17, M2-T9); the rule came from a spec review to tell a model that pages with the wrong cursor to switch. Clients that fill every optional field with its zero value were not part of that decision, and v1.0.169 had no cross-mode check. Profile (median of 50, handler, 20 rows): timeline 0.478 -> 0.467 ms, relevance 0.742 -> 0.752 ms (noise). |
|
||||
| 2026-11-11 | `src/core/tools/search.ts` (handler cross-mode guard), `docs/architecture/adr/0009-compaction-and-memory.md` (§8.1 rule 6 line 168, §8.4 line 215), `docs/architecture/modules/00-architecture.md` (`INVALID_ARGS` row), `tests/0009-compaction-memory.test.mjs`, `tests/0007-mcp-server.test.mjs`, `e2e/cases/GP5-index-search.e2e.mjs` | #1354: Pi with a whole-schema model sends `offset:0, after:0, source:""` on every `ctx_search`; both sort modes then return `Invalid argument offset/after`, so the tool never answers. With the cursors fixed, `source:""` still filters on a source named `""` and finds nothing. Repro is the same on npm 2.1.7 and main f681b458. (D-R54-SEARCH-ZERO-1) | Only a non-zero cursor pages: the guard checks `(input.offset ?? 0) !== 0` with timeline and `(input.after ?? 0) !== 0` with relevance. `0` is the first page of either cursor and answers as if the field were absent. Every non-zero conflict keeps its exact error line. A blank or whitespace-only `source` counts as absent (the same rule as D-1353-RESUME-BLANK-1). The zod schema stays as it is. | ADR-0009:168 and :215, DECISIONS-r9 M23 (with M18, M22). Archaeology: `git log -S` and `git blame` on the guard show only dfac356e (2026-10-17, M2-T9); the rule came from a spec review to tell a model that pages with the wrong cursor to switch. Clients that fill every optional field with its zero value were not part of that decision, and v1.0.169 had no cross-mode check. The `source === undefined` checks in search.ts date from the same spec and treat `""` as a name; the same whole-schema client fills it. Profile (median of 50, handler, 20 rows): timeline 0.478 -> 0.467 ms, relevance 0.742 -> 0.752 ms; blank source 1.774 -> 1.851 ms, bare call 1.830 -> 1.943 ms (3 runs after, 1.7-2.1 ms, noise). |
|
||||
| 2026-11-11 | `src/core/tools/resume.ts` (step 2 session resolve), `docs/architecture/modules/06-tools-session.md` (step 2), `tests/0009-compaction-memory.test.mjs`, `tests/0007-mcp-server.test.mjs`, `e2e/cases/GP6-journal-resume.e2e.mjs` | #1353: Pi with deepseek sends `session:""` for the optional field; `ctx_resume` then says "no session id" although the call comes from an active session. (D-1353-RESUME-BLANK-1) | A blank or whitespace-only `session` counts as absent and falls back to `ctx.sessionId`. A non-blank `session` behaves as before; an empty `ctx.sessionId` still gives `RESUME_NO_SESSION_LINE`. No schema change (`.min(1)` would turn the blank field into an error). | 06-tools-session.md:233 step 2 (`input.session ?? currentSessionIdFromMeta`). Archaeology: `git log -S "input.session ?? ctx.sessionId"` and `git blame` show only 0e3b3828 (2026-10-18, M4-S2), a literal copy of the spec; D-M4-arch-3 only moved the resolver to `ctx.sessionId`. v1 `currentAttribution()` used a truthy check, so v1 treated `""` as absent. Profile (median of 50): `{}` 0.515 -> 0.525 ms, `{seq}` 0.326 -> 0.317 ms (noise). Out of scope: `purge.ts:37` `session:""` deletes 0 rows; own lane. |
|
||||
@@ -385,6 +385,11 @@ async function handler(input: CtxSearchInput, ctx: ToolContext): Promise<ToolRep
|
||||
if (sort === "relevance" && (input.after ?? 0) !== 0) {
|
||||
return invalid("after", 'drop after, or pass sort:"timeline"');
|
||||
}
|
||||
// A blank source names no source: whole-schema clients send source:"" too (D-R54-SEARCH-ZERO-1, #1354).
|
||||
if (input.source !== undefined && input.source.trim() === "") {
|
||||
const { source: _blank, ...rest } = input;
|
||||
input = rest;
|
||||
}
|
||||
const scope: SearchScope = input.scope ?? "worktree";
|
||||
const db = await openDb(ctx.project, { readOnly: true });
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user