aptly 0.1.10 → 0.1.12
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/README.en.md +10 -10
- package/README.ja.md +10 -10
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/dist/bin/aptly.js +21 -16
- package/dist/src/cli-help.js +12 -10
- package/dist/src/cli-input.d.ts +19 -1
- package/dist/src/cli-input.js +23 -11
- package/dist/src/policy-source.d.ts +3 -0
- package/dist/src/policy-source.js +11 -0
- package/dist/src/server.d.ts +1 -1
- package/dist/src/server.js +10 -1
- package/dist/src/setup.d.ts +21 -0
- package/dist/src/setup.js +349 -5
- package/dist/src/transmission-review-cli.d.ts +11 -0
- package/dist/src/transmission-review-cli.js +35 -0
- package/dist/src/update-notifier.js +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/docs/ADVISORY_USAGE.md +1 -1
- package/docs/DRAFT_0_1_0.md +1 -1
- package/docs/guide/en/advanced.md +217 -0
- package/docs/guide/en/benchmarks.md +32 -0
- package/docs/guide/en/budget.md +45 -0
- package/docs/guide/en/configuration.md +104 -0
- package/docs/guide/en/installation.md +114 -0
- package/docs/guide/en/routing.md +61 -0
- package/docs/guide/en/statistics.md +43 -0
- package/docs/guide/en/transmission.md +71 -0
- package/docs/guide/en/troubleshooting.md +99 -0
- package/docs/guide/en.md +80 -505
- package/docs/guide/ja/advanced.md +217 -0
- package/docs/guide/ja/benchmarks.md +32 -0
- package/docs/guide/ja/budget.md +45 -0
- package/docs/guide/ja/configuration.md +104 -0
- package/docs/guide/ja/installation.md +114 -0
- package/docs/guide/ja/routing.md +61 -0
- package/docs/guide/ja/statistics.md +43 -0
- package/docs/guide/ja/transmission.md +71 -0
- package/docs/guide/ja/troubleshooting.md +99 -0
- package/docs/guide/ja.md +80 -505
- package/docs/guide/ko/advanced.md +217 -0
- package/docs/guide/ko/benchmarks.md +32 -0
- package/docs/guide/ko/budget.md +45 -0
- package/docs/guide/ko/configuration.md +104 -0
- package/docs/guide/ko/installation.md +114 -0
- package/docs/guide/ko/routing.md +61 -0
- package/docs/guide/ko/statistics.md +43 -0
- package/docs/guide/ko/transmission.md +71 -0
- package/docs/guide/ko/troubleshooting.md +99 -0
- package/docs/guide/ko.md +80 -505
- package/docs/guide/zh-CN/advanced.md +217 -0
- package/docs/guide/zh-CN/benchmarks.md +32 -0
- package/docs/guide/zh-CN/budget.md +45 -0
- package/docs/guide/zh-CN/configuration.md +104 -0
- package/docs/guide/zh-CN/installation.md +114 -0
- package/docs/guide/zh-CN/routing.md +61 -0
- package/docs/guide/zh-CN/statistics.md +43 -0
- package/docs/guide/zh-CN/transmission.md +71 -0
- package/docs/guide/zh-CN/troubleshooting.md +99 -0
- package/docs/guide/zh-CN.md +80 -505
- package/package.json +2 -1
package/dist/src/setup.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface SetupClientResult {
|
|
|
22
22
|
recovery?: string[];
|
|
23
23
|
transmission?: string;
|
|
24
24
|
transmission_source?: 'explicit' | 'legacy' | 'unselected';
|
|
25
|
+
transmission_review?: 'required' | 'complete';
|
|
25
26
|
budget?: {
|
|
26
27
|
limits: Record<string, number>;
|
|
27
28
|
added: string[];
|
|
@@ -52,8 +53,26 @@ export declare function prepareCredentialReference(options: SetupOptions, client
|
|
|
52
53
|
};
|
|
53
54
|
/** Preserved standard registrations require a separate explicit opt-in; ownership stays unchanged. */
|
|
54
55
|
export declare function migrateLauncher(options: SetupOptions, dryRun?: boolean, includeExisting?: boolean): SetupResult;
|
|
56
|
+
/** Explicitly select a per-Codex-home policy without moving any state. */
|
|
57
|
+
export declare function setPolicySource(options: SetupOptions, dryRun?: boolean): SetupResult;
|
|
55
58
|
/** Explicit operator change; updates policy and its receipt through normal guarded staging. */
|
|
56
59
|
export declare function setTransmission(scope: TransmissionScope, options?: SetupOptions): SetupResult;
|
|
60
|
+
export type TransmissionReviewCandidate = {
|
|
61
|
+
client: Client;
|
|
62
|
+
transmission: TransmissionScope | 'unselected';
|
|
63
|
+
transmission_source: 'legacy' | 'explicit' | 'unselected';
|
|
64
|
+
selected_home_source: 'default' | 'override';
|
|
65
|
+
application_mode: 'defaults' | 'advisory';
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** Read-only, two-phase local acknowledgement. Recheck every captured host before writing. */
|
|
69
|
+
export declare function prepareTransmissionReview(options?: SetupOptions & {
|
|
70
|
+
forceReview?: boolean;
|
|
71
|
+
}): {
|
|
72
|
+
result: SetupResult;
|
|
73
|
+
candidates: TransmissionReviewCandidate[];
|
|
74
|
+
apply(choice: 'keep' | TransmissionScope): SetupResult;
|
|
75
|
+
};
|
|
57
76
|
/** Read-only redacted policy state. Does not create host directories or contact a provider. */
|
|
58
77
|
export declare function showTransmission(options?: SetupOptions): {
|
|
59
78
|
clients: ({
|
|
@@ -62,6 +81,7 @@ export declare function showTransmission(options?: SetupOptions): {
|
|
|
62
81
|
code: string;
|
|
63
82
|
application_mode?: undefined;
|
|
64
83
|
enabled?: undefined;
|
|
84
|
+
transmission_review?: undefined;
|
|
65
85
|
transmission?: undefined;
|
|
66
86
|
transmission_source?: undefined;
|
|
67
87
|
} | {
|
|
@@ -70,6 +90,7 @@ export declare function showTransmission(options?: SetupOptions): {
|
|
|
70
90
|
status: string;
|
|
71
91
|
application_mode: "advisory" | "defaults";
|
|
72
92
|
enabled: boolean;
|
|
93
|
+
transmission_review: string;
|
|
73
94
|
transmission: import("./automatic-hook.ts").Transmission;
|
|
74
95
|
transmission_source: string;
|
|
75
96
|
})[];
|
package/dist/src/setup.js
CHANGED
|
@@ -10,6 +10,7 @@ import { budgetEnvironmentDefaults, budgetEnvironmentKeys, parseBudgetValue, res
|
|
|
10
10
|
import { Router, defaultPolicy } from './core.js';
|
|
11
11
|
import { loadAutomaticHookPolicy, effectiveTransmission } from './automatic-hook.js';
|
|
12
12
|
import { assertPrivateStatePath } from './files.js';
|
|
13
|
+
import { CODEX_HOME_POLICY_SOURCE, resolvePolicySource } from './policy-source.js';
|
|
13
14
|
import { assertWindowsPrivatePath, protectNewWindowsPrivateDirectory, copyWindowsFilePermissions } from './windows-private.js';
|
|
14
15
|
import { STATISTICS_CONFIG_FILE, STATISTICS_KEY_FILE, STATISTICS_DB_FILE, parseStatisticsConfig, serializeStatisticsConfig, readStatistics } from './statistics.js';
|
|
15
16
|
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -103,7 +104,7 @@ const q = (value) => JSON.stringify(value);
|
|
|
103
104
|
const blockStart = '# aptly managed MCP start v1';
|
|
104
105
|
const blockEnd = '# aptly managed MCP end v1';
|
|
105
106
|
function newTomlBlock(entry) {
|
|
106
|
-
const lines = [blockStart, '[mcp_servers.aptly]', `command = ${q(entry.command)}`, `args = ${JSON.stringify(entry.args)}`,
|
|
107
|
+
const lines = [blockStart, '[mcp_servers.aptly]', `command = ${q(entry.command)}`, `args = ${JSON.stringify(entry.args)}`, `env_vars = ${JSON.stringify(entry.env_vars ?? [])}`, '[mcp_servers.aptly.env]'];
|
|
107
108
|
for (const [key, value] of Object.entries(entry.env))
|
|
108
109
|
lines.push(`${key} = ${q(value)}`);
|
|
109
110
|
return lines.concat(blockEnd, '').join('\n');
|
|
@@ -291,11 +292,54 @@ function updateTomlLauncher(text, entry) {
|
|
|
291
292
|
fail('unsupported_toml_layout');
|
|
292
293
|
return rendered;
|
|
293
294
|
}
|
|
295
|
+
/** Replace an unambiguous env_vars assignment, preserving every existing forwarded name. */
|
|
296
|
+
function updateTomlForwarding(text, names) {
|
|
297
|
+
const original = toml(text), expected = structuredClone(original);
|
|
298
|
+
if (names === undefined)
|
|
299
|
+
delete expected.mcp_servers.aptly.env_vars;
|
|
300
|
+
else
|
|
301
|
+
expected.mcp_servers.aptly.env_vars = names;
|
|
302
|
+
const headers = [...text.matchAll(/^\s*\[([^\n]+)\][ \t]*(?:#[^\n]*)?\r?$/gm)];
|
|
303
|
+
const header = headers.find(h => { try {
|
|
304
|
+
return toml(h[0] + '\naptly_probe = true\n').mcp_servers?.aptly?.aptly_probe === true;
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
return false;
|
|
308
|
+
} });
|
|
309
|
+
if (!header)
|
|
310
|
+
fail('unsupported_toml_layout');
|
|
311
|
+
const start = header.index + header[0].length, end = headers.find(h => h.index > header.index)?.index ?? text.length;
|
|
312
|
+
let body = text.slice(start, end);
|
|
313
|
+
const line = /^[ \t]*env_vars[ \t]*=[^\n]*(?:\n|$)/gm, matches = [...body.matchAll(line)];
|
|
314
|
+
if (matches.length > 1 || (original.mcp_servers.aptly.env_vars !== undefined && matches.length !== 1))
|
|
315
|
+
fail('unsupported_toml_layout');
|
|
316
|
+
if (matches.length)
|
|
317
|
+
body = body.replace(line, () => names === undefined ? '' : `env_vars = ${JSON.stringify(names)}\n`);
|
|
318
|
+
else if (names !== undefined)
|
|
319
|
+
body = '\n' + `env_vars = ${JSON.stringify(names)}\n` + body.replace(/^\r?\n/, '');
|
|
320
|
+
const rendered = text.slice(0, start) + body + text.slice(end);
|
|
321
|
+
if (!isDeepStrictEqual(toml(rendered), expected))
|
|
322
|
+
fail('unsupported_toml_layout');
|
|
323
|
+
return rendered;
|
|
324
|
+
}
|
|
325
|
+
/** CLI commands validate their explicitly selected config home, not a running host. */
|
|
326
|
+
function selectedCliPolicyPath(options) {
|
|
327
|
+
const env = options.env ?? process.env;
|
|
328
|
+
return resolvePolicySource(CODEX_HOME_POLICY_SOURCE, env.CODEX_HOME === undefined ? { ...env, CODEX_HOME: resolved(options, 'codex').dir } : env);
|
|
329
|
+
}
|
|
330
|
+
function policyReferenceMatches(entry, client, policyPath, options) {
|
|
331
|
+
const source = entry.env?.APTLY_HOOK_POLICY_PATH;
|
|
332
|
+
if (source !== CODEX_HOME_POLICY_SOURCE)
|
|
333
|
+
return source === policyPath;
|
|
334
|
+
return client === 'codex' && entry.env?.CODEX_HOME === undefined && Array.isArray(entry.env_vars) && entry.env_vars.every((x) => typeof x === 'string') && entry.env_vars.includes('CODEX_HOME') && selectedCliPolicyPath(options) === policyPath;
|
|
335
|
+
}
|
|
294
336
|
function resolved(options, client) {
|
|
295
337
|
const home = resolve(options.home ?? homedir()), env = options.env ?? process.env;
|
|
296
338
|
const override = client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR;
|
|
297
339
|
if (override && !isAbsolute(override))
|
|
298
340
|
fail('relative_configuration_directory');
|
|
341
|
+
if (client === 'codex' && override !== undefined)
|
|
342
|
+
resolvePolicySource(CODEX_HOME_POLICY_SOURCE, env);
|
|
299
343
|
const dir = override || join(home, client === 'codex' ? '.codex' : '.claude');
|
|
300
344
|
const mcpPath = client === 'codex' ? join(dir, 'config.toml') : override ? join(dir, '.claude.json') : join(home, '.claude.json');
|
|
301
345
|
return { dir, mcpPath, hooksPath: join(dir, client === 'codex' ? 'hooks.json' : 'settings.json'), privateDir: join(dir, 'aptly') };
|
|
@@ -303,6 +347,12 @@ function resolved(options, client) {
|
|
|
303
347
|
function ownership(value, client) {
|
|
304
348
|
if (value.schema_version !== 1 || value.kind !== 'aptly-setup-ownership' || value.client !== client || !object(value.hook) || typeof value.mcp_created !== 'boolean' || !object(value.env_added) || !object(value.policy) || typeof value.policy_created !== 'boolean')
|
|
305
349
|
fail('invalid_ownership');
|
|
350
|
+
if (value.policy_source_previous !== undefined && (client !== 'codex' || value.mcp_created || typeof value.policy_source_previous !== 'string' || !isAbsolute(value.policy_source_previous) || Object.hasOwn(value.env_added, 'APTLY_HOOK_POLICY_PATH')))
|
|
351
|
+
fail('invalid_ownership');
|
|
352
|
+
if (value.env_vars_added !== undefined && (client !== 'codex' || value.mcp_created || !Array.isArray(value.env_vars_added) || value.env_vars_added.length !== 1 || value.env_vars_added[0] !== 'CODEX_HOME'))
|
|
353
|
+
fail('invalid_ownership');
|
|
354
|
+
if (value.env_vars_was_absent !== undefined && (client !== 'codex' || value.mcp_created || typeof value.env_vars_was_absent !== 'boolean' || !value.env_vars_added))
|
|
355
|
+
fail('invalid_ownership');
|
|
306
356
|
return value;
|
|
307
357
|
}
|
|
308
358
|
/** Compatibility restriction only: this does not authenticate arbitrary launcher code. */
|
|
@@ -405,6 +455,18 @@ function prepare(options, client, removing, edit) {
|
|
|
405
455
|
delete servers.aptly.env[key];
|
|
406
456
|
}
|
|
407
457
|
mcp.after = client === 'codex' ? removeTomlEnv(mcp.before ?? '', owned.env_added) : stringify(config);
|
|
458
|
+
if (owned.policy_source_previous !== undefined) {
|
|
459
|
+
if (servers.aptly.env?.APTLY_HOOK_POLICY_PATH !== CODEX_HOME_POLICY_SOURCE)
|
|
460
|
+
fail('managed_entry_changed');
|
|
461
|
+
mcp.after = updateTomlEnv(mcp.after, { APTLY_HOOK_POLICY_PATH: owned.policy_source_previous });
|
|
462
|
+
}
|
|
463
|
+
if (client === 'codex' && owned.env_vars_added?.length) {
|
|
464
|
+
const names = toml(mcp.after).mcp_servers?.aptly?.env_vars;
|
|
465
|
+
if (!Array.isArray(names) || owned.env_vars_added.some(name => names.filter((x) => x === name).length !== 1))
|
|
466
|
+
fail('managed_entry_changed');
|
|
467
|
+
const remaining = names.filter((name) => !owned.env_vars_added.includes(name));
|
|
468
|
+
mcp.after = updateTomlForwarding(mcp.after, owned.env_vars_was_absent && remaining.length === 0 ? undefined : remaining);
|
|
469
|
+
}
|
|
408
470
|
}
|
|
409
471
|
const p = json(policy.before);
|
|
410
472
|
if (!isDeepStrictEqual(p, owned.policy))
|
|
@@ -439,7 +501,9 @@ function prepare(options, client, removing, edit) {
|
|
|
439
501
|
if (!object(servers.aptly))
|
|
440
502
|
fail('mcp_entry_conflict');
|
|
441
503
|
const configuredPolicy = object(servers.aptly.env) ? servers.aptly.env.APTLY_HOOK_POLICY_PATH : undefined;
|
|
442
|
-
|
|
504
|
+
if (oldOwner?.policy_source_previous !== undefined && configuredPolicy !== CODEX_HOME_POLICY_SOURCE)
|
|
505
|
+
fail('managed_entry_changed');
|
|
506
|
+
const mismatch = configuredPolicy !== undefined && !policyReferenceMatches(servers.aptly, client, policyPath, options);
|
|
443
507
|
const detail = mismatch && typeof configuredPolicy === 'string' && configuredPolicy.length > 0 ? {
|
|
444
508
|
policy_location: configuredPolicy === join(resolve(options.home ?? homedir()), client === 'codex' ? '.codex' : '.claude', 'aptly', 'auto-policy.json') ? 'default_home' : 'elsewhere',
|
|
445
509
|
selected_home_source: (client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR) ? 'override' : 'default',
|
|
@@ -457,7 +521,7 @@ function prepare(options, client, removing, edit) {
|
|
|
457
521
|
servers.aptly.command = process.execPath;
|
|
458
522
|
servers.aptly.args = [join(root, 'dist', 'src', 'server.js')];
|
|
459
523
|
}
|
|
460
|
-
if (edit && ('credential' in edit || 'migrate' in edit))
|
|
524
|
+
if ((edit && ('credential' in edit || 'migrate' in edit)) || servers.aptly.env?.APTLY_HOOK_POLICY_PATH === CODEX_HOME_POLICY_SOURCE)
|
|
461
525
|
requireCredentialRuntime(servers.aptly, root);
|
|
462
526
|
const currentEnv = map(servers.aptly, 'env');
|
|
463
527
|
const originalEnvKeys = new Set(Object.keys(currentEnv)), inheritedBudget = budgetInheritance(servers.aptly, env, client);
|
|
@@ -563,6 +627,14 @@ function prepare(options, client, removing, edit) {
|
|
|
563
627
|
result.transmission = effectiveTransmission(policyValue);
|
|
564
628
|
result.transmission_source = policyValue.schema_version === 1 ? 'legacy' : policyValue.transmission === 'unselected' ? 'unselected' : 'explicit';
|
|
565
629
|
manifest.after = stringify(owner);
|
|
630
|
+
const review = transmissionReviewSnapshot(options, client);
|
|
631
|
+
observations.push(review);
|
|
632
|
+
if (requestedScope !== undefined) {
|
|
633
|
+
review.after = transmissionReviewMarker(options, client, policyValue);
|
|
634
|
+
if (review.after !== review.before)
|
|
635
|
+
changes.push(review);
|
|
636
|
+
}
|
|
637
|
+
result.transmission_review = reviewMatches(review.after, options, client, policyValue) ? 'complete' : 'required';
|
|
566
638
|
if (client === 'codex')
|
|
567
639
|
result.requires_hook_review = true;
|
|
568
640
|
result.codes = [...(client === 'codex' ? ['requires_hook_review'] : []), ...(result.transmission === 'unselected' ? ['transmission_selection_required'] : result.transmission_source === 'legacy' ? ['legacy_transmission_excerpt'] : []), ...(requestedScope !== undefined || result.budget?.restart_required ? ['mcp_restart_required'] : [])];
|
|
@@ -576,12 +648,17 @@ function prepare(options, client, removing, edit) {
|
|
|
576
648
|
changes.push(snapshot);
|
|
577
649
|
if (!removing && changes.length)
|
|
578
650
|
result.status = 'configured';
|
|
651
|
+
const markerIndex = changes.findIndex(item => item.reviewPrivate);
|
|
652
|
+
if (markerIndex >= 0)
|
|
653
|
+
changes.push(...changes.splice(markerIndex, 1));
|
|
579
654
|
return { changes, observations, dirs, result };
|
|
580
655
|
}
|
|
581
656
|
/** Secure sibling staging is short-lived and never a backup; original settings stay in memory. */
|
|
582
657
|
function replace(snapshot, forward) {
|
|
583
658
|
const expected = forward ? snapshot.before : snapshot.after, next = forward ? snapshot.after : snapshot.before;
|
|
584
659
|
const check = () => {
|
|
660
|
+
if (snapshot.reviewPrivate)
|
|
661
|
+
validateReviewPrivate(snapshot.path);
|
|
585
662
|
const current = read(snapshot.path);
|
|
586
663
|
if (current.text !== expected || (process.platform !== 'win32' && expected !== null && current.mode !== snapshot.mode))
|
|
587
664
|
fail('concurrent_configuration_change');
|
|
@@ -715,7 +792,7 @@ function execute(options, removing, edit, captured) {
|
|
|
715
792
|
}
|
|
716
793
|
return { status: results.some(result => result.status === 'error') ? 'partial' : results.every(result => result.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
717
794
|
}
|
|
718
|
-
const codes = new Set(['statistics_requires_setup', 'statistics_policy_conflict', 'statistics_config_invalid', 'statistics_ownership_invalid', 'statistics_observers_present', 'statistics_key_missing', 'statistics_shared_state', 'statistics_platform_unsupported', 'statistics_invalid_options', 'statistics_observer_missing', 'unsafe_ledger', 'invalid_ledger', 'budget_ledger_unconfigured', 'invalid_budget_configuration', 'ledger_locked', 'ledger_error', 'transmission_selection_changed', 'transmission_invalid_scope', 'launcher_migration_not_owned', 'launcher_migration_not_standard', 'credential_launcher_unverified', 'environment_invalid_value', 'environment_sensitive_value', 'environment_key_unsupported', 'environment_secret_key_unsupported', 'unsafe_directory', 'unsafe_symlink', 'unsafe_configuration_file', 'invalid_json', 'invalid_json_object', 'configuration_shape_conflict', 'hook_shape_conflict', 'invalid_toml', 'unsupported_toml_layout', 'relative_configuration_directory', 'invalid_ownership', 'managed_hook_changed', 'managed_mcp_changed', 'managed_entry_changed', 'managed_policy_changed', 'mcp_entry_conflict', 'mcp_environment_conflict', 'existing_routing_hook_conflict', 'policy_conflict', 'existing_hook_not_owned', 'concurrent_configuration_change', 'private_directory_permissions', 'private_file_permissions']);
|
|
795
|
+
const codes = new Set(['policy_source_home_invalid', 'policy_source_requires_setup', 'policy_source_invalid_options', 'transmission_review_requires_setup', 'transmission_review_invalid_options', 'statistics_requires_setup', 'statistics_policy_conflict', 'statistics_config_invalid', 'statistics_ownership_invalid', 'statistics_observers_present', 'statistics_key_missing', 'statistics_shared_state', 'statistics_platform_unsupported', 'statistics_invalid_options', 'statistics_observer_missing', 'unsafe_ledger', 'invalid_ledger', 'budget_ledger_unconfigured', 'invalid_budget_configuration', 'ledger_locked', 'ledger_error', 'transmission_selection_changed', 'transmission_invalid_scope', 'launcher_migration_not_owned', 'launcher_migration_not_standard', 'credential_launcher_unverified', 'environment_invalid_value', 'environment_sensitive_value', 'environment_key_unsupported', 'environment_secret_key_unsupported', 'unsafe_directory', 'unsafe_symlink', 'unsafe_configuration_file', 'invalid_json', 'invalid_json_object', 'configuration_shape_conflict', 'hook_shape_conflict', 'invalid_toml', 'unsupported_toml_layout', 'relative_configuration_directory', 'invalid_ownership', 'managed_hook_changed', 'managed_mcp_changed', 'managed_entry_changed', 'managed_policy_changed', 'mcp_entry_conflict', 'mcp_environment_conflict', 'existing_routing_hook_conflict', 'policy_conflict', 'existing_hook_not_owned', 'concurrent_configuration_change', 'private_directory_permissions', 'private_file_permissions']);
|
|
719
796
|
function safeCode(error) { return error instanceof Error && codes.has(error.message) ? error.message : 'configuration_io_error'; }
|
|
720
797
|
export function setupHosts(options = {}) { return execute(options, false); }
|
|
721
798
|
/** Snapshot the normal setup plan without applying it; it does not verify a running host. */
|
|
@@ -750,8 +827,12 @@ export function setCredentialReference(options = {}) { return execute(options, f
|
|
|
750
827
|
/** Include unchanged files: a no-op reference update must still detect prompt-time edits. */
|
|
751
828
|
function validateObservations(plan, written = []) {
|
|
752
829
|
for (const snapshot of plan.observations) {
|
|
830
|
+
if (snapshot.reviewPrivate)
|
|
831
|
+
validateReviewPrivate(snapshot.path);
|
|
753
832
|
const current = read(snapshot.path);
|
|
754
833
|
const expected = written.includes(snapshot) ? snapshot.after : snapshot.before;
|
|
834
|
+
if (!written.includes(snapshot) && snapshot.identity && reviewIdentity(snapshot.path) !== snapshot.identity)
|
|
835
|
+
fail('concurrent_configuration_change');
|
|
755
836
|
if (current.text !== expected || (process.platform !== 'win32' && expected !== null && current.mode !== snapshot.mode))
|
|
756
837
|
fail('concurrent_configuration_change');
|
|
757
838
|
}
|
|
@@ -833,12 +914,274 @@ export function migrateLauncher(options, dryRun = false, includeExisting = false
|
|
|
833
914
|
return { status: 'partial', clients: [errorResult(client, error)] };
|
|
834
915
|
}
|
|
835
916
|
}
|
|
917
|
+
/** Explicitly select a per-Codex-home policy without moving any state. */
|
|
918
|
+
export function setPolicySource(options, dryRun = false) {
|
|
919
|
+
if (options.clients?.length !== 1 || options.clients[0] !== 'codex' || options.automatic !== undefined || options.mode !== undefined || options.transmission !== undefined || options.selectUnselectedOnly !== undefined)
|
|
920
|
+
return { status: 'partial', clients: [{ client: 'codex', status: 'error', codes: ['policy_source_invalid_options'] }] };
|
|
921
|
+
const client = 'codex';
|
|
922
|
+
try {
|
|
923
|
+
const paths = resolved(options, client), policyPath = join(paths.privateDir, 'auto-policy.json');
|
|
924
|
+
// Validate the selector even when CODEX_HOME is present but empty.
|
|
925
|
+
if (selectedCliPolicyPath(options) !== policyPath)
|
|
926
|
+
fail('policy_source_home_invalid');
|
|
927
|
+
const snap = (path) => { const file = read(path); return { path, before: file.text, after: file.text, mode: file.mode }; };
|
|
928
|
+
const mcp = snap(paths.mcpPath), hooks = snap(paths.hooksPath), policy = snap(policyPath), manifest = snap(join(paths.privateDir, 'setup-ownership.json'));
|
|
929
|
+
for (const dir of [paths.privateDir, join(paths.privateDir, 'state')]) {
|
|
930
|
+
try {
|
|
931
|
+
checkedDirectory(dir);
|
|
932
|
+
privatePermissions(dir, 'private_directory_permissions');
|
|
933
|
+
}
|
|
934
|
+
catch (e) {
|
|
935
|
+
if (e.code !== 'ENOENT')
|
|
936
|
+
throw e;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (policy.before === null || manifest.before === null || mcp.before === null || hooks.before === null)
|
|
940
|
+
fail('policy_source_requires_setup');
|
|
941
|
+
privatePermissions(policy.path, 'private_file_permissions');
|
|
942
|
+
privatePermissions(manifest.path, 'private_file_permissions');
|
|
943
|
+
const owner = ownership(json(manifest.before), client), config = toml(mcp.before), entry = config.mcp_servers?.aptly;
|
|
944
|
+
if (!object(entry) || !object(entry.env))
|
|
945
|
+
fail('mcp_entry_conflict');
|
|
946
|
+
if (!hooksArray(json(hooks.before)).some(item => isDeepStrictEqual(item, owner.hook)))
|
|
947
|
+
fail('managed_hook_changed');
|
|
948
|
+
if (!loadAutomaticHookPolicy(policyPath).policy || !isDeepStrictEqual(json(policy.before), owner.policy))
|
|
949
|
+
fail('managed_policy_changed');
|
|
950
|
+
const root = resolve(options.packageRoot ?? join(dirname(fileURLToPath(import.meta.url)), '..', ...(import.meta.url.includes('/dist/src/') ? ['..'] : [])));
|
|
951
|
+
requireCredentialRuntime(entry, root);
|
|
952
|
+
if (entry.env.CODEX_HOME !== undefined)
|
|
953
|
+
fail('mcp_environment_conflict');
|
|
954
|
+
if (entry.env_vars !== undefined && (!Array.isArray(entry.env_vars) || entry.env_vars.some((v) => typeof v !== 'string')))
|
|
955
|
+
fail('configuration_shape_conflict');
|
|
956
|
+
const source = entry.env.APTLY_HOOK_POLICY_PATH, ownedSource = owner.mcp_created ? owner.mcp?.env?.APTLY_HOOK_POLICY_PATH : owner.env_added.APTLY_HOOK_POLICY_PATH;
|
|
957
|
+
const defaultPath = join(resolve(options.home ?? homedir()), '.codex', 'aptly', 'auto-policy.json');
|
|
958
|
+
if (![policyPath, defaultPath, CODEX_HOME_POLICY_SOURCE].includes(source) || (ownedSource !== undefined && ![policyPath, defaultPath, CODEX_HOME_POLICY_SOURCE].includes(ownedSource)) || (owner.mcp_created && ownedSource === undefined))
|
|
959
|
+
fail('managed_entry_changed');
|
|
960
|
+
const vars = entry.env_vars ?? [];
|
|
961
|
+
if (owner.mcp_created) {
|
|
962
|
+
if (!object(owner.mcp) || !owner.toml_block)
|
|
963
|
+
fail('invalid_ownership');
|
|
964
|
+
const expected = structuredClone(owner.mcp);
|
|
965
|
+
expected.env.APTLY_HOOK_POLICY_PATH = source;
|
|
966
|
+
expected.env_vars = vars;
|
|
967
|
+
const priorVars = owner.mcp.env_vars ?? [];
|
|
968
|
+
if (!isDeepStrictEqual(vars, priorVars) && !isDeepStrictEqual(vars, [...priorVars, 'CODEX_HOME']))
|
|
969
|
+
fail('managed_mcp_changed');
|
|
970
|
+
if (!isDeepStrictEqual(expected, entry))
|
|
971
|
+
fail('managed_mcp_changed');
|
|
972
|
+
const previousBlock = newTomlBlock(entry);
|
|
973
|
+
if (!mcp.before.includes(owner.toml_block) && !mcp.before.includes(previousBlock))
|
|
974
|
+
fail('managed_mcp_changed');
|
|
975
|
+
entry.env.APTLY_HOOK_POLICY_PATH = CODEX_HOME_POLICY_SOURCE;
|
|
976
|
+
if (!vars.includes('CODEX_HOME'))
|
|
977
|
+
entry.env_vars = [...vars, 'CODEX_HOME'];
|
|
978
|
+
const nextBlock = newTomlBlock(entry), oldBlock = mcp.before.includes(owner.toml_block) ? owner.toml_block : previousBlock;
|
|
979
|
+
mcp.after = mcp.before.replace(oldBlock, nextBlock);
|
|
980
|
+
if (!isDeepStrictEqual(toml(mcp.after), config))
|
|
981
|
+
fail('managed_mcp_changed');
|
|
982
|
+
owner.mcp = structuredClone(entry);
|
|
983
|
+
owner.toml_block = nextBlock;
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
for (const [key, value] of Object.entries(owner.env_added))
|
|
987
|
+
if (key !== 'APTLY_HOOK_POLICY_PATH' && entry.env[key] !== value)
|
|
988
|
+
fail('managed_entry_changed');
|
|
989
|
+
if (owner.policy_source_previous !== undefined && source !== CODEX_HOME_POLICY_SOURCE)
|
|
990
|
+
fail('managed_entry_changed');
|
|
991
|
+
const preexistingSelector = ownedSource === undefined && owner.policy_source_previous === undefined && source === CODEX_HOME_POLICY_SOURCE;
|
|
992
|
+
if (!vars.includes('CODEX_HOME')) {
|
|
993
|
+
if (owner.env_vars_added?.length)
|
|
994
|
+
fail('managed_entry_changed');
|
|
995
|
+
mcp.after = updateTomlForwarding(mcp.after, [...vars, 'CODEX_HOME']);
|
|
996
|
+
owner.env_vars_added = [...(owner.env_vars_added ?? []), 'CODEX_HOME'];
|
|
997
|
+
if (entry.env_vars === undefined)
|
|
998
|
+
owner.env_vars_was_absent = true;
|
|
999
|
+
}
|
|
1000
|
+
mcp.after = updateTomlEnv(mcp.after, { APTLY_HOOK_POLICY_PATH: CODEX_HOME_POLICY_SOURCE });
|
|
1001
|
+
if (ownedSource !== undefined)
|
|
1002
|
+
owner.env_added.APTLY_HOOK_POLICY_PATH = CODEX_HOME_POLICY_SOURCE;
|
|
1003
|
+
else if (!preexistingSelector && owner.policy_source_previous === undefined)
|
|
1004
|
+
owner.policy_source_previous = source;
|
|
1005
|
+
}
|
|
1006
|
+
manifest.after = stringify(owner);
|
|
1007
|
+
const changes = [mcp, manifest].filter(item => item.before !== item.after);
|
|
1008
|
+
const plan = { changes, observations: [mcp, hooks, policy, manifest], dirs: [], result: { client, status: changes.length ? 'configured' : 'unchanged', codes: changes.length ? ['policy_source_selected', 'mcp_restart_required'] : ['policy_source_current'] } };
|
|
1009
|
+
if (dryRun)
|
|
1010
|
+
return { status: 'complete', clients: [{ ...plan.result, status: 'unchanged', codes: [changes.length ? 'policy_source_selection_available' : 'policy_source_current'] }] };
|
|
1011
|
+
return execute(options, false, { migrate: true }, [plan]);
|
|
1012
|
+
}
|
|
1013
|
+
catch (error) {
|
|
1014
|
+
return { status: 'partial', clients: [errorResult(client, error)] };
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
836
1017
|
/** Explicit operator change; updates policy and its receipt through normal guarded staging. */
|
|
837
1018
|
export function setTransmission(scope, options = {}) {
|
|
838
1019
|
if (!['none', 'description', 'excerpt'].includes(scope))
|
|
839
1020
|
return { status: 'partial', clients: (options.clients ?? ['codex', 'claude']).map(client => ({ client, status: 'error', codes: ['transmission_invalid_scope'] })) };
|
|
840
1021
|
return execute(options, false, { transmission: scope });
|
|
841
1022
|
}
|
|
1023
|
+
const TRANSMISSION_REVIEW_FILE = 'transmission-review.json';
|
|
1024
|
+
function reviewIdentity(path) {
|
|
1025
|
+
try {
|
|
1026
|
+
const stat = lstatSync(path);
|
|
1027
|
+
return `${stat.dev}:${stat.ino}:${stat.uid}:${stat.nlink}`;
|
|
1028
|
+
}
|
|
1029
|
+
catch (error) {
|
|
1030
|
+
if (error.code === 'ENOENT')
|
|
1031
|
+
return 'missing';
|
|
1032
|
+
throw error;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function validateReviewPrivate(path) {
|
|
1036
|
+
noSymlinks(path);
|
|
1037
|
+
for (const [target, directory] of [[dirname(path), true], [path, false]]) {
|
|
1038
|
+
try {
|
|
1039
|
+
const stat = lstatSync(target);
|
|
1040
|
+
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile() || stat.nlink !== 1))
|
|
1041
|
+
fail('unsafe_configuration_file');
|
|
1042
|
+
if (process.platform !== 'win32' && process.getuid && stat.uid !== process.getuid())
|
|
1043
|
+
fail(directory ? 'private_directory_permissions' : 'private_file_permissions');
|
|
1044
|
+
privatePermissions(target, directory ? 'private_directory_permissions' : 'private_file_permissions');
|
|
1045
|
+
}
|
|
1046
|
+
catch (error) {
|
|
1047
|
+
if (error.code !== 'ENOENT')
|
|
1048
|
+
throw error;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function transmissionReviewSnapshot(options, client) {
|
|
1053
|
+
const path = join(resolved(options, client).privateDir, TRANSMISSION_REVIEW_FILE);
|
|
1054
|
+
validateReviewPrivate(path);
|
|
1055
|
+
const source = read(path);
|
|
1056
|
+
return { path, before: source.text, after: source.text, mode: source.mode, reviewPrivate: true, identity: reviewIdentity(path) };
|
|
1057
|
+
}
|
|
1058
|
+
function transmissionReviewMarker(options, client, policy) {
|
|
1059
|
+
const paths = resolved(options, client), scope = effectiveTransmission(policy);
|
|
1060
|
+
// A local UI acknowledgement, not authentication or authorization of host code.
|
|
1061
|
+
const binding = { selected_home: resolve(paths.dir), policyPath: join(paths.privateDir, 'auto-policy.json'),
|
|
1062
|
+
state_directory: resolve(policy.state_directory), schema_version: policy.schema_version, effective_scope: scope,
|
|
1063
|
+
provenance: policy.schema_version === 1 ? 'legacy' : scope === 'unselected' ? 'unselected' : 'explicit' };
|
|
1064
|
+
return stringify({ schema_version: 1, revision: 1, client, binding_sha256: createHash('sha256').update(JSON.stringify(binding)).digest('hex') });
|
|
1065
|
+
}
|
|
1066
|
+
function reviewMatches(text, options, client, policy) {
|
|
1067
|
+
if (text === null || effectiveTransmission(policy) === 'unselected')
|
|
1068
|
+
return false;
|
|
1069
|
+
try {
|
|
1070
|
+
return isDeepStrictEqual(JSON.parse(text), JSON.parse(transmissionReviewMarker(options, client, policy)));
|
|
1071
|
+
}
|
|
1072
|
+
catch {
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
/** Read-only, two-phase local acknowledgement. Recheck every captured host before writing. */
|
|
1077
|
+
export function prepareTransmissionReview(options = {}) {
|
|
1078
|
+
options = { ...options, home: resolve(options.home ?? homedir()), env: { ...(options.env ?? process.env) }, ...(options.clients ? { clients: [...options.clients] } : {}) };
|
|
1079
|
+
const clients = [...new Set(options.clients ?? ['codex', 'claude'])];
|
|
1080
|
+
const plans = [], candidates = [];
|
|
1081
|
+
if (!clients.length || clients.some(client => !['codex', 'claude'].includes(client)) || options.automatic !== undefined || options.mode !== undefined || options.transmission !== undefined || options.selectUnselectedOnly !== undefined) {
|
|
1082
|
+
const result = { status: 'partial', clients: clients.map(client => ({ client, status: 'error', codes: ['transmission_review_invalid_options'] })) };
|
|
1083
|
+
return { result, candidates: [], apply: () => result };
|
|
1084
|
+
}
|
|
1085
|
+
const results = clients.map(client => {
|
|
1086
|
+
try {
|
|
1087
|
+
const paths = resolved(options, client), policyPath = join(paths.privateDir, 'auto-policy.json');
|
|
1088
|
+
const mcp = read(paths.mcpPath), config = client === 'codex' ? toml(mcp.text ?? '') : json(mcp.text);
|
|
1089
|
+
const entry = config[client === 'codex' ? 'mcp_servers' : 'mcpServers']?.aptly;
|
|
1090
|
+
const policySource = read(policyPath), ownerSource = read(join(paths.privateDir, 'setup-ownership.json'));
|
|
1091
|
+
if (entry === undefined && policySource.text === null && ownerSource.text === null)
|
|
1092
|
+
return { client, status: 'skipped', codes: ['host_not_configured'] };
|
|
1093
|
+
if (!object(entry) || !policyReferenceMatches(entry, client, policyPath, options) || policySource.text === null || ownerSource.text === null)
|
|
1094
|
+
fail('transmission_review_requires_setup');
|
|
1095
|
+
const loaded = loadAutomaticHookPolicy(policyPath);
|
|
1096
|
+
if (!loaded.policy)
|
|
1097
|
+
fail('policy_conflict');
|
|
1098
|
+
const policy = loaded.policy, owner = ownership(json(ownerSource.text), client);
|
|
1099
|
+
if (!isDeepStrictEqual(policy, owner.policy))
|
|
1100
|
+
fail('managed_policy_changed');
|
|
1101
|
+
const hooksSource = read(paths.hooksPath), hookSettings = json(hooksSource.text);
|
|
1102
|
+
if (!Array.isArray(hookSettings.hooks?.PreToolUse) || !hookSettings.hooks.PreToolUse.some((value) => isDeepStrictEqual(value, owner.hook)) || !isDeepStrictEqual(owner.hook, hook(client)))
|
|
1103
|
+
fail('transmission_review_requires_setup');
|
|
1104
|
+
if (!object(entry.env) || entry.env.ROUTER_LEDGER_PATH === undefined)
|
|
1105
|
+
fail('transmission_review_requires_setup');
|
|
1106
|
+
// Use the existing explicit-change validator without executing a setup repair.
|
|
1107
|
+
const plan = prepare(options, client, false, { transmission: effectiveTransmission(policy) === 'unselected' ? 'none' : effectiveTransmission(policy) });
|
|
1108
|
+
for (const [path, source] of [[paths.mcpPath, mcp], [policyPath, policySource], [join(paths.privateDir, 'setup-ownership.json'), ownerSource], [paths.hooksPath, hooksSource]]) {
|
|
1109
|
+
const captured = plan.observations.find(snapshot => snapshot.path === path);
|
|
1110
|
+
if (!captured || captured.before !== source.text || captured.mode !== source.mode)
|
|
1111
|
+
fail('concurrent_configuration_change');
|
|
1112
|
+
}
|
|
1113
|
+
for (const snapshot of plan.observations) {
|
|
1114
|
+
snapshot.identity = reviewIdentity(snapshot.path);
|
|
1115
|
+
if (snapshot.path === policyPath || snapshot.path === join(paths.privateDir, 'setup-ownership.json')) {
|
|
1116
|
+
validateReviewPrivate(snapshot.path);
|
|
1117
|
+
snapshot.reviewPrivate = true;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
const review = plan.observations.find(snapshot => snapshot.path === join(paths.privateDir, TRANSMISSION_REVIEW_FILE));
|
|
1121
|
+
const complete = reviewMatches(review.before, options, client, policy);
|
|
1122
|
+
const state = { client, status: 'unchanged', codes: [complete ? 'transmission_review_complete' : 'transmission_review_required'], transmission_review: complete ? 'complete' : 'required', transmission: effectiveTransmission(policy), transmission_source: policy.schema_version === 1 ? 'legacy' : effectiveTransmission(policy) === 'unselected' ? 'unselected' : 'explicit' };
|
|
1123
|
+
if (!complete || options.forceReview) {
|
|
1124
|
+
plans.push({ ...plan, changes: [], dirs: [], result: state });
|
|
1125
|
+
candidates.push({ client, transmission: effectiveTransmission(policy), transmission_source: state.transmission_source, selected_home_source: (client === 'codex' ? (options.env ?? process.env).CODEX_HOME : (options.env ?? process.env).CLAUDE_CONFIG_DIR) ? 'override' : 'default', application_mode: policy.mode, enabled: policy.enabled });
|
|
1126
|
+
}
|
|
1127
|
+
return state;
|
|
1128
|
+
}
|
|
1129
|
+
catch (error) {
|
|
1130
|
+
return errorResult(client, error);
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
const result = { status: results.some(value => value.status === 'error') ? 'partial' : results.every(value => value.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
1134
|
+
if (result.status === 'partial') {
|
|
1135
|
+
result.clients = results.map(initial => plans.some(plan => plan.result.client === initial.client) ? { ...initial, status: 'skipped', codes: ['other_host_validation_failed'] } : initial);
|
|
1136
|
+
return { result, candidates: [], apply: () => result };
|
|
1137
|
+
}
|
|
1138
|
+
return { result, candidates, apply: (choice) => {
|
|
1139
|
+
const merge = (updates, status) => ({ status, clients: results.map(initial => updates.find(updated => updated.client === initial.client) ?? initial) });
|
|
1140
|
+
if (!['keep', 'none', 'description', 'excerpt'].includes(choice))
|
|
1141
|
+
return merge(plans.map(plan => ({ ...plan.result, status: 'error', codes: ['transmission_invalid_scope'] })), 'partial');
|
|
1142
|
+
if (!plans.length)
|
|
1143
|
+
return result;
|
|
1144
|
+
const commits = [];
|
|
1145
|
+
const failures = [];
|
|
1146
|
+
// All preflight checks precede every write; commits retain per-client rollback.
|
|
1147
|
+
for (const plan of plans) {
|
|
1148
|
+
const client = plan.result.client;
|
|
1149
|
+
try {
|
|
1150
|
+
validateObservations(plan);
|
|
1151
|
+
const currentPolicy = loadAutomaticHookPolicy(join(resolved(options, client).privateDir, 'auto-policy.json')).policy;
|
|
1152
|
+
if (!currentPolicy)
|
|
1153
|
+
fail('policy_conflict');
|
|
1154
|
+
if ((choice === 'keep' && effectiveTransmission(currentPolicy) !== 'unselected') || (currentPolicy.schema_version === 2 && choice === effectiveTransmission(currentPolicy))) {
|
|
1155
|
+
const marker = plan.observations.find(snapshot => snapshot.path === join(resolved(options, client).privateDir, TRANSMISSION_REVIEW_FILE));
|
|
1156
|
+
marker.after = transmissionReviewMarker(options, client, currentPolicy);
|
|
1157
|
+
commits.push({ ...plan, changes: marker.before === marker.after ? [] : [marker], result: { ...plan.result, status: marker.before === marker.after ? 'unchanged' : 'configured', codes: ['transmission_review_complete'], transmission_review: 'complete' } });
|
|
1158
|
+
}
|
|
1159
|
+
else {
|
|
1160
|
+
const scope = choice === 'keep' ? 'none' : choice;
|
|
1161
|
+
const next = prepare(options, client, false, { transmission: scope });
|
|
1162
|
+
validateObservations(plan);
|
|
1163
|
+
for (const original of plan.observations) {
|
|
1164
|
+
const fresh = next.observations.find(snapshot => snapshot.path === original.path);
|
|
1165
|
+
if (!fresh || fresh.before !== original.before || fresh.mode !== original.mode)
|
|
1166
|
+
fail('concurrent_configuration_change');
|
|
1167
|
+
}
|
|
1168
|
+
// Capture the original prompt-time observations, including unchanged files.
|
|
1169
|
+
next.observations = plan.observations.map(original => next.observations.find(snapshot => snapshot.path === original.path) ? Object.assign(next.observations.find(snapshot => snapshot.path === original.path), { identity: original.identity, reviewPrivate: original.reviewPrivate }) : original);
|
|
1170
|
+
next.dirs = [];
|
|
1171
|
+
next.result.codes.push('transmission_review_complete');
|
|
1172
|
+
commits.push(next);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
catch (error) {
|
|
1176
|
+
failures.push({ ...plan.result, ...errorResult(client, error) });
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if (failures.length)
|
|
1180
|
+
return merge(plans.map(plan => failures.find(failed => failed.client === plan.result.client) ?? { ...plan.result, status: 'skipped', codes: ['other_host_validation_failed'] }), 'partial');
|
|
1181
|
+
const applied = execute({ ...options, clients: plans.map(plan => plan.result.client) }, false, undefined, commits);
|
|
1182
|
+
return merge(applied.clients, applied.status);
|
|
1183
|
+
} };
|
|
1184
|
+
}
|
|
842
1185
|
/** Read-only redacted policy state. Does not create host directories or contact a provider. */
|
|
843
1186
|
export function showTransmission(options = {}) {
|
|
844
1187
|
return { clients: (options.clients ?? ['codex', 'claude']).map(client => {
|
|
@@ -849,6 +1192,7 @@ export function showTransmission(options = {}) {
|
|
|
849
1192
|
if (!loaded.policy)
|
|
850
1193
|
return { client, status: 'unavailable', code: loaded.reason };
|
|
851
1194
|
return { client, status: 'configured', application_mode: loaded.policy.mode, enabled: loaded.policy.enabled,
|
|
1195
|
+
transmission_review: reviewMatches(transmissionReviewSnapshot(options, client).before, options, client, loaded.policy) ? 'complete' : 'required',
|
|
852
1196
|
transmission: effectiveTransmission(loaded.policy), transmission_source: loaded.policy.schema_version === 1 ? 'legacy' : effectiveTransmission(loaded.policy) === 'unselected' ? 'unselected' : 'explicit' };
|
|
853
1197
|
}
|
|
854
1198
|
catch (error) {
|
|
@@ -926,7 +1270,7 @@ function statisticsPolicy(options, client, requireRegistration = true) {
|
|
|
926
1270
|
const entry = config[client === 'codex' ? 'mcp_servers' : 'mcpServers']?.aptly;
|
|
927
1271
|
if (!object(entry))
|
|
928
1272
|
fail('statistics_requires_setup');
|
|
929
|
-
if (entry
|
|
1273
|
+
if (!policyReferenceMatches(entry, client, policyPath, options))
|
|
930
1274
|
fail('statistics_policy_conflict');
|
|
931
1275
|
}
|
|
932
1276
|
const loaded = loadAutomaticHookPolicy(policyPath);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SetupOptions, type SetupResult } from './setup.ts';
|
|
2
|
+
import { type TransmissionPromptCandidate, type TransmissionReviewChoice } from './cli-input.ts';
|
|
3
|
+
interface ReviewDependencies {
|
|
4
|
+
interactive?: boolean;
|
|
5
|
+
readChoice?: (candidates: readonly TransmissionPromptCandidate[]) => Promise<TransmissionReviewChoice>;
|
|
6
|
+
}
|
|
7
|
+
/** CLI-only orchestration: never called by MCP, Hooks, updater or read-only commands. */
|
|
8
|
+
export declare function runTransmissionReview(options?: SetupOptions, forceReview?: boolean, dependencies?: ReviewDependencies): Promise<SetupResult>;
|
|
9
|
+
/** Preserve the completed base setup result while exposing the separate review outcome. */
|
|
10
|
+
export declare function reviewAfterSetup(base: SetupResult, options?: SetupOptions, dependencies?: ReviewDependencies): Promise<SetupResult>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { prepareTransmissionReview } from './setup.js';
|
|
2
|
+
import { canPromptTransmission, readTransmissionReviewChoice } from './cli-input.js';
|
|
3
|
+
/** CLI-only orchestration: never called by MCP, Hooks, updater or read-only commands. */
|
|
4
|
+
export async function runTransmissionReview(options = {}, forceReview = false, dependencies = {}) {
|
|
5
|
+
const interactive = dependencies.interactive ?? canPromptTransmission();
|
|
6
|
+
if (forceReview && !interactive)
|
|
7
|
+
throw new Error('set_interactive_input_required');
|
|
8
|
+
const prepared = prepareTransmissionReview({ ...options, forceReview });
|
|
9
|
+
if (prepared.result.status !== 'complete' || !prepared.candidates.length || !interactive)
|
|
10
|
+
return prepared.result;
|
|
11
|
+
const choice = await (dependencies.readChoice ?? readTransmissionReviewChoice)(prepared.candidates);
|
|
12
|
+
return prepared.apply(choice);
|
|
13
|
+
}
|
|
14
|
+
/** Preserve the completed base setup result while exposing the separate review outcome. */
|
|
15
|
+
export async function reviewAfterSetup(base, options = {}, dependencies = {}) {
|
|
16
|
+
if (base.status !== 'complete')
|
|
17
|
+
return base;
|
|
18
|
+
const clients = base.clients.filter(c => c.status === 'configured' || c.status === 'unchanged').map(c => c.client);
|
|
19
|
+
if (!clients.length)
|
|
20
|
+
return base;
|
|
21
|
+
const review = await runTransmissionReview({ ...options, clients }, false, dependencies);
|
|
22
|
+
return { status: review.status === 'partial' ? 'partial' : base.status, clients: base.clients.map(previous => {
|
|
23
|
+
const next = review.clients.find(c => c.client === previous.client);
|
|
24
|
+
if (!next)
|
|
25
|
+
return previous;
|
|
26
|
+
let codes = [...new Set([...previous.codes, ...next.codes])];
|
|
27
|
+
if (next.transmission_review === 'complete')
|
|
28
|
+
codes = codes.filter(c => c !== 'transmission_review_required');
|
|
29
|
+
if (next.transmission !== undefined && next.transmission !== 'unselected')
|
|
30
|
+
codes = codes.filter(c => c !== 'transmission_selection_required');
|
|
31
|
+
if (next.transmission_source !== undefined && next.transmission_source !== 'legacy')
|
|
32
|
+
codes = codes.filter(c => c !== 'legacy_transmission_excerpt');
|
|
33
|
+
return { ...previous, ...next, status: next.status === 'unchanged' ? previous.status : next.status, codes };
|
|
34
|
+
}) };
|
|
35
|
+
}
|
|
@@ -23,7 +23,7 @@ function newer(candidate, current) {
|
|
|
23
23
|
}
|
|
24
24
|
function eligible(o) {
|
|
25
25
|
return o.stdinIsTTY && o.stderrIsTTY && o.stdoutIsTTY !== false && !o.env.CI && o.env.APTLY_NO_UPDATE_NOTIFIER !== '1' && !!version(o.currentVersion) &&
|
|
26
|
-
['--version', 'config', 'setup', 'remove', 'set', 'report'].includes(o.command) && !o.args.some(arg => arg === '--help' || arg === '-h') && !o.args.includes('--automatic') && !o.args.includes('--check') && !(o.command === 'set' && o.args[0] === 'transmission' && o.args.includes('--show'));
|
|
26
|
+
['--version', 'config', 'setup', 'remove', 'set', 'report'].includes(o.command) && !o.args.some(arg => arg === '--help' || arg === '-h') && !o.args.includes('--automatic') && !o.args.includes('--check') && !o.args.includes('--dry-run') && !(o.command === 'set' && o.args[0] === 'transmission' && o.args.includes('--show'));
|
|
27
27
|
}
|
|
28
28
|
function directory(path) {
|
|
29
29
|
if (!isAbsolute(path))
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.12";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.12';
|
package/docs/ADVISORY_USAGE.md
CHANGED
|
@@ -191,6 +191,6 @@ live 분류는 비용이 발생할 수 있어요. 원장은 요청 전에 예약
|
|
|
191
191
|
- `ledger_locked`이면 같은 원장을 쓰는 기존 서버·명령이 아직 실행 중인지 먼저 확인해요. 실행 중인 프로세스의 lock은 삭제하지 않아요. crash가 확인돼도 원장을 보존하고, 관련 프로세스가 모두 끝난 것을 확인한 뒤 그 원장의 stale lock만 운영자가 별도로 처리해요. 자동 lock 삭제·원장 초기화 기능은 없어요.
|
|
192
192
|
- 인증·429·timeout을 수정한 뒤에도 이전 요청이 unknown이면 새 ID로 무조건 재시도하지 않아요. 이 규칙은 실패 메시지가 안전한 코드로만 반환돼 원시 API 오류를 볼 수 없는 경우에도 같아요.
|
|
193
193
|
|
|
194
|
-
진단 자료가 필요하면 `report --format both --output-dir reports`로 로컬 첨부 파일을 만들고 검토해요. 키가 존재한다는 진단은 API 인증 성공을 뜻하지 않아요. [진단 안내](REPORTING.md), [공개 준비](RELEASING.md)를 참고해요.
|
|
194
|
+
진단 자료가 필요하면 `report --format both --output-dir reports`로 로컬 첨부 파일을 만들고 검토해요. 키가 존재한다는 진단은 API 인증 성공을 뜻하지 않아요. [진단 안내](https://github.com/abruption/aptly/blob/9d1f7d6449290fee961ccaead0be1d032a88e809/docs/REPORTING.md), [공개 준비](https://github.com/abruption/aptly/blob/9d1f7d6449290fee961ccaead0be1d032a88e809/docs/RELEASING.md)를 참고해요.
|
|
195
195
|
|
|
196
196
|
설치용 npm archive에는 이 사용 안내를 동봉해요. 설계·호환성·과거 검증 등 다른 문서는 source archive에서 확인해요.
|
package/docs/DRAFT_0_1_0.md
CHANGED
|
@@ -52,4 +52,4 @@ Hook 추가 전 후보·모델 정보 초안은 Node 무료 회귀 **226/226**,
|
|
|
52
52
|
|
|
53
53
|
후보·모델 정보 초안 작업에서는 새 후보의 유료 Decisions 호출·실제 child 실행·호스트 내부 실험을 하지 않았어요. 설치·자동 Hook 후속 작업의 실제 검증 상태는 해당 후보의 기록을 확인해요. 문서나 합성 시험만으로 native 적용 성공을 주장하지 않아요. 새 세 단계의 업무별 품질·토큰 절감·비용 최적성은 아직 평가하지 않았어요. 비용 관련 기본값은 사용자 요청한 프리셋이며 측정된 최저 비용 순위가 아니에요.
|
|
54
54
|
|
|
55
|
-
과거 Node 193개 회귀·실제 Decisions 11회·초기 범주 8/8 기록은 **이전 네 프로필 카탈로그**의 검증이에요. 이를 이번 여섯 기본 프로필이나 새 환경변수·cache의 검증으로 바꾸어 표시하지 않아요. 그 기록은 [이전 실제 결과](ADVISORY_RESULTS.md)에 보존해요.
|
|
55
|
+
과거 Node 193개 회귀·실제 Decisions 11회·초기 범주 8/8 기록은 **이전 네 프로필 카탈로그**의 검증이에요. 이를 이번 여섯 기본 프로필이나 새 환경변수·cache의 검증으로 바꾸어 표시하지 않아요. 그 기록은 [이전 실제 결과](https://github.com/abruption/aptly/blob/9d1f7d6449290fee961ccaead0be1d032a88e809/docs/ADVISORY_RESULTS.md)에 보존해요.
|