Skip to content

feat(analysis-view): share templated positions across manifest tools - #5664

Merged
morluto merged 10 commits into
morluto:mainfrom
earakely-scale:feat/manifest-item-write-templates
Oct 21, 2026
Merged

morluto merged 10 commits into
morluto:mainfrom
earakely-scale:feat/manifest-item-write-templates

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A capture session usually edits one scratch entity: it creates it, then updates and deletes it at a fixed path such as /api/v1/collections/0RZ576QZQA5KG. The environment manifest templates a segment only when sibling routes of the same method and segment count vary there. So those writes stay literal single-entity tools (patch_collections_0rz576qzqa5kg), even though the reads of the same collection were templated as /api/v1/collections/{collection_id}.

This PR adds an opt-in template rule, prefix-variance. It templates such a literal with the parameter another tool already uses at that position, so the write becomes patch_collections_by_collection_id on the read's exact template.

Part of #4933. Spec, plan, tasks and verification are in docs/specs/agent-environments/prefix-variance/.

Problem and expected behavior

A literal write tool addresses one entity that may not exist in any later state. Nothing can model its effect. The write-effects gate in #5600 reports these tools as no-state-target, and they were the largest group it could not serve.

With the rule listed in template_rules:

  • When it applies: a literal at position p is templated when another tool on the same origin has a parameter at p from one of the other opt-in rules, after the same preceding parts. The other tool can have any method and any segment count, so deeper routes such as …/collections/{collection_id}/books are covered too.

  • Which literals qualify:

    • one of the values any such tool observed at that position;
    • a literal that carries a digit and has the length and character classes (digits, lower case, upper case, each other character) of an observed value; or
    • when every observed value has one length of eight or more characters, as generated ids often do, a literal of that length using only their character classes, so an id that happens to hold no digit still qualifies. This clause was added after the end-to-end runs below.

    Empty literals, stop words and v1-style versions never qualify, and format-rule positions ({numeric}, …) are never shared.

  • Naming: the parameter takes the shared parameter's name (collection_id, uid, a pair's _namespace and _name) and is labelled prefix-variance.

  • Merging: tools whose routes now match merge, and a merged position keeps a tool's own rule when one templated it.

  • Segment limit: like the sibling rules, it compares routes of at most 32 segments and says so in a limitation.

Change and scope

  • Rule placement: environmentManifestRules.ts gains the pass. It runs last, so it can share every parameter the other rules produce.
  • Recorded rule: a prefix-variance parameter records the rule it shares (sharedRule), which both names it and keys it when routes are compared.
  • Supporting refactors:
    • tool naming moves to environmentManifestNames.ts, so the rules file stays under the length limit;
    • the three comparing passes share the 32-segment split;
    • the segment-limited rules are listed once.
  • Not included:
    • no change to the default rules or to any other rule;
    • no templating from response bodies;
    • no change to which groups are excluded.
  • Follow-up found: writes whose response has no body and no content type outside /api/ are still excluded as non-json. That hides 13 write tools in 5 of the showcase captures (Directus, Jellyfin, Keycloak, Miniflux, Shlink). Fixing it changes default output, so it belongs in a separate change.

Within the contribution scope: an analysis-view projection change inside an existing boundary; no target execution.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the environment-manifest analysis view (src/domain/analysisView/), at template-rule application.
  • Contribution scope fit and linked maintainer decision: an opt-in rule within the existing view; not applicable.
  • CLI and MCP/tool-catalog contract: template_rules accepts prefix-variance. The request schema's description names it, which changes the generated tool catalog. Tool params[].rule can now be prefix-variance. Requests that don't list it give identical results.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: the manifest is still derived from request lines only; every merged parameter stays basis: "inferred", with its observed values.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none beyond the generated MCP catalog.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

Tests added. Seven cases in environmentManifestView.test.ts:

  • a literal shared across methods and depths, plus the same capture without the rule;
  • the spelling condition: same classes and length, case, a missing digit, a colon word, a version;
  • a digit-free member of a fixed-length id family, against a shorter word, a hyphenated value and a family shorter than eight characters;
  • merges that keep a tool's own rule;
  • both halves of a templated pair;
  • format-rule positions;
  • the segment limit and its limitation.

Corpus evidence (executed over the 50 showcase captures: 45 HAR inspections, 5 browser scenarios):

  • Unchanged without the rule. Main's build and this branch give byte-identical results without the rule: the manifest with no rules, with the four existing opt-in rules, and the environment-state view. All 150 of 150 hash equal.

  • Templated with the rule. Added to after-uid-literal, opaque-token and sibling-variance, the rule templates 25 literal write tools and 44 read tools in 10 captures:

    • Komga: collections, readlists, book pages;
    • n8n: workflow PATCH, DELETE, archive, and the reads of a workflow whose id holds no digit;
    • Memos: memos, user reads, and the reads of two memos whose ids hold no digit;
    • Navidrome: playlists;
    • Mealie: recipes;
    • Grist: documents, table records;
    • Redpanda Console: subjects, topics;
    • Sentry: releases;
    • Shlink: short URLs;
    • Mattermost: me reads.

    Tools go from 1,591 to 1,578, because Redpanda Console's per-subject reads and the per-memo and per-workflow reads merge.

  • Left alone, as intended: Espo CRM layout, Federal Register facets, Ghost slug, Shlink stats, Lychee Metrics::photo and Vault's path names.

  • Combined with feat(environment): apply evidence-gated write effects to the served state #5600 (merged locally with main):

    • served write tools go from 33 to 39: Komga collection create, update and delete; n8n workflow delete; Sentry release update and delete;
    • write tools with no state target go from 102 to 87.
  • Newly modelled but still unserved, because of what the capture holds:

    • no read after the write: Komga readlists, Mealie, Navidrome, Redpanda Console;
    • n8n's item read shows an expanded shared relation its create response never returned;
    • Shlink sorts tags while the update echoes the request's order.

End to end on five random environments. Komga, Mealie, n8n, Sentry and Shlink were drawn at random from the ten environments the rule changes, redrawing until one had newly served writes. Each was rebuilt on its own Linux VM from its published scoped HAR with npm pack of #5600 + main + this branch: manifest, bundle, smoke, retrieval tasks for gpt-oss-120b and GLM-5.3-Flash, write tasks graded from the state through data/get, and a dry-run dataset. Published results are in brackets.

Environment Tools Served from state (reads / writes) Retrieval gpt-oss Retrieval GLM Writes gpt-oss Writes GLM
Komga 42 → 46 26 / 3 12/12 (11/12) 12/12 (11/12) 3/4 4/4
Mealie 39 → 39 36 / 0 12/12 (12/12) 12/12 (12/12) – –
n8n 30 → 33 17 / 1 9/9 (9/9) 9/9 (9/9) 2/2 2/2
Sentry 34 → 34 26 / 3 12/12 (12/12) 11/12 (12/12) 2/4, rerun 0/4 4/4
Shlink 17 → 17 5 / 0 5/7, rerun 7/7 7/7 (7/7) – –

Every smoke task passed. The misses:

  • Sentry writes with gpt-oss: in every failed episode the model passed id: "sentry" for the /api/0/ segment, which the tool schema describes as observed: 0. Every passing episode, and every GLM episode, passed 0.
  • Komga's update and Shlink's first run with gpt-oss: the provider rejected malformed tool calls (null or undefined optional arguments).
  • Sentry qa-03 with GLM: the model never called the alert-rules tool.

The first n8n run showed that a digit-free workflow id stayed literal: reading that workflow by id failed because the state held only its list fields. The fixed-length clause fixed that, and the rebuilt n8n reads it correctly.

Live comparison, seeded by the same scripts:

  • Komga 1.29.1: 9 of 12 steps equal. Collection create, update, delete and the reads after them agree apart from the generated id. Two differences remain: the collection list after a create omits the new collection (recorded membership), and a deleted collection's 404 replays the recorded body.

  • n8n 1.123.85: 3 of 8 steps equal.

    • n8n refuses to delete a workflow that isn't archived (400); the environment deletes it.
    • The workflow list replays its recorded response, so deletes don't show in it.
    • Archiving isn't served.

    These gaps belong to the write and list serving in feat(environment): apply evidence-gated write effects to the served state #5600 and its base, not to this rule.

User-visible output. Komga, with the rule:

{
  "name": "patch_collections_by_collection_id",
  "method": "PATCH",
  "path_template": "/api/v1/collections/{collection_id}",
  "api_surface_template": "/api/v1/collections/0RZ576QZQA5KG",
  "params": [
    {
      "index": 3,
      "name": "collection_id",
      "rule": "prefix-variance",
      "basis": "inferred",
      "observed_values": ["0RZ576QZQA5KG"]
    }
  ],
  "body_shape": { "type": "object", "properties": { "name": "string", "ordered": "boolean" } },
  "statuses": [204],
  "record_ordinals": [108]
}

Without the rule the same record is patch_collections_0rz576qzqa5kg with params: [].

Remaining proof gaps. The rule is an inference from paths. An app whose identifier-like literal sits beside an opt-in parameter but names a different resource would be templated wrongly. In the 50 captures, every such literal that qualified was the same resource, and every one that didn't qualify was a word.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Run on macOS with Node v22.23.1 at 33b0643 (the rule, the alias removal, and the fixed-length clause); 9a025b3 adds only the verification record.

  • npm run build:cached, npm run check:fast, npm run format:check, npm run scan:todos, npm run docs:check, npm run verify:test-discovery, npm run mcp-catalog:check: passed.
  • npx knip: passed.
  • npm run jscpd: 3.49% over 3561 files, 3067 clones. Main is 3.49% with 3068.
  • npx vitest run --project domain --project services: 7119 passed, 5 pre-existing skips.
  • npm run test:prepare, then npm run test:focused -- the analysis-view MCP and CLI boundaries, compact input schema, tool schema validity, and environment serve and export boundaries: 7 files, 76 passed.
  • npx vitest run src/domain/analysisView/: 280 passed.
  • Main's build and this branch's give identical outputs without the rule: 150 of 150 over the 50 captures, rechecked at 33b0643.
  • Review round (head 6a8beb5): merged main at 52c84f6, then fixed the five bot threads in 75af11f. Shared values stay with the parameter that observed them, each donor's spelling is summarised once, and one observation forms a fixed-length family. Both new tests fail on the previous head. The gates above passed again (domain and services 7255, 5 pre-existing skips; focused boundaries 76; jscpd 3.49%), and the tools with and without prefix-variance over the 50 captures are unchanged, name for name.
  • Review round 2 (head 03b66df): bounded the spelling summary for Codex's follow-up: characters are classified in one pass, and a value over 128 characters is compared only exactly. Its test fails on 6a8beb5; the gates passed again (domain and services 7257, focused boundaries 76, jscpd 3.49%), and the census over the 50 captures is unchanged.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The rule is opt-in, and outputs without it are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: request lines only; no bodies or headers are read by the rule.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

earakely-scale and others added 4 commits October 20, 2026 12:29
Record the outcome, requirements, non-goals, plan and tasks for
prefix-variance, an opt-in environment-manifest rule that templates a
literal segment with the parameter another tool already uses at that
position, so a session's writes to one entity share the read's template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the opt-in prefix-variance template rule. It runs after the other
opt-in rules and templates a literal at a position that another tool,
of any method or segment count, templates by one of those rules after
the same preceding parts, when the literal is one of that parameter's
observed values or carries a digit and is spelled like one. The
parameter takes the shared parameter's name, tools that now match merge,
and a merged position keeps a tool's own rule when one templated it.

A write to the one entity a session edited, such as
PATCH /api/v1/collections/0RZ576QZQA5KG, becomes
patch_collections_by_collection_id on the read's template instead of a
literal single-entity tool.

Tool naming moves to its own module, and the three comparing passes
share the 32-segment split. Manifests that do not list the rule are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parameters now type their rule as a format rule, a shared opt-in rule
or prefix-variance, so nothing reads the union alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record the gates, and the 50 showcase captures with and without the
rule: identical output without it, 25 write and 34 read tools templated
with it, and the write tools the write-plan branch serves on top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review October 20, 2026 19:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T23:47:38.429901Z 03b66df New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain in the reviewed changes.

Summary

Adds opt-in prefix-variance so literal routes can share parameters already inferred for related tools.

  • Environment manifests can share an inferred path parameter with matching literal routes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Grouped request routes] --> B[Existing opt-in rules]
  B --> C[Index inferred parameters by preceding route parts]
  C --> D{Literal qualifies?}
  D -->|Observed value or matching spelling| E[Share parameter name]
  D -->|No| F[Keep literal]
  E --> G[Merge matching routes]
  F --> G
Loading

Reviews (5) · Last reviewed commit: "fix(analysis-view): bound the spelling s..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 930c96d0a1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…iers

prefix-variance accepted an unobserved literal only when it carried a
digit, so a generated identifier that happened to hold none stayed a
literal tool: an n8n workflow id such as FkMwxmXNGaGVsXFG, whose reads
then never joined the item view. A literal now also qualifies when every
value observed at the position has one length of eight or more characters
and the literal has that length and uses only their character classes.

Across the 50 showcase captures this templates 10 more read tools in
Memos and n8n and no words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33b0643e8c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Five randomly drawn environments rebuilt on VMs with the rule and the
write-plan branch: smoke, retrieval and write tasks for two models, and
the same calls against the live applications. Record the results, the
misses and their causes, and the corpus numbers after the fixed-length
clause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits October 20, 2026 15:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the literal

A shared position folded every donor's values into the earliest donor's
parameter. With an opaque-token read before sibling-variance reads at
the same position, a PATCH of /api/items/b2 qualified on the sibling's
evidence but became /api/items/{uid} instead of joining the item read's
/api/items/{item_id}. Each position now keeps one donor per naming rule
with its own values, and a literal takes the donor that observed it,
else the earliest one it is spelled like.

Each donor's spelling (length and character classes of its values, and
its fixed-length family) is summarised once per position, so a literal
is checked in time independent of how many values were observed, rather
than copying and rescanning them for every candidate.

A family now forms from one observed value, as the requirement says, so
a digit-free id of the same length shares a position that only one
opaque-token or after-uid-literal tool supplied. The 50 showcase
captures give the same tools as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a8beb589a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

spellingSummary classified every observed value with three full-size
replaceAll copies and a set per distinct character, so a donor holding
a multi-megabyte segment cost unaccounted memory and time in finish().
Characters are now classified in one pass, and a value longer than 128
characters takes no part in spelling comparisons: it shares a position
only as an exactly observed value. The 50 showcase captures give the
same tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@morluto
morluto merged commit ea35347 into morluto:main Oct 21, 2026
38 of 42 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
3 tasks done
@morluto morluto added the enhancement New feature or request label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants