Skip to content

feat(adapters): shared service-token core - #308

Merged
delpher merged 2 commits into
masterfrom
adapters/service-tokens
Dec 1, 2026
Merged

delpher merged 2 commits into
masterfrom
adapters/service-tokens

Conversation

@delpher

@delpher delpher commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Step 3 of ТЗ-5 (#244 v2): the shared core module every adapter builds on. Small on purpose — no adapter is wired here yet, so the contract can be reviewed before four copies grow from it.

What it does (src/adapters/core/serviceTokens.mjs)

  • serviceTokens from aichat.config.json; ghTokenFile is read as serviceTokens.github for one release (never written back), and only when serviceTokens does not already name github.
  • Relative paths resolve against the config folder, ~ expands.
  • Validation: id ^[a-z0-9-]+$; value trimmed, single line (a control character or a newline in the middle means a wrong file), non-empty, ≤ 1024 chars. Anything else is skipped, not thrown.
  • serviceTokenHeaders(config) → { "X-Service-Token-<id>": "…" }, the only shape an adapter adds to its /mcp request.
  • Log lines name the service and the file, never a value.

Tests (serviceTokens.test.mjs, 8 cases, added to npm test): alias precedence, path resolution, bad id/empty path, unusable values (empty, two lines, NUL, too long, a folder, a missing file), missing legacy token reported once, and a guard that a value never lands in the returned file list or in a log line.

npm run typecheck clean.

Next, after review: each adapter wires its own transport on top (claude — requestInit, agy — mcpServerSpec() on session/new|load, codex — after its live check, opencode — {file:} in opencode.jsonc); then the manager.

…, X-Service-Token header)

One reader for the four adapters, so a service token cannot be parsed four ways: serviceTokens with ghTokenFile as github for one release, validation of id and value (trimmed, one line, <=1024), and the headers a /mcp request gets. Values never reach a log line.
…; ASCII-only header values

codex 6317: an explicit but empty/broken serviceTokens.github is a mistake to report, not a reason to fall back to the old PAT. agy 6318: a header value must be printable ASCII - a UTF-8 file would make fetch throw and take /mcp down. Adds redactServiceTokens for adapter log/error lines.
@delpher
delpher merged commit d37cd76 into master Dec 1, 2026
3 checks passed
@delpher
delpher deleted the adapters/service-tokens branch December 1, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant