From 94c3bbae3129b34b81a56edd8d13dc1af8ebe34e Mon Sep 17 00:00:00 2001 From: "r4yharris-agent-coder[bot]" <334673250+r4yharris-agent-coder[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:08:30 -0400 Subject: [PATCH] feat(copilot): assess offline worker capability descriptors ## Model GPT-6.1-Sol identifies the independent parent reviewer/publisher and its documentation contribution only. The child implementation author's served model is unknown; no measured Roster seat or usage is claimed. ## Summary Add a pure closed-schema synthetic worker capability assessment with descriptor-only compatibility. Missing/null and unsupported controls remain distinct. Unknown fields/tools and any launch/network/auth/shell/git/publisher authority fail closed; finite declared limits and independent frozen snapshots are validated. Live dispatch and publication eligibility always remain false. No production imports, process launch, live provider calls or default changes. Document exact schema, limitations, child verification and independent parent review. This is one offline preparation slice, not a completed live adapter. Parent #571 and dependency #570 remain open; #596 permission recovery and physical/auth/account/data/model/spend gates are unchanged. Spec: docs/FEATURE_SPEC.md sections5.2/5.4/5.5/5.8, honors principles3 and non-goals7. Node20 ESM, zero new runtime dependencies; exact three-file allowlist only. Closes #645. ## How to test node --test --test-reporter=tap tests/copilot-worker-capabilities.test.mjs tests/copilot-worker-contract.test.mjs tests/capabilities.test.mjs Independent parent Windows Node20.19.5:97 tests,97 pass,0 fail,0 skip,1467.8426ms. Child same-selector97/97,2176.0346ms. Preliminary Node24 evidence retained separately. git diff --cached --check passed. Full required CI must pass before merge. No full #571 delivery, physical containment, live integration, human evaluation or observed enforcement is asserted. GHCP token usage unknown; declared capacity is not usage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> AI-Agent: r4yharris-agent-coder AI-Model: GPT-6.1-Sol AI-Run: 1|github-copilot|GPT-6.1-Sol@-|x|-/1000000|-|ghcp-20261014-117004|645 --- docs/COPILOT_WORKER_DESIGN.md | 76 ++++++++- src/lib/copilot-worker-capabilities.mjs | 95 +++++++++++ tests/copilot-worker-capabilities.test.mjs | 182 +++++++++++++++++++++ 3 files changed, 352 insertions(+), 1 deletion(-) create mode 100644 src/lib/copilot-worker-capabilities.mjs create mode 100644 tests/copilot-worker-capabilities.test.mjs diff --git a/docs/COPILOT_WORKER_DESIGN.md b/docs/COPILOT_WORKER_DESIGN.md index cd871d4..1642896 100644 --- a/docs/COPILOT_WORKER_DESIGN.md +++ b/docs/COPILOT_WORKER_DESIGN.md @@ -1,6 +1,6 @@ # Optional Copilot full-agent worker: design proposal -**Status: DESIGN ONLY, 2026-10-13.** Preparation for #571 under #569; neither +**Status: OFFLINE PREPARATION ONLY, 2026-10-14.** Preparation for #571 under #569; neither issue is declared complete. Ray delegated the architecture choice on 2026-10-13; the parent selected preparation of an explicitly selected external **full-agent worker**, not a Copilot transport substituted into the builtin @@ -299,6 +299,80 @@ review, and no passing mock authorizes publication. Gates C/D, actual supported CLI capability wiring, account/data/spend/dependency approval and #570's publication gate remain separate. No real worker adapter is delivered here. +## 9. Offline capability assessment (separate from Gate B's event protocol) + +The #645 pure [capability assessment](../src/lib/copilot-worker-capabilities.mjs) +exposes `assessCopilotWorkerCapabilities(report)` for offline preparation only. +It is not imported by the CLI, builtin seat loop or worker mock, and provides +no transport, launch, authentication, artifact import, review or publication +operation. It implements the fail-closed capability declaration prerequisite +in sections 3, 5 and 7 of this design, tracing to FEATURE_SPEC sections +5.2, 5.4, 5.5 and 5.8 while preserving principles 3 and non-goals 7. + +Schema 1 accepts exactly these fields: + +- `schema: 1`, `kind: 'external-full-agent'`, `evidence: 'synthetic'`, + `concurrency: 1` and `tools: ['read_file']`. Only Gate B's existing read + callback is recognized; unknown, automatic or expanded tools fail rather + than being filtered or granted. +- `authority`: `launch`, `network`, `auth`, `shell`, `git` and `publisher` + must each be explicitly `false`. No environment, credential, model, + transport or physical-containment fields are accepted. +- `limits`: `files`, `bytes`, `callbacks`, `events` and `duration` must each + be finite positive safe integers. `duration` is milliseconds. These are + declarations, not enforced budgets or proof of a hard spend ceiling. +- `controls`: `immutableTask`, `exactScope`, `boundedCallbacks`, + `candidateHashes`, `cancellation`, `deadline`, `exitAndCleanup`, + `separateProvenance` and `independentReview`. Values are `true`, `false` + or `null`; omitted controls remain explicitly unknown. + +Malformed records throw `TypeError`. Missing/null and explicitly unsupported +controls produce a `blocked` assessment with separate `unknownControls` and +`unsupportedControls` lists. All controls declared true yield +`offline-contract-compatible`, meaning **descriptor compatibility only**. +Declarations are not observations of actual worker behavior. The returned +snapshot is deeply frozen and independent of caller mutation. + +Every assessment has `liveDispatchEligible: false` and +`publicationEligible: false`. Live blockers separately identify the +unqualified production bridge, physical containment, inference auth, +account/data/model/spend approval, remote cancellation, authoring provenance +and unresolved dependency gate. This schema cannot clear those gates, +fabricate served-model usage, qualify an executable or produce builtin +attribution. #570's original #596 remains a separate dependency; its +installation-permission blocker is not repaired or accepted here. + +The [focused descriptor tests](../tests/copilot-worker-capabilities.test.mjs) +exercise closed records, unknown/unsupported controls, forbidden authority, +tools, finite limits, nonexecuted accessors and immutable results. They do not +repeat Gate B's artifact/event protocol tests or prove Gates C/D. The next +safe step is independent review of this bounded offline slice, not enabling +production dispatch or claiming #571 complete. + +Child verification on Windows Node `v20.19.5`, 2026-10-14: + +```powershell +& 'C:\Users\harrr\AppData\Local\nvm\v20.19.5\node.exe' --test --test-reporter=tap ` + tests\copilot-worker-capabilities.test.mjs tests\copilot-worker-contract.test.mjs ` + tests\capabilities.test.mjs +``` + +Result: **97 tests, 97 passed, zero failures/skips**, **2176.0346 ms**. +This selector combines the new descriptor tests with the unchanged Gate B +protocol and model-prior tests; it is not the earlier 121-test parent selector. +Preliminary Node `v24.19.0` verification ran only descriptor/model-prior tests: +13 passed, zero failures/skips, 574.7498 ms, before the final test additions. +The child author's actual served model remains unknown. This evidence is not +independent parent review, publication, merge, human acceptance or live proof. + +Independent parent review on Windows Node `v20.19.5` reran the same selector: +**97 tests, 97 passed, zero failures/skips**, **1467.8426 ms**. Review covered +the complete three-file staged diff, closed-record validation, denied authority, +missing versus unsupported controls, independent frozen snapshots and the +absence of production wiring. No blocking defects were identified in this +descriptor-only scope. Parent review does not identify the unknown child model +or discharge any live qualification, publication or human acceptance gate. + ## Sources and preparation record No new web research or provider transfer was performed for this proposal. diff --git a/src/lib/copilot-worker-capabilities.mjs b/src/lib/copilot-worker-capabilities.mjs new file mode 100644 index 0000000..b927057 --- /dev/null +++ b/src/lib/copilot-worker-capabilities.mjs @@ -0,0 +1,95 @@ +const controlNames = Object.freeze([ + 'immutableTask', 'exactScope', 'boundedCallbacks', 'candidateHashes', + 'cancellation', 'deadline', 'exitAndCleanup', 'separateProvenance', 'independentReview', +]); +const authorityNames = ['launch', 'network', 'auth', 'shell', 'git', 'publisher']; +const limitNames = ['files', 'bytes', 'callbacks', 'events', 'duration']; +const liveBlockers = Object.freeze([ + 'production-capability-bridge-unqualified', + 'physical-containment-unqualified', + 'inference-auth-unapproved', + 'account-data-model-spend-unapproved', + 'remote-cancellation-unqualified', + 'authoring-provenance-unverified', + 'dependency-gate-unresolved', +]); + +function record(value, fields, label, { required = true } = {}) { + if (!value || typeof value !== 'object' || Object.getPrototypeOf(value) !== Object.prototype) { + throw new TypeError(`${label} must be a plain record`); + } + const keys = Reflect.ownKeys(value); + if (keys.some((key) => !fields.includes(key)) || + (required && fields.some((key) => !Object.hasOwn(value, key)))) { + throw new TypeError(`${label} must use only the documented fields`); + } + const result = {}; + for (const key of keys) { + const descriptor = Object.getOwnPropertyDescriptor(value, key); + if (!descriptor.enumerable || !Object.hasOwn(descriptor, 'value')) { + throw new TypeError(`${label} must contain enumerable data properties`); + } + result[key] = descriptor.value; + } + return result; +} + +/** + * Assess a synthetic capability declaration, not execution readiness or a grant. + * This module deliberately has no transport, environment, filesystem or publisher access. + */ +export function assessCopilotWorkerCapabilities(report) { + const input = record(report, + ['schema', 'kind', 'evidence', 'concurrency', 'tools', 'authority', 'limits', 'controls'], + 'Offline worker capability report'); + if (input.schema !== 1 || input.kind !== 'external-full-agent' || + input.evidence !== 'synthetic' || input.concurrency !== 1) { + throw new TypeError('Offline report requires schema 1, external-full-agent, synthetic evidence and concurrency 1'); + } + // Only the existing Gate B fixture's read callback is recognized. + const tools = input.tools; + if (!Array.isArray(tools) || Object.getPrototypeOf(tools) !== Array.prototype || + tools.length !== 1 || Reflect.ownKeys(tools).length !== 2) { + throw new TypeError('Offline tools must contain only read_file'); + } + const tool = Object.getOwnPropertyDescriptor(tools, '0'); + if (!tool?.enumerable || !Object.hasOwn(tool, 'value') || tool.value !== 'read_file') { + throw new TypeError('Offline tools must contain only read_file'); + } + const authority = record(input.authority, authorityNames, 'Offline authority'); + if (authorityNames.some((key) => authority[key] !== false)) { + throw new TypeError('Offline launch, network, auth, shell, git and publisher authority must be false'); + } + const limits = record(input.limits, limitNames, 'Offline limits'); + if (limitNames.some((key) => !Number.isSafeInteger(limits[key]) || limits[key] < 1)) { + throw new TypeError('Offline limits must all be finite positive safe integers'); + } + const controls = record(input.controls, controlNames, 'Offline controls', { required: false }); + if (Object.values(controls).some((value) => value !== null && typeof value !== 'boolean')) { + throw new TypeError('Offline controls must be true, false or null (unknown)'); + } + const unknownControls = Object.freeze(controlNames.filter((key) => + !Object.hasOwn(controls, key) || controls[key] === null)); + const unsupportedControls = Object.freeze(controlNames.filter((key) => controls[key] === false)); + const declaredControls = Object.freeze(Object.fromEntries(controlNames.map((key) => + [key, Object.hasOwn(controls, key) ? controls[key] : null]))); + return Object.freeze({ + schema: 1, + kind: 'external-full-agent', + evidence: 'synthetic', + status: unknownControls.length || unsupportedControls.length ? 'blocked' : 'offline-contract-compatible', + offlineContractCompatible: unknownControls.length === 0 && unsupportedControls.length === 0, + unknownControls, + unsupportedControls, + capabilities: Object.freeze({ + concurrency: 1, + tools: Object.freeze(['read_file']), + authority: Object.freeze(authority), + limits: Object.freeze(limits), + controls: declaredControls, + }), + liveDispatchEligible: false, + publicationEligible: false, + liveBlockers, + }); +} diff --git a/tests/copilot-worker-capabilities.test.mjs b/tests/copilot-worker-capabilities.test.mjs new file mode 100644 index 0000000..24cd035 --- /dev/null +++ b/tests/copilot-worker-capabilities.test.mjs @@ -0,0 +1,182 @@ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import test from 'node:test'; +import { assessCopilotWorkerCapabilities } from '../src/lib/copilot-worker-capabilities.mjs'; + +function report() { + return { + schema: 1, kind: 'external-full-agent', evidence: 'synthetic', concurrency: 1, + tools: ['read_file'], + authority: { launch: false, network: false, auth: false, shell: false, git: false, publisher: false }, + limits: { files: 16, bytes: 1_000_000, callbacks: 32, events: 128, duration: 60_000 }, + controls: { immutableTask: true, exactScope: true, boundedCallbacks: true, candidateHashes: true, + cancellation: true, deadline: true, exitAndCleanup: true, separateProvenance: true, independentReview: true }, + }; +} + +test('complete synthetic declarations qualify only the offline contract, never live dispatch or publication', () => { + const result = assessCopilotWorkerCapabilities(report()); + assert.equal(result.status, 'offline-contract-compatible'); + assert.equal(result.offlineContractCompatible, true); + assert.deepEqual(result.unknownControls, []); + assert.deepEqual(result.unsupportedControls, []); + assert.equal(result.kind, 'external-full-agent'); + assert.equal(result.evidence, 'synthetic'); + assert.equal(result.liveDispatchEligible, false); + assert.equal(result.publicationEligible, false); + assert.deepEqual(result.liveBlockers, [ + 'production-capability-bridge-unqualified', 'physical-containment-unqualified', + 'inference-auth-unapproved', 'account-data-model-spend-unapproved', + 'remote-cancellation-unqualified', 'authoring-provenance-unverified', 'dependency-gate-unresolved', + ]); + assert.equal(Object.hasOwn(result, 'model'), false); + assert.equal(Object.hasOwn(result, 'usage'), false); +}); + +test('every missing, unknown or explicitly unsupported control blocks offline compatibility', () => { + for (const key of Object.keys(report().controls)) { + for (const state of ['missing', null, false]) { + const input = report(); + if (state === 'missing') delete input.controls[key]; + else input.controls[key] = state; + const result = assessCopilotWorkerCapabilities(input); + assert.equal(result.status, 'blocked', `${key}: ${state}`); + assert.equal(result.offlineContractCompatible, false); + assert.deepEqual(result.unknownControls, state === false ? [] : [key]); + assert.deepEqual(result.unsupportedControls, state === false ? [key] : []); + assert.equal(result.capabilities.controls[key], state === false ? false : null); + assert.equal(result.liveDispatchEligible, false); + assert.equal(result.publicationEligible, false); + } + } + const result = assessCopilotWorkerCapabilities({ ...report(), controls: {} }); + assert.deepEqual(result.unknownControls, Object.keys(report().controls)); + const mixed = report(); + delete mixed.controls.immutableTask; + mixed.controls.cancellation = false; + mixed.controls.deadline = null; + const assessment = assessCopilotWorkerCapabilities(mixed); + assert.deepEqual(assessment.unknownControls, ['immutableTask', 'deadline']); + assert.deepEqual(assessment.unsupportedControls, ['cancellation']); +}); + +test('reports cannot claim builtin identity, measured/live evidence, fan-out or additional authority', () => { + for (const changes of [ + { schema: 2 }, { schema: '1' }, { kind: 'builtin' }, { evidence: 'verified' }, + { evidence: 'live' }, { concurrency: 2 }, { concurrency: 0 }, { concurrency: '1' }, + { environment: {} }, { physicalContainment: true }, { model: 'requested-only' }, + { transport: () => assert.fail('transport invoked') }, { token: 'synthetic-token' }, + ]) { + assert.throws(() => assessCopilotWorkerCapabilities({ ...report(), ...changes }), TypeError); + } + for (const key of Object.keys(report().authority)) { + for (const value of [true, null, 0, 'false', undefined]) { + const input = report(); + input.authority[key] = value; + assert.throws(() => assessCopilotWorkerCapabilities(input), /authority must be false/); + } + const input = report(); + delete input.authority[key]; + assert.throws(() => assessCopilotWorkerCapabilities(input), /documented fields/); + } +}); + +test('unknown, automatic and expanded callbacks are denied, not silently filtered', () => { + for (const tools of [ + [], ['read_file', 'read_file'], ['read_file', 'write_file'], ['shell'], ['filesystem'], + ['network'], ['mcp'], ['github'], ['publish'], ['git'], ['READ_FILE'], [null], + 'read_file', new Array(1), Object.assign(['read_file'], { extra: true }), + ]) { + assert.throws(() => assessCopilotWorkerCapabilities({ ...report(), tools }), /only read_file/); + } +}); + +test('each budget must be explicit and finite with no unlimited or silent default value', () => { + for (const key of Object.keys(report().limits)) { + for (const value of [0, -1, 1.5, Infinity, NaN, Number.MAX_SAFE_INTEGER + 1, '1', null]) { + const input = report(); + input.limits[key] = value; + assert.throws(() => assessCopilotWorkerCapabilities(input), /positive safe integers/); + } + const input = report(); + delete input.limits[key]; + assert.throws(() => assessCopilotWorkerCapabilities(input), /documented fields/); + } + for (const value of [1, Number.MAX_SAFE_INTEGER]) { + const input = report(); + for (const key of Object.keys(input.limits)) input.limits[key] = value; + assert.deepEqual(assessCopilotWorkerCapabilities(input).capabilities.limits, input.limits); + } +}); + +test('closed records reject unknown fields, non-JSON values and accessors without executing them', () => { + for (const section of ['authority', 'limits', 'controls']) { + const input = report(); + input[section].extra = true; + assert.throws(() => assessCopilotWorkerCapabilities(input), /documented fields/); + for (const value of [null, [], new Date(), Object.create(null)]) { + assert.throws(() => assessCopilotWorkerCapabilities({ ...report(), [section]: value }), /plain record/); + } + } + for (const value of [null, [], new Date(), Object.create(null)]) { + assert.throws(() => assessCopilotWorkerCapabilities(value), /plain record/); + } + for (const value of [undefined, 'true', 1, {}, () => true]) { + const input = report(); + input.controls.exactScope = value; + assert.throws(() => assessCopilotWorkerCapabilities(input), /true, false or null/); + } + for (const section of ['root', 'authority', 'limits', 'controls', 'tools']) { + const input = report(); + const target = section === 'root' ? input : input[section]; + const key = Object.keys(target)[0]; + Object.defineProperty(target, key, { enumerable: true, get() { assert.fail('accessor executed'); } }); + assert.throws(() => assessCopilotWorkerCapabilities(input), /data properties|only read_file/); + } + for (const section of ['root', 'authority', 'limits', 'controls', 'tools']) { + const input = report(); + const target = section === 'root' ? input : input[section]; + target[Symbol('hidden')] = true; + assert.throws(() => assessCopilotWorkerCapabilities(input), /documented fields|only read_file/); + } + const input = report(); + Object.defineProperty(input, 'schema', { enumerable: false }); + assert.throws(() => assessCopilotWorkerCapabilities(input), /data properties/); + for (const key of Object.keys(report())) { + const input = report(); + delete input[key]; + assert.throws(() => assessCopilotWorkerCapabilities(input), /documented fields/); + } + const callable = Object.assign(() => assert.fail('callable executed'), report()); + Object.setPrototypeOf(callable, Object.prototype); + assert.throws(() => assessCopilotWorkerCapabilities(callable), /plain record/); +}); + +test('assessment snapshots are deeply immutable and independent from caller mutation', () => { + const input = report(); + const result = assessCopilotWorkerCapabilities(input); + input.tools[0] = 'shell'; + input.authority.auth = true; + input.limits.duration = Infinity; + input.controls.exactScope = false; + assert.deepEqual(result.capabilities.tools, ['read_file']); + assert.equal(result.capabilities.authority.auth, false); + assert.equal(result.capabilities.limits.duration, 60_000); + assert.equal(result.capabilities.controls.exactScope, true); + for (const value of [result, result.capabilities, ...Object.values(result.capabilities), + result.unknownControls, result.unsupportedControls, result.liveBlockers]) { + if (typeof value === 'object') assert.equal(Object.isFrozen(value), true); + } + assert.throws(() => { result.liveDispatchEligible = true; }, TypeError); + assert.throws(() => { result.capabilities.authority.publisher = true; }, TypeError); + assert.throws(() => result.liveBlockers.pop(), TypeError); +}); + +test('offline assessment has no execution imports and leaves default runtime selection untouched', () => { + const source = readFileSync(new URL('../src/lib/copilot-worker-capabilities.mjs', import.meta.url), 'utf8'); + assert.doesNotMatch(source, /^\s*import\b|import\s*\(|process\.|fetch\s*\(/m); + for (const file of ['../src/cli.mjs', '../src/runtime/loop.mjs']) { + const runtime = readFileSync(new URL(file, import.meta.url), 'utf8'); + assert.doesNotMatch(runtime, /copilot-worker-capabilities/); + } +});