aptly 0.1.10 → 0.1.11
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 +342 -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,6 +292,42 @@ 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
|
+
function policyReferenceMatches(entry, client, policyPath, options) {
|
|
326
|
+
const source = entry.env?.APTLY_HOOK_POLICY_PATH;
|
|
327
|
+
if (source !== CODEX_HOME_POLICY_SOURCE)
|
|
328
|
+
return source === policyPath;
|
|
329
|
+
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') && resolvePolicySource(source, options.env ?? process.env, options.home) === policyPath;
|
|
330
|
+
}
|
|
294
331
|
function resolved(options, client) {
|
|
295
332
|
const home = resolve(options.home ?? homedir()), env = options.env ?? process.env;
|
|
296
333
|
const override = client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR;
|
|
@@ -303,6 +340,12 @@ function resolved(options, client) {
|
|
|
303
340
|
function ownership(value, client) {
|
|
304
341
|
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
342
|
fail('invalid_ownership');
|
|
343
|
+
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')))
|
|
344
|
+
fail('invalid_ownership');
|
|
345
|
+
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'))
|
|
346
|
+
fail('invalid_ownership');
|
|
347
|
+
if (value.env_vars_was_absent !== undefined && (client !== 'codex' || value.mcp_created || typeof value.env_vars_was_absent !== 'boolean' || !value.env_vars_added))
|
|
348
|
+
fail('invalid_ownership');
|
|
306
349
|
return value;
|
|
307
350
|
}
|
|
308
351
|
/** Compatibility restriction only: this does not authenticate arbitrary launcher code. */
|
|
@@ -405,6 +448,18 @@ function prepare(options, client, removing, edit) {
|
|
|
405
448
|
delete servers.aptly.env[key];
|
|
406
449
|
}
|
|
407
450
|
mcp.after = client === 'codex' ? removeTomlEnv(mcp.before ?? '', owned.env_added) : stringify(config);
|
|
451
|
+
if (owned.policy_source_previous !== undefined) {
|
|
452
|
+
if (servers.aptly.env?.APTLY_HOOK_POLICY_PATH !== CODEX_HOME_POLICY_SOURCE)
|
|
453
|
+
fail('managed_entry_changed');
|
|
454
|
+
mcp.after = updateTomlEnv(mcp.after, { APTLY_HOOK_POLICY_PATH: owned.policy_source_previous });
|
|
455
|
+
}
|
|
456
|
+
if (client === 'codex' && owned.env_vars_added?.length) {
|
|
457
|
+
const names = toml(mcp.after).mcp_servers?.aptly?.env_vars;
|
|
458
|
+
if (!Array.isArray(names) || owned.env_vars_added.some(name => names.filter((x) => x === name).length !== 1))
|
|
459
|
+
fail('managed_entry_changed');
|
|
460
|
+
const remaining = names.filter((name) => !owned.env_vars_added.includes(name));
|
|
461
|
+
mcp.after = updateTomlForwarding(mcp.after, owned.env_vars_was_absent && remaining.length === 0 ? undefined : remaining);
|
|
462
|
+
}
|
|
408
463
|
}
|
|
409
464
|
const p = json(policy.before);
|
|
410
465
|
if (!isDeepStrictEqual(p, owned.policy))
|
|
@@ -439,7 +494,9 @@ function prepare(options, client, removing, edit) {
|
|
|
439
494
|
if (!object(servers.aptly))
|
|
440
495
|
fail('mcp_entry_conflict');
|
|
441
496
|
const configuredPolicy = object(servers.aptly.env) ? servers.aptly.env.APTLY_HOOK_POLICY_PATH : undefined;
|
|
442
|
-
|
|
497
|
+
if (oldOwner?.policy_source_previous !== undefined && configuredPolicy !== CODEX_HOME_POLICY_SOURCE)
|
|
498
|
+
fail('managed_entry_changed');
|
|
499
|
+
const mismatch = configuredPolicy !== undefined && !policyReferenceMatches(servers.aptly, client, policyPath, options);
|
|
443
500
|
const detail = mismatch && typeof configuredPolicy === 'string' && configuredPolicy.length > 0 ? {
|
|
444
501
|
policy_location: configuredPolicy === join(resolve(options.home ?? homedir()), client === 'codex' ? '.codex' : '.claude', 'aptly', 'auto-policy.json') ? 'default_home' : 'elsewhere',
|
|
445
502
|
selected_home_source: (client === 'codex' ? env.CODEX_HOME : env.CLAUDE_CONFIG_DIR) ? 'override' : 'default',
|
|
@@ -457,7 +514,7 @@ function prepare(options, client, removing, edit) {
|
|
|
457
514
|
servers.aptly.command = process.execPath;
|
|
458
515
|
servers.aptly.args = [join(root, 'dist', 'src', 'server.js')];
|
|
459
516
|
}
|
|
460
|
-
if (edit && ('credential' in edit || 'migrate' in edit))
|
|
517
|
+
if ((edit && ('credential' in edit || 'migrate' in edit)) || servers.aptly.env?.APTLY_HOOK_POLICY_PATH === CODEX_HOME_POLICY_SOURCE)
|
|
461
518
|
requireCredentialRuntime(servers.aptly, root);
|
|
462
519
|
const currentEnv = map(servers.aptly, 'env');
|
|
463
520
|
const originalEnvKeys = new Set(Object.keys(currentEnv)), inheritedBudget = budgetInheritance(servers.aptly, env, client);
|
|
@@ -563,6 +620,14 @@ function prepare(options, client, removing, edit) {
|
|
|
563
620
|
result.transmission = effectiveTransmission(policyValue);
|
|
564
621
|
result.transmission_source = policyValue.schema_version === 1 ? 'legacy' : policyValue.transmission === 'unselected' ? 'unselected' : 'explicit';
|
|
565
622
|
manifest.after = stringify(owner);
|
|
623
|
+
const review = transmissionReviewSnapshot(options, client);
|
|
624
|
+
observations.push(review);
|
|
625
|
+
if (requestedScope !== undefined) {
|
|
626
|
+
review.after = transmissionReviewMarker(options, client, policyValue);
|
|
627
|
+
if (review.after !== review.before)
|
|
628
|
+
changes.push(review);
|
|
629
|
+
}
|
|
630
|
+
result.transmission_review = reviewMatches(review.after, options, client, policyValue) ? 'complete' : 'required';
|
|
566
631
|
if (client === 'codex')
|
|
567
632
|
result.requires_hook_review = true;
|
|
568
633
|
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 +641,17 @@ function prepare(options, client, removing, edit) {
|
|
|
576
641
|
changes.push(snapshot);
|
|
577
642
|
if (!removing && changes.length)
|
|
578
643
|
result.status = 'configured';
|
|
644
|
+
const markerIndex = changes.findIndex(item => item.reviewPrivate);
|
|
645
|
+
if (markerIndex >= 0)
|
|
646
|
+
changes.push(...changes.splice(markerIndex, 1));
|
|
579
647
|
return { changes, observations, dirs, result };
|
|
580
648
|
}
|
|
581
649
|
/** Secure sibling staging is short-lived and never a backup; original settings stay in memory. */
|
|
582
650
|
function replace(snapshot, forward) {
|
|
583
651
|
const expected = forward ? snapshot.before : snapshot.after, next = forward ? snapshot.after : snapshot.before;
|
|
584
652
|
const check = () => {
|
|
653
|
+
if (snapshot.reviewPrivate)
|
|
654
|
+
validateReviewPrivate(snapshot.path);
|
|
585
655
|
const current = read(snapshot.path);
|
|
586
656
|
if (current.text !== expected || (process.platform !== 'win32' && expected !== null && current.mode !== snapshot.mode))
|
|
587
657
|
fail('concurrent_configuration_change');
|
|
@@ -715,7 +785,7 @@ function execute(options, removing, edit, captured) {
|
|
|
715
785
|
}
|
|
716
786
|
return { status: results.some(result => result.status === 'error') ? 'partial' : results.every(result => result.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
717
787
|
}
|
|
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']);
|
|
788
|
+
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
789
|
function safeCode(error) { return error instanceof Error && codes.has(error.message) ? error.message : 'configuration_io_error'; }
|
|
720
790
|
export function setupHosts(options = {}) { return execute(options, false); }
|
|
721
791
|
/** Snapshot the normal setup plan without applying it; it does not verify a running host. */
|
|
@@ -750,8 +820,12 @@ export function setCredentialReference(options = {}) { return execute(options, f
|
|
|
750
820
|
/** Include unchanged files: a no-op reference update must still detect prompt-time edits. */
|
|
751
821
|
function validateObservations(plan, written = []) {
|
|
752
822
|
for (const snapshot of plan.observations) {
|
|
823
|
+
if (snapshot.reviewPrivate)
|
|
824
|
+
validateReviewPrivate(snapshot.path);
|
|
753
825
|
const current = read(snapshot.path);
|
|
754
826
|
const expected = written.includes(snapshot) ? snapshot.after : snapshot.before;
|
|
827
|
+
if (!written.includes(snapshot) && snapshot.identity && reviewIdentity(snapshot.path) !== snapshot.identity)
|
|
828
|
+
fail('concurrent_configuration_change');
|
|
755
829
|
if (current.text !== expected || (process.platform !== 'win32' && expected !== null && current.mode !== snapshot.mode))
|
|
756
830
|
fail('concurrent_configuration_change');
|
|
757
831
|
}
|
|
@@ -833,12 +907,274 @@ export function migrateLauncher(options, dryRun = false, includeExisting = false
|
|
|
833
907
|
return { status: 'partial', clients: [errorResult(client, error)] };
|
|
834
908
|
}
|
|
835
909
|
}
|
|
910
|
+
/** Explicitly select a per-Codex-home policy without moving any state. */
|
|
911
|
+
export function setPolicySource(options, dryRun = false) {
|
|
912
|
+
if (options.clients?.length !== 1 || options.clients[0] !== 'codex' || options.automatic !== undefined || options.mode !== undefined || options.transmission !== undefined || options.selectUnselectedOnly !== undefined)
|
|
913
|
+
return { status: 'partial', clients: [{ client: 'codex', status: 'error', codes: ['policy_source_invalid_options'] }] };
|
|
914
|
+
const client = 'codex';
|
|
915
|
+
try {
|
|
916
|
+
const paths = resolved(options, client), policyPath = join(paths.privateDir, 'auto-policy.json');
|
|
917
|
+
// Validate the selector even when CODEX_HOME is present but empty.
|
|
918
|
+
if (resolvePolicySource(CODEX_HOME_POLICY_SOURCE, options.env ?? process.env, options.home) !== policyPath)
|
|
919
|
+
fail('policy_source_home_invalid');
|
|
920
|
+
const snap = (path) => { const file = read(path); return { path, before: file.text, after: file.text, mode: file.mode }; };
|
|
921
|
+
const mcp = snap(paths.mcpPath), hooks = snap(paths.hooksPath), policy = snap(policyPath), manifest = snap(join(paths.privateDir, 'setup-ownership.json'));
|
|
922
|
+
for (const dir of [paths.privateDir, join(paths.privateDir, 'state')]) {
|
|
923
|
+
try {
|
|
924
|
+
checkedDirectory(dir);
|
|
925
|
+
privatePermissions(dir, 'private_directory_permissions');
|
|
926
|
+
}
|
|
927
|
+
catch (e) {
|
|
928
|
+
if (e.code !== 'ENOENT')
|
|
929
|
+
throw e;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (policy.before === null || manifest.before === null || mcp.before === null || hooks.before === null)
|
|
933
|
+
fail('policy_source_requires_setup');
|
|
934
|
+
privatePermissions(policy.path, 'private_file_permissions');
|
|
935
|
+
privatePermissions(manifest.path, 'private_file_permissions');
|
|
936
|
+
const owner = ownership(json(manifest.before), client), config = toml(mcp.before), entry = config.mcp_servers?.aptly;
|
|
937
|
+
if (!object(entry) || !object(entry.env))
|
|
938
|
+
fail('mcp_entry_conflict');
|
|
939
|
+
if (!hooksArray(json(hooks.before)).some(item => isDeepStrictEqual(item, owner.hook)))
|
|
940
|
+
fail('managed_hook_changed');
|
|
941
|
+
if (!loadAutomaticHookPolicy(policyPath).policy || !isDeepStrictEqual(json(policy.before), owner.policy))
|
|
942
|
+
fail('managed_policy_changed');
|
|
943
|
+
const root = resolve(options.packageRoot ?? join(dirname(fileURLToPath(import.meta.url)), '..', ...(import.meta.url.includes('/dist/src/') ? ['..'] : [])));
|
|
944
|
+
requireCredentialRuntime(entry, root);
|
|
945
|
+
if (entry.env.CODEX_HOME !== undefined)
|
|
946
|
+
fail('mcp_environment_conflict');
|
|
947
|
+
if (entry.env_vars !== undefined && (!Array.isArray(entry.env_vars) || entry.env_vars.some((v) => typeof v !== 'string')))
|
|
948
|
+
fail('configuration_shape_conflict');
|
|
949
|
+
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;
|
|
950
|
+
const defaultPath = join(resolve(options.home ?? homedir()), '.codex', 'aptly', 'auto-policy.json');
|
|
951
|
+
if (![policyPath, defaultPath, CODEX_HOME_POLICY_SOURCE].includes(source) || (ownedSource !== undefined && ![policyPath, defaultPath, CODEX_HOME_POLICY_SOURCE].includes(ownedSource)) || (owner.mcp_created && ownedSource === undefined))
|
|
952
|
+
fail('managed_entry_changed');
|
|
953
|
+
const vars = entry.env_vars ?? [];
|
|
954
|
+
if (owner.mcp_created) {
|
|
955
|
+
if (!object(owner.mcp) || !owner.toml_block)
|
|
956
|
+
fail('invalid_ownership');
|
|
957
|
+
const expected = structuredClone(owner.mcp);
|
|
958
|
+
expected.env.APTLY_HOOK_POLICY_PATH = source;
|
|
959
|
+
expected.env_vars = vars;
|
|
960
|
+
const priorVars = owner.mcp.env_vars ?? [];
|
|
961
|
+
if (!isDeepStrictEqual(vars, priorVars) && !isDeepStrictEqual(vars, [...priorVars, 'CODEX_HOME']))
|
|
962
|
+
fail('managed_mcp_changed');
|
|
963
|
+
if (!isDeepStrictEqual(expected, entry))
|
|
964
|
+
fail('managed_mcp_changed');
|
|
965
|
+
const previousBlock = newTomlBlock(entry);
|
|
966
|
+
if (!mcp.before.includes(owner.toml_block) && !mcp.before.includes(previousBlock))
|
|
967
|
+
fail('managed_mcp_changed');
|
|
968
|
+
entry.env.APTLY_HOOK_POLICY_PATH = CODEX_HOME_POLICY_SOURCE;
|
|
969
|
+
if (!vars.includes('CODEX_HOME'))
|
|
970
|
+
entry.env_vars = [...vars, 'CODEX_HOME'];
|
|
971
|
+
const nextBlock = newTomlBlock(entry), oldBlock = mcp.before.includes(owner.toml_block) ? owner.toml_block : previousBlock;
|
|
972
|
+
mcp.after = mcp.before.replace(oldBlock, nextBlock);
|
|
973
|
+
if (!isDeepStrictEqual(toml(mcp.after), config))
|
|
974
|
+
fail('managed_mcp_changed');
|
|
975
|
+
owner.mcp = structuredClone(entry);
|
|
976
|
+
owner.toml_block = nextBlock;
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
for (const [key, value] of Object.entries(owner.env_added))
|
|
980
|
+
if (key !== 'APTLY_HOOK_POLICY_PATH' && entry.env[key] !== value)
|
|
981
|
+
fail('managed_entry_changed');
|
|
982
|
+
if (owner.policy_source_previous !== undefined && source !== CODEX_HOME_POLICY_SOURCE)
|
|
983
|
+
fail('managed_entry_changed');
|
|
984
|
+
const preexistingSelector = ownedSource === undefined && owner.policy_source_previous === undefined && source === CODEX_HOME_POLICY_SOURCE;
|
|
985
|
+
if (!vars.includes('CODEX_HOME')) {
|
|
986
|
+
if (owner.env_vars_added?.length)
|
|
987
|
+
fail('managed_entry_changed');
|
|
988
|
+
mcp.after = updateTomlForwarding(mcp.after, [...vars, 'CODEX_HOME']);
|
|
989
|
+
owner.env_vars_added = [...(owner.env_vars_added ?? []), 'CODEX_HOME'];
|
|
990
|
+
if (entry.env_vars === undefined)
|
|
991
|
+
owner.env_vars_was_absent = true;
|
|
992
|
+
}
|
|
993
|
+
mcp.after = updateTomlEnv(mcp.after, { APTLY_HOOK_POLICY_PATH: CODEX_HOME_POLICY_SOURCE });
|
|
994
|
+
if (ownedSource !== undefined)
|
|
995
|
+
owner.env_added.APTLY_HOOK_POLICY_PATH = CODEX_HOME_POLICY_SOURCE;
|
|
996
|
+
else if (!preexistingSelector && owner.policy_source_previous === undefined)
|
|
997
|
+
owner.policy_source_previous = source;
|
|
998
|
+
}
|
|
999
|
+
manifest.after = stringify(owner);
|
|
1000
|
+
const changes = [mcp, manifest].filter(item => item.before !== item.after);
|
|
1001
|
+
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'] } };
|
|
1002
|
+
if (dryRun)
|
|
1003
|
+
return { status: 'complete', clients: [{ ...plan.result, status: 'unchanged', codes: [changes.length ? 'policy_source_selection_available' : 'policy_source_current'] }] };
|
|
1004
|
+
return execute(options, false, { migrate: true }, [plan]);
|
|
1005
|
+
}
|
|
1006
|
+
catch (error) {
|
|
1007
|
+
return { status: 'partial', clients: [errorResult(client, error)] };
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
836
1010
|
/** Explicit operator change; updates policy and its receipt through normal guarded staging. */
|
|
837
1011
|
export function setTransmission(scope, options = {}) {
|
|
838
1012
|
if (!['none', 'description', 'excerpt'].includes(scope))
|
|
839
1013
|
return { status: 'partial', clients: (options.clients ?? ['codex', 'claude']).map(client => ({ client, status: 'error', codes: ['transmission_invalid_scope'] })) };
|
|
840
1014
|
return execute(options, false, { transmission: scope });
|
|
841
1015
|
}
|
|
1016
|
+
const TRANSMISSION_REVIEW_FILE = 'transmission-review.json';
|
|
1017
|
+
function reviewIdentity(path) {
|
|
1018
|
+
try {
|
|
1019
|
+
const stat = lstatSync(path);
|
|
1020
|
+
return `${stat.dev}:${stat.ino}:${stat.uid}:${stat.nlink}`;
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
if (error.code === 'ENOENT')
|
|
1024
|
+
return 'missing';
|
|
1025
|
+
throw error;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
function validateReviewPrivate(path) {
|
|
1029
|
+
noSymlinks(path);
|
|
1030
|
+
for (const [target, directory] of [[dirname(path), true], [path, false]]) {
|
|
1031
|
+
try {
|
|
1032
|
+
const stat = lstatSync(target);
|
|
1033
|
+
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile() || stat.nlink !== 1))
|
|
1034
|
+
fail('unsafe_configuration_file');
|
|
1035
|
+
if (process.platform !== 'win32' && process.getuid && stat.uid !== process.getuid())
|
|
1036
|
+
fail(directory ? 'private_directory_permissions' : 'private_file_permissions');
|
|
1037
|
+
privatePermissions(target, directory ? 'private_directory_permissions' : 'private_file_permissions');
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
if (error.code !== 'ENOENT')
|
|
1041
|
+
throw error;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
function transmissionReviewSnapshot(options, client) {
|
|
1046
|
+
const path = join(resolved(options, client).privateDir, TRANSMISSION_REVIEW_FILE);
|
|
1047
|
+
validateReviewPrivate(path);
|
|
1048
|
+
const source = read(path);
|
|
1049
|
+
return { path, before: source.text, after: source.text, mode: source.mode, reviewPrivate: true, identity: reviewIdentity(path) };
|
|
1050
|
+
}
|
|
1051
|
+
function transmissionReviewMarker(options, client, policy) {
|
|
1052
|
+
const paths = resolved(options, client), scope = effectiveTransmission(policy);
|
|
1053
|
+
// A local UI acknowledgement, not authentication or authorization of host code.
|
|
1054
|
+
const binding = { selected_home: resolve(paths.dir), policyPath: join(paths.privateDir, 'auto-policy.json'),
|
|
1055
|
+
state_directory: resolve(policy.state_directory), schema_version: policy.schema_version, effective_scope: scope,
|
|
1056
|
+
provenance: policy.schema_version === 1 ? 'legacy' : scope === 'unselected' ? 'unselected' : 'explicit' };
|
|
1057
|
+
return stringify({ schema_version: 1, revision: 1, client, binding_sha256: createHash('sha256').update(JSON.stringify(binding)).digest('hex') });
|
|
1058
|
+
}
|
|
1059
|
+
function reviewMatches(text, options, client, policy) {
|
|
1060
|
+
if (text === null || effectiveTransmission(policy) === 'unselected')
|
|
1061
|
+
return false;
|
|
1062
|
+
try {
|
|
1063
|
+
return isDeepStrictEqual(JSON.parse(text), JSON.parse(transmissionReviewMarker(options, client, policy)));
|
|
1064
|
+
}
|
|
1065
|
+
catch {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
/** Read-only, two-phase local acknowledgement. Recheck every captured host before writing. */
|
|
1070
|
+
export function prepareTransmissionReview(options = {}) {
|
|
1071
|
+
options = { ...options, home: resolve(options.home ?? homedir()), env: { ...(options.env ?? process.env) }, ...(options.clients ? { clients: [...options.clients] } : {}) };
|
|
1072
|
+
const clients = [...new Set(options.clients ?? ['codex', 'claude'])];
|
|
1073
|
+
const plans = [], candidates = [];
|
|
1074
|
+
if (!clients.length || clients.some(client => !['codex', 'claude'].includes(client)) || options.automatic !== undefined || options.mode !== undefined || options.transmission !== undefined || options.selectUnselectedOnly !== undefined) {
|
|
1075
|
+
const result = { status: 'partial', clients: clients.map(client => ({ client, status: 'error', codes: ['transmission_review_invalid_options'] })) };
|
|
1076
|
+
return { result, candidates: [], apply: () => result };
|
|
1077
|
+
}
|
|
1078
|
+
const results = clients.map(client => {
|
|
1079
|
+
try {
|
|
1080
|
+
const paths = resolved(options, client), policyPath = join(paths.privateDir, 'auto-policy.json');
|
|
1081
|
+
const mcp = read(paths.mcpPath), config = client === 'codex' ? toml(mcp.text ?? '') : json(mcp.text);
|
|
1082
|
+
const entry = config[client === 'codex' ? 'mcp_servers' : 'mcpServers']?.aptly;
|
|
1083
|
+
const policySource = read(policyPath), ownerSource = read(join(paths.privateDir, 'setup-ownership.json'));
|
|
1084
|
+
if (entry === undefined && policySource.text === null && ownerSource.text === null)
|
|
1085
|
+
return { client, status: 'skipped', codes: ['host_not_configured'] };
|
|
1086
|
+
if (!object(entry) || !policyReferenceMatches(entry, client, policyPath, options) || policySource.text === null || ownerSource.text === null)
|
|
1087
|
+
fail('transmission_review_requires_setup');
|
|
1088
|
+
const loaded = loadAutomaticHookPolicy(policyPath);
|
|
1089
|
+
if (!loaded.policy)
|
|
1090
|
+
fail('policy_conflict');
|
|
1091
|
+
const policy = loaded.policy, owner = ownership(json(ownerSource.text), client);
|
|
1092
|
+
if (!isDeepStrictEqual(policy, owner.policy))
|
|
1093
|
+
fail('managed_policy_changed');
|
|
1094
|
+
const hooksSource = read(paths.hooksPath), hookSettings = json(hooksSource.text);
|
|
1095
|
+
if (!Array.isArray(hookSettings.hooks?.PreToolUse) || !hookSettings.hooks.PreToolUse.some((value) => isDeepStrictEqual(value, owner.hook)) || !isDeepStrictEqual(owner.hook, hook(client)))
|
|
1096
|
+
fail('transmission_review_requires_setup');
|
|
1097
|
+
if (!object(entry.env) || entry.env.ROUTER_LEDGER_PATH === undefined)
|
|
1098
|
+
fail('transmission_review_requires_setup');
|
|
1099
|
+
// Use the existing explicit-change validator without executing a setup repair.
|
|
1100
|
+
const plan = prepare(options, client, false, { transmission: effectiveTransmission(policy) === 'unselected' ? 'none' : effectiveTransmission(policy) });
|
|
1101
|
+
for (const [path, source] of [[paths.mcpPath, mcp], [policyPath, policySource], [join(paths.privateDir, 'setup-ownership.json'), ownerSource], [paths.hooksPath, hooksSource]]) {
|
|
1102
|
+
const captured = plan.observations.find(snapshot => snapshot.path === path);
|
|
1103
|
+
if (!captured || captured.before !== source.text || captured.mode !== source.mode)
|
|
1104
|
+
fail('concurrent_configuration_change');
|
|
1105
|
+
}
|
|
1106
|
+
for (const snapshot of plan.observations) {
|
|
1107
|
+
snapshot.identity = reviewIdentity(snapshot.path);
|
|
1108
|
+
if (snapshot.path === policyPath || snapshot.path === join(paths.privateDir, 'setup-ownership.json')) {
|
|
1109
|
+
validateReviewPrivate(snapshot.path);
|
|
1110
|
+
snapshot.reviewPrivate = true;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
const review = plan.observations.find(snapshot => snapshot.path === join(paths.privateDir, TRANSMISSION_REVIEW_FILE));
|
|
1114
|
+
const complete = reviewMatches(review.before, options, client, policy);
|
|
1115
|
+
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' };
|
|
1116
|
+
if (!complete || options.forceReview) {
|
|
1117
|
+
plans.push({ ...plan, changes: [], dirs: [], result: state });
|
|
1118
|
+
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 });
|
|
1119
|
+
}
|
|
1120
|
+
return state;
|
|
1121
|
+
}
|
|
1122
|
+
catch (error) {
|
|
1123
|
+
return errorResult(client, error);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
const result = { status: results.some(value => value.status === 'error') ? 'partial' : results.every(value => value.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
1127
|
+
if (result.status === 'partial') {
|
|
1128
|
+
result.clients = results.map(initial => plans.some(plan => plan.result.client === initial.client) ? { ...initial, status: 'skipped', codes: ['other_host_validation_failed'] } : initial);
|
|
1129
|
+
return { result, candidates: [], apply: () => result };
|
|
1130
|
+
}
|
|
1131
|
+
return { result, candidates, apply: (choice) => {
|
|
1132
|
+
const merge = (updates, status) => ({ status, clients: results.map(initial => updates.find(updated => updated.client === initial.client) ?? initial) });
|
|
1133
|
+
if (!['keep', 'none', 'description', 'excerpt'].includes(choice))
|
|
1134
|
+
return merge(plans.map(plan => ({ ...plan.result, status: 'error', codes: ['transmission_invalid_scope'] })), 'partial');
|
|
1135
|
+
if (!plans.length)
|
|
1136
|
+
return result;
|
|
1137
|
+
const commits = [];
|
|
1138
|
+
const failures = [];
|
|
1139
|
+
// All preflight checks precede every write; commits retain per-client rollback.
|
|
1140
|
+
for (const plan of plans) {
|
|
1141
|
+
const client = plan.result.client;
|
|
1142
|
+
try {
|
|
1143
|
+
validateObservations(plan);
|
|
1144
|
+
const currentPolicy = loadAutomaticHookPolicy(join(resolved(options, client).privateDir, 'auto-policy.json')).policy;
|
|
1145
|
+
if (!currentPolicy)
|
|
1146
|
+
fail('policy_conflict');
|
|
1147
|
+
if ((choice === 'keep' && effectiveTransmission(currentPolicy) !== 'unselected') || (currentPolicy.schema_version === 2 && choice === effectiveTransmission(currentPolicy))) {
|
|
1148
|
+
const marker = plan.observations.find(snapshot => snapshot.path === join(resolved(options, client).privateDir, TRANSMISSION_REVIEW_FILE));
|
|
1149
|
+
marker.after = transmissionReviewMarker(options, client, currentPolicy);
|
|
1150
|
+
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' } });
|
|
1151
|
+
}
|
|
1152
|
+
else {
|
|
1153
|
+
const scope = choice === 'keep' ? 'none' : choice;
|
|
1154
|
+
const next = prepare(options, client, false, { transmission: scope });
|
|
1155
|
+
validateObservations(plan);
|
|
1156
|
+
for (const original of plan.observations) {
|
|
1157
|
+
const fresh = next.observations.find(snapshot => snapshot.path === original.path);
|
|
1158
|
+
if (!fresh || fresh.before !== original.before || fresh.mode !== original.mode)
|
|
1159
|
+
fail('concurrent_configuration_change');
|
|
1160
|
+
}
|
|
1161
|
+
// Capture the original prompt-time observations, including unchanged files.
|
|
1162
|
+
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);
|
|
1163
|
+
next.dirs = [];
|
|
1164
|
+
next.result.codes.push('transmission_review_complete');
|
|
1165
|
+
commits.push(next);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
failures.push({ ...plan.result, ...errorResult(client, error) });
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (failures.length)
|
|
1173
|
+
return merge(plans.map(plan => failures.find(failed => failed.client === plan.result.client) ?? { ...plan.result, status: 'skipped', codes: ['other_host_validation_failed'] }), 'partial');
|
|
1174
|
+
const applied = execute({ ...options, clients: plans.map(plan => plan.result.client) }, false, undefined, commits);
|
|
1175
|
+
return merge(applied.clients, applied.status);
|
|
1176
|
+
} };
|
|
1177
|
+
}
|
|
842
1178
|
/** Read-only redacted policy state. Does not create host directories or contact a provider. */
|
|
843
1179
|
export function showTransmission(options = {}) {
|
|
844
1180
|
return { clients: (options.clients ?? ['codex', 'claude']).map(client => {
|
|
@@ -849,6 +1185,7 @@ export function showTransmission(options = {}) {
|
|
|
849
1185
|
if (!loaded.policy)
|
|
850
1186
|
return { client, status: 'unavailable', code: loaded.reason };
|
|
851
1187
|
return { client, status: 'configured', application_mode: loaded.policy.mode, enabled: loaded.policy.enabled,
|
|
1188
|
+
transmission_review: reviewMatches(transmissionReviewSnapshot(options, client).before, options, client, loaded.policy) ? 'complete' : 'required',
|
|
852
1189
|
transmission: effectiveTransmission(loaded.policy), transmission_source: loaded.policy.schema_version === 1 ? 'legacy' : effectiveTransmission(loaded.policy) === 'unselected' ? 'unselected' : 'explicit' };
|
|
853
1190
|
}
|
|
854
1191
|
catch (error) {
|
|
@@ -926,7 +1263,7 @@ function statisticsPolicy(options, client, requireRegistration = true) {
|
|
|
926
1263
|
const entry = config[client === 'codex' ? 'mcp_servers' : 'mcpServers']?.aptly;
|
|
927
1264
|
if (!object(entry))
|
|
928
1265
|
fail('statistics_requires_setup');
|
|
929
|
-
if (entry
|
|
1266
|
+
if (!policyReferenceMatches(entry, client, policyPath, options))
|
|
930
1267
|
fail('statistics_policy_conflict');
|
|
931
1268
|
}
|
|
932
1269
|
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.11";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.11';
|
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)에 보존해요.
|