aptly 0.1.11 → 0.1.13
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/dist/bin/aptly.js +16 -2
- package/dist/src/automatic-hook.d.ts +7 -0
- package/dist/src/automatic-hook.js +33 -15
- package/dist/src/cli-help.js +6 -5
- package/dist/src/context-retry.d.ts +10 -0
- package/dist/src/context-retry.js +16 -3
- package/dist/src/core.d.ts +2 -0
- package/dist/src/core.js +39 -35
- package/dist/src/doctor.d.ts +84 -0
- package/dist/src/doctor.js +163 -0
- package/dist/src/host-paths.d.ts +10 -0
- package/dist/src/host-paths.js +15 -0
- package/dist/src/query-snapshot.d.ts +17 -0
- package/dist/src/query-snapshot.js +112 -0
- package/dist/src/server.js +2 -0
- package/dist/src/setup.d.ts +7 -5
- package/dist/src/setup.js +162 -39
- package/dist/src/statistics.d.ts +48 -2
- package/dist/src/statistics.js +87 -6
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/docs/guide/en/advanced.md +6 -0
- package/docs/guide/en/configuration.md +3 -1
- package/docs/guide/en/installation.md +2 -2
- package/docs/guide/en/statistics.md +4 -0
- package/docs/guide/en/transmission.md +7 -5
- package/docs/guide/en/troubleshooting.md +4 -2
- package/docs/guide/en.md +2 -0
- package/docs/guide/ja/advanced.md +6 -0
- package/docs/guide/ja/configuration.md +3 -1
- package/docs/guide/ja/installation.md +2 -2
- package/docs/guide/ja/statistics.md +4 -0
- package/docs/guide/ja/transmission.md +7 -5
- package/docs/guide/ja/troubleshooting.md +4 -2
- package/docs/guide/ja.md +2 -0
- package/docs/guide/ko/advanced.md +6 -0
- package/docs/guide/ko/configuration.md +3 -1
- package/docs/guide/ko/installation.md +2 -2
- package/docs/guide/ko/statistics.md +4 -0
- package/docs/guide/ko/transmission.md +7 -5
- package/docs/guide/ko/troubleshooting.md +4 -2
- package/docs/guide/ko.md +2 -0
- package/docs/guide/zh-CN/advanced.md +6 -0
- package/docs/guide/zh-CN/configuration.md +3 -1
- package/docs/guide/zh-CN/installation.md +2 -2
- package/docs/guide/zh-CN/statistics.md +4 -0
- package/docs/guide/zh-CN/transmission.md +7 -5
- package/docs/guide/zh-CN/troubleshooting.md +4 -2
- package/docs/guide/zh-CN.md +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** Read-only local observations, deliberately separate from legacy report schema v1. */
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
4
|
+
import { parse } from 'smol-toml';
|
|
5
|
+
import { resolveHostPaths } from './host-paths.js';
|
|
6
|
+
import { QuerySnapshot } from './query-snapshot.js';
|
|
7
|
+
import { queryAutomaticHookPolicy, effectiveTransmission } from './automatic-hook.js';
|
|
8
|
+
import { validateLedgerState } from './core.js';
|
|
9
|
+
import { isRecord } from './types.js';
|
|
10
|
+
import { VERSION } from './version.js';
|
|
11
|
+
import { CODEX_HOME_POLICY_SOURCE } from './policy-source.js';
|
|
12
|
+
export const DOCTOR_LEDGER_SCAN_LIMIT = 4 * 1024 * 1024;
|
|
13
|
+
const unknown = 'unknown';
|
|
14
|
+
function fail(code) { throw new Error(code); }
|
|
15
|
+
const version = (value) => typeof value === 'string' && /^(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})$/.test(value) ? value : null;
|
|
16
|
+
const json = (bytes) => { const value = JSON.parse(bytes.toString('utf8')); if (!isRecord(value))
|
|
17
|
+
fail('invalid_configuration'); return value; };
|
|
18
|
+
const observationCode = (error) => error instanceof Error && error.message === 'concurrent_configuration_change' ? 'changed_during_observation' : error instanceof Error && ['invalid_ledger', 'invalid_outcome', 'invalid_usage'].includes(error.message) ? 'invalid_ledger' : error instanceof Error && ['invalid_configuration', 'invalid_policy', 'invalid_policy_binding', 'missing_hook_registration', 'invalid_ledger_binding'].includes(error.message) ? error.message : 'configuration_observation_failed';
|
|
19
|
+
/** No lock, load, state initialization, provider or filesystem mutation. */
|
|
20
|
+
export function observeDoctorLedger(path, snapshot) {
|
|
21
|
+
const bytes = snapshot.size(path, { privateFile: true, singleLink: true });
|
|
22
|
+
const base = { bytes, scan_limit_bytes: DOCTOR_LEDGER_SCAN_LIMIT, write_timing: 'not_measured', counts: null };
|
|
23
|
+
if (bytes === null)
|
|
24
|
+
return { ...base, status: 'absent', history: unknown };
|
|
25
|
+
if (bytes > DOCTOR_LEDGER_SCAN_LIMIT)
|
|
26
|
+
return { ...base, status: 'scan_skipped_size_limit', history: unknown };
|
|
27
|
+
const state = JSON.parse(snapshot.read(path, { privateFile: true, singleLink: true, maxBytes: DOCTOR_LEDGER_SCAN_LIMIT }).toString('utf8'));
|
|
28
|
+
validateLedgerState(state);
|
|
29
|
+
const records = Object.values(state.requests);
|
|
30
|
+
return { ...base, status: 'validated_bounded_snapshot', counts: { total: records.length, complete: records.filter(r => r.state === 'complete').length, unknown: records.filter(r => r.state === 'unknown').length } };
|
|
31
|
+
}
|
|
32
|
+
function standardEntry(entry) {
|
|
33
|
+
return entry.command === process.execPath && Array.isArray(entry.args) && entry.args.length === 1 && typeof entry.args[0] === 'string' && isAbsolute(entry.args[0]) && /(?:^|[\\/])(?:dist[\\/]src[\\/]server\.js|src[\\/]server\.ts)$/.test(entry.args[0]) && !Object.hasOwn(entry, 'url');
|
|
34
|
+
}
|
|
35
|
+
function packageObservation(entry, snapshot) {
|
|
36
|
+
const server = entry.args[0], root = server.endsWith('.ts') ? dirname(dirname(server)) : dirname(dirname(dirname(server)));
|
|
37
|
+
// Check file kind/identity only; never execute this file or recursively follow its imports.
|
|
38
|
+
if (!snapshot.track(server))
|
|
39
|
+
return { status: 'target_missing', version: null };
|
|
40
|
+
const bytes = snapshot.read(join(root, 'package.json'), { maxBytes: 65536 });
|
|
41
|
+
if (!bytes)
|
|
42
|
+
return { status: 'metadata_absent', version: null };
|
|
43
|
+
const meta = json(bytes), v = version(meta.version);
|
|
44
|
+
if (meta.name !== 'aptly')
|
|
45
|
+
return { status: 'unrecognized_package', version: null };
|
|
46
|
+
return { status: v ? 'observed_numeric_release' : 'unsupported_version_metadata', version: v };
|
|
47
|
+
}
|
|
48
|
+
function hookObservation(bytes) {
|
|
49
|
+
if (!bytes)
|
|
50
|
+
return 'absent';
|
|
51
|
+
const config = json(bytes);
|
|
52
|
+
if (config.hooks !== undefined && !isRecord(config.hooks))
|
|
53
|
+
fail('invalid_configuration');
|
|
54
|
+
const pre = isRecord(config.hooks) ? config.hooks.PreToolUse : undefined;
|
|
55
|
+
if (pre === undefined)
|
|
56
|
+
return 'absent';
|
|
57
|
+
if (!Array.isArray(pre))
|
|
58
|
+
fail('invalid_configuration');
|
|
59
|
+
return pre.some(item => isRecord(item) && Array.isArray(item.hooks) && item.hooks.some(h => isRecord(h) && h.type === 'mcp_tool' && h.server === 'aptly' && h.tool === 'route_spawn_hook')) ? 'static_registration_present' : 'not_observed';
|
|
60
|
+
}
|
|
61
|
+
export function collectDoctor(options = {}) {
|
|
62
|
+
const env = options.env ?? process.env;
|
|
63
|
+
const clients = (options.clients ?? ['codex', 'claude']).map(client => {
|
|
64
|
+
const snapshot = new QuerySnapshot(), started = performance.now();
|
|
65
|
+
const base = { client, selected_home_source: (client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR) ? 'override' : 'default', connected_mcp_version: unknown, hook_trust: unknown, hook_execution: unknown, restart_required: unknown, retry_ticket_usage: unknown, credential_validity: unknown };
|
|
66
|
+
try {
|
|
67
|
+
const paths = resolveHostPaths(options, client), bytes = snapshot.read(paths.mcpPath, { maxBytes: 256 * 1024 });
|
|
68
|
+
const config = bytes ? (client === 'codex' ? parse(bytes.toString('utf8')) : json(bytes)) : {};
|
|
69
|
+
const servers = config[client === 'codex' ? 'mcp_servers' : 'mcpServers'];
|
|
70
|
+
if (servers !== undefined && !isRecord(servers))
|
|
71
|
+
fail('invalid_configuration');
|
|
72
|
+
const entry = isRecord(servers) ? servers.aptly : undefined;
|
|
73
|
+
if (entry === undefined) {
|
|
74
|
+
if (snapshot.read(join(paths.privateDir, 'setup-ownership.json'), { privateFile: true, maxBytes: 65536 }))
|
|
75
|
+
fail('invalid_configuration');
|
|
76
|
+
snapshot.verify();
|
|
77
|
+
return { ...base, status: 'complete', registration: 'unconfigured' };
|
|
78
|
+
}
|
|
79
|
+
if (!isRecord(entry) || (entry.env !== undefined && (!isRecord(entry.env) || Object.values(entry.env).some(v => typeof v !== 'string'))))
|
|
80
|
+
fail('invalid_configuration');
|
|
81
|
+
if (entry.env_vars !== undefined && (!Array.isArray(entry.env_vars) || entry.env_vars.length > 256 || entry.env_vars.some(v => typeof v !== 'string')))
|
|
82
|
+
fail('invalid_configuration');
|
|
83
|
+
const settings = isRecord(entry.env) ? entry.env : {}, forwarded = Array.isArray(entry.env_vars) ? entry.env_vars : [];
|
|
84
|
+
const permitted = (key) => client === 'claude' || forwarded.includes(key);
|
|
85
|
+
// A permitted passthrough is a future host binding, not evidence from this terminal.
|
|
86
|
+
const setting = (key) => Object.hasOwn(settings, key) ? settings[key] : undefined;
|
|
87
|
+
const candidate = standardEntry(entry), target = candidate ? packageObservation(entry, snapshot) : { status: 'custom_or_remote_launcher', version: null };
|
|
88
|
+
const standard = candidate && ['observed_numeric_release', 'unsupported_version_metadata'].includes(target.status);
|
|
89
|
+
if (target.status === 'target_missing')
|
|
90
|
+
fail('invalid_configuration');
|
|
91
|
+
const raw = setting('APTLY_HOOK_POLICY_PATH');
|
|
92
|
+
let source = 'unconfigured', policyStatus = 'unconfigured', transmission = null;
|
|
93
|
+
if (!standard) {
|
|
94
|
+
source = raw === CODEX_HOME_POLICY_SOURCE ? 'codex_home' : raw !== undefined ? 'fixed' : 'unconfigured';
|
|
95
|
+
policyStatus = 'custom_launcher_unobserved';
|
|
96
|
+
}
|
|
97
|
+
else if (raw !== undefined) {
|
|
98
|
+
if (typeof raw !== 'string')
|
|
99
|
+
fail('invalid_policy_binding');
|
|
100
|
+
let policyPath;
|
|
101
|
+
if (raw === CODEX_HOME_POLICY_SOURCE) {
|
|
102
|
+
source = 'codex_home';
|
|
103
|
+
if (standard && (client !== 'codex' || Object.hasOwn(settings, 'CODEX_HOME') || !forwarded.includes('CODEX_HOME')))
|
|
104
|
+
fail('invalid_policy_binding');
|
|
105
|
+
policyPath = join(paths.dir, 'aptly', 'auto-policy.json');
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
source = 'fixed';
|
|
109
|
+
if (!isAbsolute(raw))
|
|
110
|
+
fail('invalid_policy_binding');
|
|
111
|
+
policyPath = resolve(raw);
|
|
112
|
+
}
|
|
113
|
+
const loaded = queryAutomaticHookPolicy(policyPath, snapshot);
|
|
114
|
+
if (loaded.availability !== 'valid' || !loaded.policy)
|
|
115
|
+
fail('invalid_policy');
|
|
116
|
+
policyStatus = loaded.policy.enabled ? 'enabled' : 'disabled';
|
|
117
|
+
transmission = effectiveTransmission(loaded.policy);
|
|
118
|
+
}
|
|
119
|
+
else if (permitted('APTLY_HOOK_POLICY_PATH')) {
|
|
120
|
+
source = 'runtime_value_unobserved';
|
|
121
|
+
policyStatus = 'runtime_value_unobserved';
|
|
122
|
+
}
|
|
123
|
+
const hook = hookObservation(snapshot.read(paths.hooksPath, { maxBytes: 256 * 1024 }));
|
|
124
|
+
if (standard && policyStatus === 'enabled' && hook !== 'static_registration_present')
|
|
125
|
+
fail('missing_hook_registration');
|
|
126
|
+
const ledgerPath = setting('ROUTER_LEDGER_PATH');
|
|
127
|
+
let ledger = { status: 'runtime_value_unobserved', counts: null, write_timing: 'not_measured' };
|
|
128
|
+
if (standard && ledgerPath !== undefined) {
|
|
129
|
+
if (typeof ledgerPath !== 'string' || !isAbsolute(ledgerPath))
|
|
130
|
+
fail('invalid_ledger_binding');
|
|
131
|
+
try {
|
|
132
|
+
ledger = observeDoctorLedger(ledgerPath, snapshot);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error instanceof SyntaxError)
|
|
136
|
+
fail('invalid_ledger');
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (!standard)
|
|
141
|
+
ledger = { status: 'custom_launcher_unobserved', counts: null, write_timing: 'not_measured' };
|
|
142
|
+
else if (!permitted('ROUTER_LEDGER_PATH')) {
|
|
143
|
+
if (setting('ROUTER_PROVIDER') === 'decisions')
|
|
144
|
+
fail('invalid_ledger_binding');
|
|
145
|
+
ledger = { status: 'not_declared', counts: null, write_timing: 'not_measured' };
|
|
146
|
+
}
|
|
147
|
+
snapshot.verify();
|
|
148
|
+
return { ...base, status: 'complete', registration: standard ? 'standard_node_registration' : 'custom_or_remote_launcher', registered_package: target, policy: { source_kind: source, status: policyStatus, transmission }, hook_registration: hook, credential_reference: settings.APTLY_SECRET_BACKEND === 'os' ? 'os_reference' : Object.hasOwn(settings, 'OPENAI_API_KEY') ? 'inline_environment_present' : permitted('OPENAI_API_KEY') ? 'runtime_environment_permitted' : 'not_declared', ledger: { ...ledger, diagnostic_scan_ms: Math.max(0, performance.now() - started), timing_scope: 'full_client_observation_and_rechecks' } };
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
// A changed observation takes precedence over a parse/validation failure.
|
|
152
|
+
try {
|
|
153
|
+
snapshot.verify();
|
|
154
|
+
}
|
|
155
|
+
catch (changed) {
|
|
156
|
+
if (changed instanceof Error && changed.message === 'concurrent_configuration_change')
|
|
157
|
+
error = changed;
|
|
158
|
+
}
|
|
159
|
+
return { ...base, status: 'partial', code: observationCode(error) };
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return { kind: 'aptly-doctor', schema_version: 1, status: clients.some(c => c.status === 'partial') ? 'partial' : 'complete', cli_version: VERSION, scope: 'local_configuration_snapshot', readiness: 'not_certified', clients };
|
|
163
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Shared CLI selection; never claims the home of a running host. */
|
|
2
|
+
export declare function resolveHostPaths(options: {
|
|
3
|
+
home?: string;
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
5
|
+
}, client: 'codex' | 'claude'): {
|
|
6
|
+
dir: string;
|
|
7
|
+
mcpPath: string;
|
|
8
|
+
hooksPath: string;
|
|
9
|
+
privateDir: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
import { CODEX_HOME_POLICY_SOURCE, resolvePolicySource } from './policy-source.js';
|
|
4
|
+
/** Shared CLI selection; never claims the home of a running host. */
|
|
5
|
+
export function resolveHostPaths(options, client) {
|
|
6
|
+
const home = resolve(options.home ?? homedir()), env = options.env ?? process.env;
|
|
7
|
+
const override = client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR;
|
|
8
|
+
if (override && !isAbsolute(override))
|
|
9
|
+
throw new Error('relative_configuration_directory');
|
|
10
|
+
if (client === 'codex' && override !== undefined)
|
|
11
|
+
resolvePolicySource(CODEX_HOME_POLICY_SOURCE, env);
|
|
12
|
+
const dir = override || join(home, client === 'codex' ? '.codex' : '.claude');
|
|
13
|
+
const mcpPath = client === 'codex' ? join(dir, 'config.toml') : override ? join(dir, '.claude.json') : join(home, '.claude.json');
|
|
14
|
+
return { dir, mcpPath, hooksPath: join(dir, client === 'codex' ? 'hooks.json' : 'settings.json'), privateDir: join(dir, 'aptly') };
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
privateFile?: boolean;
|
|
3
|
+
directory?: boolean;
|
|
4
|
+
singleLink?: boolean;
|
|
5
|
+
identityOnly?: boolean;
|
|
6
|
+
maxBytes?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class QuerySnapshot {
|
|
9
|
+
private observations;
|
|
10
|
+
private remember;
|
|
11
|
+
track(path: string, options?: Options): boolean;
|
|
12
|
+
/** Checked size from the same observation later verified; does not read the body. */
|
|
13
|
+
size(path: string, options?: Options): number | null;
|
|
14
|
+
read(path: string, options?: Options): Buffer | null;
|
|
15
|
+
verify(): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Checked, bounded observations for read-only CLI queries; never an atomic multi-file snapshot. */
|
|
2
|
+
import { lstatSync, readlinkSync } from 'node:fs';
|
|
3
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
4
|
+
import { assertPrivateStatePath, readRegularFile, systemAliasAllowed } from './files.js';
|
|
5
|
+
import { assertWindowsPrivatePath } from './windows-private.js';
|
|
6
|
+
function metadata(path) {
|
|
7
|
+
try {
|
|
8
|
+
const s = lstatSync(path);
|
|
9
|
+
if (s.isSymbolicLink() && !systemAliasAllowed(path, s, readlinkSync(path)))
|
|
10
|
+
throw new Error('unsafe_configuration_file');
|
|
11
|
+
return { dev: s.dev, ino: s.ino, mode: s.mode, uid: s.uid, gid: s.gid, nlink: s.nlink, size: s.size, mtime: s.mtimeMs, ctime: s.ctimeMs, directory: s.isDirectory() };
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === 'ENOENT')
|
|
15
|
+
return null;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function signature(value, identityOnly = false) {
|
|
20
|
+
if (value === null)
|
|
21
|
+
return 'absent';
|
|
22
|
+
const { dev, ino, mode, uid, gid, nlink, size, mtime, ctime, directory } = value;
|
|
23
|
+
return JSON.stringify(directory ? { dev, ino, mode, uid, gid, directory } : identityOnly ? { dev, ino, mode, uid, gid, nlink, directory } : { dev, ino, mode, uid, gid, nlink, size, mtime, ctime, directory });
|
|
24
|
+
}
|
|
25
|
+
export class QuerySnapshot {
|
|
26
|
+
observations = new Map();
|
|
27
|
+
remember(path, value, options = {}) {
|
|
28
|
+
const old = this.observations.get(path);
|
|
29
|
+
if (old && signature(old.metadata, old.options.identityOnly) !== signature(value, old.options.identityOnly))
|
|
30
|
+
throw new Error('concurrent_configuration_change');
|
|
31
|
+
if (!old)
|
|
32
|
+
this.observations.set(path, { metadata: value, options: { ...options } });
|
|
33
|
+
else
|
|
34
|
+
old.options = { ...old.options, ...options, privateFile: old.options.privateFile || options.privateFile, singleLink: old.options.singleLink || options.singleLink };
|
|
35
|
+
}
|
|
36
|
+
track(path, options = {}) {
|
|
37
|
+
if (typeof path !== 'string' || !isAbsolute(path))
|
|
38
|
+
throw new Error('unsafe_configuration_file');
|
|
39
|
+
path = resolve(path);
|
|
40
|
+
const value = metadata(path);
|
|
41
|
+
this.remember(path, value, options);
|
|
42
|
+
for (let parent = dirname(path);; parent = dirname(parent)) {
|
|
43
|
+
this.remember(parent, metadata(parent), { directory: true, identityOnly: true });
|
|
44
|
+
if (dirname(parent) === parent)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
if (value === null) {
|
|
48
|
+
// Missing content does not make an existing insecure private parent safe.
|
|
49
|
+
if (options.privateFile && !options.directory && this.observations.get(dirname(path))?.metadata !== null)
|
|
50
|
+
assertPrivateStatePath(path);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (options.directory ? !value.directory : value.directory || (value.mode & 0o170000) !== 0o100000)
|
|
54
|
+
throw new Error('unsafe_configuration_file');
|
|
55
|
+
if (options.singleLink && !value.directory && value.nlink !== 1)
|
|
56
|
+
throw new Error('unsafe_configuration_file');
|
|
57
|
+
if (options.privateFile) {
|
|
58
|
+
if (options.directory) {
|
|
59
|
+
if (process.platform === 'win32')
|
|
60
|
+
assertWindowsPrivatePath(path);
|
|
61
|
+
else if ((value.mode & 0o077) || (process.getuid && value.uid !== process.getuid()))
|
|
62
|
+
throw new Error('private_directory_permissions');
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
assertPrivateStatePath(path);
|
|
66
|
+
if (!options.directory && process.platform !== 'win32' && ((value.mode & 0o077) || (process.getuid && value.uid !== process.getuid())))
|
|
67
|
+
throw new Error('private_file_permissions');
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
/** Checked size from the same observation later verified; does not read the body. */
|
|
72
|
+
size(path, options = {}) {
|
|
73
|
+
if (!this.track(path, options))
|
|
74
|
+
return null;
|
|
75
|
+
return this.observations.get(resolve(path)).metadata.size;
|
|
76
|
+
}
|
|
77
|
+
read(path, options = {}) {
|
|
78
|
+
if (typeof path !== 'string' || !isAbsolute(path))
|
|
79
|
+
throw new Error('unsafe_configuration_file');
|
|
80
|
+
path = resolve(path);
|
|
81
|
+
if (!this.track(path, options))
|
|
82
|
+
return null;
|
|
83
|
+
const bytes = readRegularFile(path, { privateFile: options.privateFile, maxBytes: options.maxBytes ?? 4 * 1024 * 1024 });
|
|
84
|
+
const observed = this.observations.get(path);
|
|
85
|
+
if (signature(observed.metadata) !== signature(metadata(path)))
|
|
86
|
+
throw new Error('concurrent_configuration_change');
|
|
87
|
+
if (observed.bytes && !observed.bytes.equals(bytes))
|
|
88
|
+
throw new Error('concurrent_configuration_change');
|
|
89
|
+
observed.bytes = bytes;
|
|
90
|
+
observed.options = { ...observed.options, ...options };
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
verify() {
|
|
94
|
+
for (const [path, observation] of this.observations) {
|
|
95
|
+
try {
|
|
96
|
+
if (signature(observation.metadata, observation.options.identityOnly) !== signature(metadata(path), observation.options.identityOnly))
|
|
97
|
+
throw new Error('concurrent_configuration_change');
|
|
98
|
+
if (observation.bytes) {
|
|
99
|
+
const bytes = readRegularFile(path, { privateFile: observation.options.privateFile, maxBytes: observation.options.maxBytes ?? 4 * 1024 * 1024 });
|
|
100
|
+
if (!observation.bytes.equals(bytes) || signature(observation.metadata) !== signature(metadata(path)))
|
|
101
|
+
throw new Error('concurrent_configuration_change');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
// A previously observed path becoming redirected/unsafe is an observation change.
|
|
106
|
+
if (error instanceof Error && ['unsafe_configuration_file', 'unsafe_path', 'unsafe_file'].includes(error.message))
|
|
107
|
+
throw new Error('concurrent_configuration_change');
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/src/server.js
CHANGED
|
@@ -24,6 +24,7 @@ const observationSchema = z.object({ client: hookSchema.client.optional(), event
|
|
|
24
24
|
const content = (result) => ({ content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result });
|
|
25
25
|
export function createServer({ env: inputEnv = process.env } = {}) {
|
|
26
26
|
const codexBound = inputEnv.APTLY_HOOK_POLICY_PATH === CODEX_HOME_POLICY_SOURCE;
|
|
27
|
+
const policySourceKind = codexBound ? 'codex_home' : inputEnv.APTLY_HOOK_POLICY_PATH === undefined ? 'unconfigured' : 'fixed';
|
|
27
28
|
const env = { ...inputEnv, APTLY_HOOK_POLICY_PATH: resolvePolicySource(inputEnv.APTLY_HOOK_POLICY_PATH, inputEnv) };
|
|
28
29
|
const { router, budget, mode, modelInfo, credentialStatus, disabledClients } = runtime(env);
|
|
29
30
|
const observations = new RoutingObservations();
|
|
@@ -71,6 +72,7 @@ export function createServer({ env: inputEnv = process.env } = {}) {
|
|
|
71
72
|
recommendation: { application: 'advisory_only', host_evidence_required: false, constraints: 'caller_declared_pins' },
|
|
72
73
|
model_information: { status: modelInfo.status, refresh: 'explicit_only', account_access_verified: false }, disabled_clients: disabledClients,
|
|
73
74
|
credential_status: credentialStatus,
|
|
75
|
+
runtime_diagnostics: { version: VERSION, policy_source_kind: policySourceKind, credential_status_observed: 'startup_snapshot', context_retries: retries.diagnostics() },
|
|
74
76
|
execution_statistics: { collection: 'explicit_operator_opt_in', view: 'aptly stats', semantics: 'host_reported_model_evidence_not_user_acceptance', effective_effort: 'not_measured', usage_rollups: 'not_collected' },
|
|
75
77
|
automatic_hook: { status: automatic.reason, mode: automatic.policy?.mode ?? 'disabled', transmission: automatic.policy ? effectiveTransmission(automatic.policy) : null, transmission_provenance: automatic.policy ? (automatic.policy.schema_version === 1 ? 'legacy_v1_default' : 'operator_policy_v2') : 'unavailable', host_settings_verified: false, context_tool: 'prepare_spawn_context', context_scope: 'this_process_exact_event_5_minutes', context_retry_tool: 'retry_spawn_recommendation', context_retry_limit: 1, fresh_delegation_tool: 'prepare_fresh_delegation', fresh_delegation_intent: 'caller_declared_not_verified', observation_tool: 'get_spawn_routing_observation', observation_scope: 'this_process_recent_calls', execution_observation: 'not_supported',
|
|
76
78
|
guarantee: { scope: 'enabled_trusted_connected_supported_hook_only', missing_hook_detectable: false, unavailable_host_hook: 'host_controls_fallback', eligible_defaults_failure: 'deny_when_transmission_enabled', inherited_application: 'defaults_deny_advisory_feedback', caller_recovery: 'model_driven_not_guaranteed' } },
|
package/dist/src/setup.d.ts
CHANGED
|
@@ -73,8 +73,9 @@ export declare function prepareTransmissionReview(options?: SetupOptions & {
|
|
|
73
73
|
candidates: TransmissionReviewCandidate[];
|
|
74
74
|
apply(choice: 'keep' | TransmissionScope): SetupResult;
|
|
75
75
|
};
|
|
76
|
-
/**
|
|
76
|
+
/** Redacted policy query; aggregate status is query completion, not host readiness. */
|
|
77
77
|
export declare function showTransmission(options?: SetupOptions): {
|
|
78
|
+
status: string;
|
|
78
79
|
clients: ({
|
|
79
80
|
client: Client;
|
|
80
81
|
status: string;
|
|
@@ -142,7 +143,12 @@ export declare function setStatisticsCollection(enabled: boolean, options?: Setu
|
|
|
142
143
|
}): SetupResult;
|
|
143
144
|
/** Snapshot view; no runtime, credentials, provider, budget gate or state creation. */
|
|
144
145
|
export declare function showStatistics(options?: SetupOptions, today?: boolean): {
|
|
146
|
+
status: string;
|
|
145
147
|
clients: ({
|
|
148
|
+
client: Client;
|
|
149
|
+
status: string;
|
|
150
|
+
collection: string;
|
|
151
|
+
} | {
|
|
146
152
|
status: string;
|
|
147
153
|
scope: string;
|
|
148
154
|
semantics: string;
|
|
@@ -178,10 +184,6 @@ export declare function showStatistics(options?: SetupOptions, today?: boolean):
|
|
|
178
184
|
model_alias_scope: string;
|
|
179
185
|
counts_are_lifetime: boolean;
|
|
180
186
|
client: Client;
|
|
181
|
-
} | {
|
|
182
|
-
client: Client;
|
|
183
|
-
status: string;
|
|
184
|
-
collection: string;
|
|
185
187
|
})[];
|
|
186
188
|
};
|
|
187
189
|
export {};
|