aptly 0.1.6 → 0.1.8
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 +3 -3
- package/README.ja.md +3 -3
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/dist/bin/aptly.js +108 -74
- package/dist/src/automatic-hook.d.ts +10 -2
- package/dist/src/automatic-hook.js +30 -5
- package/dist/src/budget.d.ts +23 -0
- package/dist/src/budget.js +54 -0
- package/dist/src/cli-help.d.ts +11 -0
- package/dist/src/cli-help.js +100 -0
- package/dist/src/cli-input.d.ts +2 -0
- package/dist/src/cli-input.js +33 -0
- package/dist/src/context-retry.js +12 -4
- package/dist/src/core.d.ts +29 -3
- package/dist/src/core.js +68 -12
- package/dist/src/ledger-lock.d.ts +3 -1
- package/dist/src/ledger-lock.js +3 -1
- package/dist/src/runtime.d.ts +1 -0
- package/dist/src/runtime.js +5 -3
- package/dist/src/server.js +16 -11
- package/dist/src/setup.d.ts +78 -0
- package/dist/src/setup.js +148 -17
- package/dist/src/types.d.ts +2 -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/guide/en.md +82 -6
- package/docs/guide/ja.md +82 -6
- package/docs/guide/ko.md +82 -6
- package/docs/guide/zh-CN.md +82 -6
- package/package.json +1 -1
package/dist/src/setup.js
CHANGED
|
@@ -6,6 +6,9 @@ import { randomUUID } from 'node:crypto';
|
|
|
6
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
7
7
|
import { parse } from 'smol-toml';
|
|
8
8
|
import { resolveCatalog } from './catalog.js';
|
|
9
|
+
import { budgetEnvironmentDefaults, budgetEnvironmentKeys, parseBudgetValue, resolveBudgetSettings, budgetErrorDetails } from './budget.js';
|
|
10
|
+
import { Router, defaultPolicy } from './core.js';
|
|
11
|
+
import { loadAutomaticHookPolicy, effectiveTransmission } from './automatic-hook.js';
|
|
9
12
|
import { assertPrivateStatePath } from './files.js';
|
|
10
13
|
import { assertWindowsPrivatePath, protectNewWindowsPrivateDirectory, copyWindowsFilePermissions } from './windows-private.js';
|
|
11
14
|
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -155,8 +158,8 @@ function removeTomlEnv(text, additions) {
|
|
|
155
158
|
fail('managed_entry_changed');
|
|
156
159
|
return text;
|
|
157
160
|
}
|
|
158
|
-
export const configurableEnvironmentKeys = Object.freeze(['ROUTER_PROVIDER', 'APTLY_CLAUDE_MODELS', 'APTLY_CODEX_MODELS', 'CLAUDE_MODELS', 'CODEX_MODELS', 'APTLY_MODEL_INFO_PATH']);
|
|
159
|
-
const defaultEnvironment = { ROUTER_PROVIDER: 'decisions', APTLY_CLAUDE_MODELS: '["haiku","sonnet","opus"]', APTLY_CODEX_MODELS: '["gpt-6-luna","gpt-6.1-terra","gpt-6.1-sol"]' };
|
|
161
|
+
export const configurableEnvironmentKeys = Object.freeze([...budgetEnvironmentKeys, 'ROUTER_PROVIDER', 'APTLY_CLAUDE_MODELS', 'APTLY_CODEX_MODELS', 'CLAUDE_MODELS', 'CODEX_MODELS', 'APTLY_MODEL_INFO_PATH']);
|
|
162
|
+
const defaultEnvironment = { ...budgetEnvironmentDefaults, ROUTER_PROVIDER: 'decisions', APTLY_CLAUDE_MODELS: '["haiku","sonnet","opus"]', APTLY_CODEX_MODELS: '["gpt-6-luna","gpt-6.1-terra","gpt-6.1-sol"]' };
|
|
160
163
|
function validateEnvironmentValue(key, value) {
|
|
161
164
|
if (!configurableEnvironmentKeys.includes(key))
|
|
162
165
|
fail(/KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL/i.test(key) ? 'environment_secret_key_unsupported' : 'environment_key_unsupported');
|
|
@@ -164,6 +167,14 @@ function validateEnvironmentValue(key, value) {
|
|
|
164
167
|
fail('environment_invalid_value');
|
|
165
168
|
if (/\bsk-[A-Za-z0-9_-]{8,}|\bBearer\s+\S+|https?:\/\/[^/\s]+:[^/\s]+@/i.test(value))
|
|
166
169
|
fail('environment_sensitive_value');
|
|
170
|
+
if (budgetEnvironmentKeys.includes(key)) {
|
|
171
|
+
try {
|
|
172
|
+
parseBudgetValue(key, value);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
throw Object.assign(new Error('environment_invalid_value'), budgetErrorDetails(error));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
167
178
|
if (key === 'ROUTER_PROVIDER' && !['fixture', 'decisions'].includes(value))
|
|
168
179
|
fail('environment_invalid_value');
|
|
169
180
|
if (key === 'APTLY_MODEL_INFO_PATH') {
|
|
@@ -175,12 +186,28 @@ function validateEnvironmentValue(key, value) {
|
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
|
-
function
|
|
189
|
+
function budgetInheritance(entry, environment, client) {
|
|
190
|
+
if (client === 'codex' && entry.env_vars !== undefined && (!Array.isArray(entry.env_vars) || entry.env_vars.some((key) => typeof key !== 'string')))
|
|
191
|
+
fail('configuration_shape_conflict');
|
|
192
|
+
const permitted = client === 'codex' ? (entry.env_vars ?? []) : [], keys = new Set(), values = {};
|
|
193
|
+
for (const key of budgetEnvironmentKeys) {
|
|
194
|
+
if (client === 'codex' ? permitted.includes(key) : environment[key] !== undefined) {
|
|
195
|
+
keys.add(key);
|
|
196
|
+
if (environment[key] !== undefined)
|
|
197
|
+
values[key] = environment[key];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const key of Object.keys(environment))
|
|
201
|
+
if ((key.startsWith('APTLY_MAX_') || key.startsWith('APTLY_ESTIMATED_')) && (client === 'claude' || permitted.includes(key)))
|
|
202
|
+
values[key] = environment[key];
|
|
203
|
+
return { keys, values };
|
|
204
|
+
}
|
|
205
|
+
function editEnvironment(current, edit, client, inherited) {
|
|
179
206
|
const updates = {};
|
|
180
207
|
if ('defaults' in edit) {
|
|
181
208
|
for (const [key, value] of Object.entries(defaultEnvironment)) {
|
|
182
209
|
const alias = key === 'APTLY_CLAUDE_MODELS' ? 'CLAUDE_MODELS' : key === 'APTLY_CODEX_MODELS' ? 'CODEX_MODELS' : null;
|
|
183
|
-
if (current[key] === undefined && (!alias || current[alias] === undefined))
|
|
210
|
+
if (current[key] === undefined && (!alias || current[alias] === undefined) && !(budgetEnvironmentKeys.includes(key) && inherited.keys.has(key)))
|
|
184
211
|
updates[key] = value;
|
|
185
212
|
}
|
|
186
213
|
}
|
|
@@ -188,18 +215,19 @@ function editEnvironment(current, edit, client) {
|
|
|
188
215
|
updates.APTLY_SECRET_BACKEND = 'os';
|
|
189
216
|
updates.APTLY_SECRET_CLIENT = client;
|
|
190
217
|
}
|
|
191
|
-
else if (!('migrate' in edit)) {
|
|
218
|
+
else if (!('migrate' in edit) && !('transmission' in edit)) {
|
|
192
219
|
validateEnvironmentValue(edit.key, edit.value);
|
|
193
220
|
updates[edit.key] = edit.value;
|
|
194
221
|
}
|
|
195
|
-
const effective = { ...current, ...updates };
|
|
222
|
+
const effective = { ...inherited.values, ...current, ...updates };
|
|
196
223
|
if (effective.ROUTER_PROVIDER !== undefined && !['fixture', 'decisions'].includes(effective.ROUTER_PROVIDER))
|
|
197
224
|
fail('environment_invalid_value');
|
|
198
225
|
try {
|
|
199
226
|
resolveCatalog(effective);
|
|
227
|
+
resolveBudgetSettings(effective);
|
|
200
228
|
}
|
|
201
|
-
catch {
|
|
202
|
-
|
|
229
|
+
catch (error) {
|
|
230
|
+
throw Object.assign(new Error('environment_invalid_value'), budgetErrorDetails(error));
|
|
203
231
|
}
|
|
204
232
|
return Object.fromEntries(Object.entries(updates).filter(([key, value]) => current[key] !== value));
|
|
205
233
|
}
|
|
@@ -421,7 +449,8 @@ function prepare(options, client, removing, edit) {
|
|
|
421
449
|
if (edit && ('credential' in edit || 'migrate' in edit))
|
|
422
450
|
requireCredentialRuntime(servers.aptly, root);
|
|
423
451
|
const currentEnv = map(servers.aptly, 'env');
|
|
424
|
-
const
|
|
452
|
+
const originalEnvKeys = new Set(Object.keys(currentEnv)), inheritedBudget = budgetInheritance(servers.aptly, env, client);
|
|
453
|
+
const updates = edit ? editEnvironment(currentEnv, edit, client, inheritedBudget) : {};
|
|
425
454
|
Object.assign(currentEnv, updates);
|
|
426
455
|
if (created) {
|
|
427
456
|
if (client === 'codex') {
|
|
@@ -442,12 +471,35 @@ function prepare(options, client, removing, edit) {
|
|
|
442
471
|
if (existingRoute.length === 0)
|
|
443
472
|
entries.push(hookValue);
|
|
444
473
|
hooks.after = edit && 'migrate' in edit ? hooks.before : stringify(hooksObject);
|
|
445
|
-
const
|
|
446
|
-
|
|
474
|
+
const currentPolicy = policy.before === null ? undefined : loadAutomaticHookPolicy(policyPath).policy;
|
|
475
|
+
if (policy.before !== null && !currentPolicy)
|
|
476
|
+
fail('policy_conflict');
|
|
477
|
+
const requestedScope = options.transmission ?? (edit && 'transmission' in edit ? edit.transmission : undefined);
|
|
478
|
+
if (requestedScope !== undefined && !['none', 'description', 'excerpt'].includes(requestedScope))
|
|
479
|
+
fail('transmission_invalid_scope');
|
|
480
|
+
const preservedMode = edit && currentPolicy ? currentPolicy.mode : undefined;
|
|
481
|
+
const desiredMode = options.mode ?? preservedMode ?? currentPolicy?.mode ?? 'defaults';
|
|
482
|
+
// Existing v1 settings retain their original scope and byte representation.
|
|
483
|
+
// Only an explicit operator scope selection migrates them to v2.
|
|
484
|
+
let policyValue = currentPolicy ? { ...currentPolicy, mode: desiredMode } : {
|
|
485
|
+
schema_version: 2, kind: 'aptly-auto-hook', mode: desiredMode,
|
|
486
|
+
issuer: 'operator_installation', enabled: true, state_directory: stateDir, transmission: 'unselected',
|
|
487
|
+
};
|
|
488
|
+
if (requestedScope !== undefined) {
|
|
489
|
+
if (options.selectUnselectedOnly && (!currentPolicy || effectiveTransmission(currentPolicy) !== 'unselected'))
|
|
490
|
+
fail('transmission_selection_changed');
|
|
491
|
+
if (currentPolicy && (!oldOwner || !isDeepStrictEqual(currentPolicy, oldOwner.policy)))
|
|
492
|
+
fail('managed_policy_changed');
|
|
493
|
+
policyValue = { ...policyValue, schema_version: 2, transmission: requestedScope };
|
|
494
|
+
}
|
|
447
495
|
if (policy.before !== null) {
|
|
448
|
-
|
|
449
|
-
|
|
496
|
+
if (requestedScope === undefined && !isDeepStrictEqual(currentPolicy, policyValue))
|
|
497
|
+
fail('policy_conflict');
|
|
498
|
+
// An unrelated setup/env operation must never adopt externally modified policy.
|
|
499
|
+
if (oldOwner && !isDeepStrictEqual(currentPolicy, oldOwner.policy))
|
|
450
500
|
fail('policy_conflict');
|
|
501
|
+
if (requestedScope !== undefined)
|
|
502
|
+
policy.after = stringify(policyValue);
|
|
451
503
|
}
|
|
452
504
|
else
|
|
453
505
|
policy.after = stringify(policyValue);
|
|
@@ -488,10 +540,21 @@ function prepare(options, client, removing, edit) {
|
|
|
488
540
|
if (priorEnv[key] === undefined)
|
|
489
541
|
owner.env_added[key] = value;
|
|
490
542
|
}
|
|
543
|
+
if (requestedScope !== undefined)
|
|
544
|
+
owner.policy = structuredClone(policyValue);
|
|
545
|
+
if (edit && ('defaults' in edit || ('key' in edit && budgetEnvironmentKeys.includes(edit.key)))) {
|
|
546
|
+
const budget = resolveBudgetSettings({ ...inheritedBudget.values, ...currentEnv });
|
|
547
|
+
result.budget = { limits: { ...budget.limits }, added: budgetEnvironmentKeys.filter(key => Object.hasOwn(updates, key) && !originalEnvKeys.has(key)),
|
|
548
|
+
updated: budgetEnvironmentKeys.filter(key => Object.hasOwn(updates, key) && originalEnvKeys.has(key)),
|
|
549
|
+
preserved: budgetEnvironmentKeys.filter(key => !Object.hasOwn(updates, key) && currentEnv[key] !== undefined),
|
|
550
|
+
inherited: budgetEnvironmentKeys.filter(key => currentEnv[key] === undefined && inheritedBudget.keys.has(key)), restart_required: budgetEnvironmentKeys.some(key => Object.hasOwn(updates, key)) };
|
|
551
|
+
}
|
|
552
|
+
result.transmission = effectiveTransmission(policyValue);
|
|
553
|
+
result.transmission_source = policyValue.schema_version === 1 ? 'legacy' : policyValue.transmission === 'unselected' ? 'unselected' : 'explicit';
|
|
491
554
|
manifest.after = stringify(owner);
|
|
492
555
|
if (client === 'codex')
|
|
493
556
|
result.requires_hook_review = true;
|
|
494
|
-
result.codes = client === 'codex' ? ['requires_hook_review'] : [];
|
|
557
|
+
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'] : [])];
|
|
495
558
|
dirs.push(dir, privateDir, stateDir);
|
|
496
559
|
}
|
|
497
560
|
// Validate complete desired data before any host file is changed.
|
|
@@ -558,6 +621,8 @@ function execute(options, removing, edit, captured) {
|
|
|
558
621
|
if (clients.some(client => client !== 'codex' && client !== 'claude'))
|
|
559
622
|
return { status: 'partial', clients: [] };
|
|
560
623
|
const env = options.env ?? process.env;
|
|
624
|
+
if (options.transmission !== undefined && !['none', 'description', 'excerpt'].includes(options.transmission))
|
|
625
|
+
return { status: 'partial', clients: clients.map(client => ({ client, status: 'error', codes: ['transmission_invalid_scope'] })) };
|
|
561
626
|
if (!removing && options.automatic && (env.APTLY_SKIP_SETUP === '1' || !!env.CI))
|
|
562
627
|
return { status: 'skipped', clients: clients.map(client => ({ client, status: 'skipped', codes: [env.APTLY_SKIP_SETUP === '1' ? 'setup_disabled' : 'ci_environment'] })) };
|
|
563
628
|
const prepared = captured ?? clients.map(client => {
|
|
@@ -565,7 +630,7 @@ function execute(options, removing, edit, captured) {
|
|
|
565
630
|
return prepare(options, client, removing, edit);
|
|
566
631
|
}
|
|
567
632
|
catch (e) {
|
|
568
|
-
return { changes: [], observations: [], dirs: [], result: { client, status: 'error', codes: [safeCode(e)] } };
|
|
633
|
+
return { changes: [], observations: [], dirs: [], result: { client, status: 'error', codes: [safeCode(e)], ...budgetErrorDetails(e) } };
|
|
569
634
|
}
|
|
570
635
|
});
|
|
571
636
|
const results = prepared.map(plan => plan.result);
|
|
@@ -632,7 +697,7 @@ function execute(options, removing, edit, captured) {
|
|
|
632
697
|
}
|
|
633
698
|
return { status: results.some(result => result.status === 'error') ? 'partial' : results.every(result => result.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
634
699
|
}
|
|
635
|
-
const codes = new Set(['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']);
|
|
700
|
+
const codes = new Set(['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']);
|
|
636
701
|
function safeCode(error) { return error instanceof Error && codes.has(error.message) ? error.message : 'configuration_io_error'; }
|
|
637
702
|
export function setupHosts(options = {}) { return execute(options, false); }
|
|
638
703
|
export function removeSetup(options = {}) { return execute(options, true); }
|
|
@@ -642,7 +707,7 @@ export function setEnvironment(key, value, options = {}) {
|
|
|
642
707
|
validateEnvironmentValue(key, value);
|
|
643
708
|
}
|
|
644
709
|
catch (error) {
|
|
645
|
-
return { status: 'partial', clients: (options.clients ?? ['codex', 'claude']).map(client => ({ client, status: 'error', codes: [safeCode(error)] })) };
|
|
710
|
+
return { status: 'partial', clients: (options.clients ?? ['codex', 'claude']).map(client => ({ client, status: 'error', codes: [safeCode(error)], ...budgetErrorDetails(error) })) };
|
|
646
711
|
}
|
|
647
712
|
return execute(options, false, { key, value });
|
|
648
713
|
}
|
|
@@ -718,3 +783,69 @@ export function migrateLauncher(options, dryRun = false, includeExisting = false
|
|
|
718
783
|
return { status: 'partial', clients: [{ client, status: 'error', codes: [safeCode(error)] }] };
|
|
719
784
|
}
|
|
720
785
|
}
|
|
786
|
+
/** Explicit operator change; updates policy and its receipt through normal guarded staging. */
|
|
787
|
+
export function setTransmission(scope, options = {}) {
|
|
788
|
+
if (!['none', 'description', 'excerpt'].includes(scope))
|
|
789
|
+
return { status: 'partial', clients: (options.clients ?? ['codex', 'claude']).map(client => ({ client, status: 'error', codes: ['transmission_invalid_scope'] })) };
|
|
790
|
+
return execute(options, false, { transmission: scope });
|
|
791
|
+
}
|
|
792
|
+
/** Read-only redacted policy state. Does not create host directories or contact a provider. */
|
|
793
|
+
export function showTransmission(options = {}) {
|
|
794
|
+
return { clients: (options.clients ?? ['codex', 'claude']).map(client => {
|
|
795
|
+
try {
|
|
796
|
+
const { privateDir } = resolved(options, client);
|
|
797
|
+
noSymlinks(privateDir);
|
|
798
|
+
const loaded = loadAutomaticHookPolicy(join(privateDir, 'auto-policy.json'));
|
|
799
|
+
if (!loaded.policy)
|
|
800
|
+
return { client, status: 'unavailable', code: loaded.reason };
|
|
801
|
+
return { client, status: 'configured', application_mode: loaded.policy.mode, enabled: loaded.policy.enabled,
|
|
802
|
+
transmission: effectiveTransmission(loaded.policy), transmission_source: loaded.policy.schema_version === 1 ? 'legacy' : effectiveTransmission(loaded.policy) === 'unselected' ? 'unselected' : 'explicit' };
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
return { client, status: 'error', code: safeCode(error) };
|
|
806
|
+
}
|
|
807
|
+
}) };
|
|
808
|
+
}
|
|
809
|
+
/** Registration snapshot only. Never loads credentials, starts a server or creates a ledger/gate. */
|
|
810
|
+
export function showBudgetStatus(options = {}) {
|
|
811
|
+
const environment = options.env ?? process.env;
|
|
812
|
+
const clients = (options.clients ?? ['codex', 'claude']).map(client => {
|
|
813
|
+
try {
|
|
814
|
+
const { mcpPath } = resolved(options, client), source = read(mcpPath);
|
|
815
|
+
if (source.text === null)
|
|
816
|
+
return { client, status: 'skipped', codes: ['host_not_configured'] };
|
|
817
|
+
const config = client === 'codex' ? toml(source.text) : json(source.text);
|
|
818
|
+
const entry = config[client === 'codex' ? 'mcp_servers' : 'mcpServers']?.aptly;
|
|
819
|
+
if (entry === undefined)
|
|
820
|
+
return { client, status: 'skipped', codes: ['host_not_configured'] };
|
|
821
|
+
if (!object(entry) || entry.env !== undefined && !object(entry.env))
|
|
822
|
+
fail('configuration_shape_conflict');
|
|
823
|
+
if (client === 'codex' && entry.env_vars !== undefined && (!Array.isArray(entry.env_vars) || entry.env_vars.some((key) => typeof key !== 'string')))
|
|
824
|
+
fail('configuration_shape_conflict');
|
|
825
|
+
const permitted = client === 'codex' ? (entry.env_vars ?? []) : [];
|
|
826
|
+
const settings = {};
|
|
827
|
+
const budgetKeys = [...new Set([...budgetEnvironmentKeys, ...Object.keys(entry.env ?? {}).filter(key => key.startsWith('APTLY_MAX_') || key.startsWith('APTLY_ESTIMATED_')), ...Object.keys(environment).filter(key => (key.startsWith('APTLY_MAX_') || key.startsWith('APTLY_ESTIMATED_')) && (client === 'claude' || permitted.includes(key)))])];
|
|
828
|
+
for (const key of [...budgetKeys, 'ROUTER_LEDGER_PATH']) {
|
|
829
|
+
const value = Object.hasOwn(entry.env ?? {}, key) ? entry.env[key] : (client === 'claude' || permitted.includes(key) ? environment[key] : undefined);
|
|
830
|
+
if (value !== undefined)
|
|
831
|
+
settings[key] = value;
|
|
832
|
+
}
|
|
833
|
+
const budget = resolveBudgetSettings(settings), ledgerPath = settings.ROUTER_LEDGER_PATH;
|
|
834
|
+
if (typeof ledgerPath !== 'string')
|
|
835
|
+
fail('budget_ledger_unconfigured');
|
|
836
|
+
assertPrivateStatePath(ledgerPath);
|
|
837
|
+
const router = new Router({ policy: { ...defaultPolicy, ...budget.limits }, budgetConfigurable: true, ledgerPath,
|
|
838
|
+
provider: async () => { throw new Error('status_provider_forbidden'); } });
|
|
839
|
+
const snapshot = router.budgetStatus();
|
|
840
|
+
return { client, status: 'ok', budget: { ...snapshot, provenance: budget.provenance,
|
|
841
|
+
display_limits: Object.fromEntries(Object.entries(snapshot.limits).map(([key, value]) => [key, key !== 'estimated_call_usd' && value === 0 ? 'Unlimited' : value])),
|
|
842
|
+
next_utc_day: new Date(Date.parse(snapshot.utc_day + 'T00:00:00Z') + 86_400_000).toISOString(),
|
|
843
|
+
cost_guard: 'local_estimate_not_billing_cap', snapshot_source: 'host_registration_and_allowed_process_environment',
|
|
844
|
+
running_host_verified: false, settings_require_mcp_restart: true } };
|
|
845
|
+
}
|
|
846
|
+
catch (error) {
|
|
847
|
+
return { client, status: 'error', codes: [safeCode(error)], ...budgetErrorDetails(error) };
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
return { status: clients.some(client => client.status === 'error') ? 'partial' : 'complete', clients };
|
|
851
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -34,7 +34,9 @@ export interface Usage {
|
|
|
34
34
|
total_tokens: number;
|
|
35
35
|
}
|
|
36
36
|
export type RoutingStatus = 'recommended' | 'keep_current' | 'needs_context' | 'unavailable';
|
|
37
|
+
export type BudgetLimit = 'max_daily_calls' | 'max_total_calls' | 'max_estimated_usd';
|
|
37
38
|
export interface RoutingResult {
|
|
39
|
+
budget_limit?: BudgetLimit;
|
|
38
40
|
status: RoutingStatus;
|
|
39
41
|
reason: string;
|
|
40
42
|
application: 'advisory_only';
|
|
@@ -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
|
-
['
|
|
26
|
+
['--version', 'config', 'setup', 'remove', 'set', 'report'].includes(o.command) && !o.args.some(arg => arg === '--help' || arg === '-h') && !o.args.includes('--automatic') && !(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.8";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.8';
|
package/docs/guide/en.md
CHANGED
|
@@ -14,7 +14,7 @@ Requires Node.js 24 or later and Claude Code or Codex. Install the latest stable
|
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
npm install -g aptly@latest --allow-scripts=aptly
|
|
17
|
-
aptly
|
|
17
|
+
aptly set default
|
|
18
18
|
aptly --version
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ For npm versions without this option, or to configure explicitly instead of auto
|
|
|
34
34
|
|
|
35
35
|
```sh
|
|
36
36
|
npm install -g aptly@latest --ignore-scripts
|
|
37
|
-
aptly setup --client all
|
|
37
|
+
aptly setup --client all
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Explicit `setup` works regardless of lifecycle execution. It preserves existing launchers; use the recovery steps below for stale paths. Key setup, MCP restart, and Codex `/hooks` trust review remain separate steps.
|
|
@@ -47,7 +47,7 @@ Stop other host, MCP, and CLI processes using the ledger before updating, follow
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
aptly update
|
|
50
|
-
aptly setup --client all
|
|
50
|
+
aptly setup --client all
|
|
51
51
|
aptly --version
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -59,6 +59,23 @@ Existing MCP launchers and user wrappers are not automatically migrated. Follow
|
|
|
59
59
|
|
|
60
60
|
Only public Aptly version metadata is requested from the npm registry; no key, task summary, or host configuration is sent. Network and body reads are limited to 800ms and 16KiB. Results are cached at `~/.cache/aptly/update-check.json` for 24 hours, with a one-hour cooldown after failure. Network/cache errors cannot fail the requested command. Set `APTLY_NO_UPDATE_NOTIFIER=1` in the CLI environment to disable checks; it is not a supported key for `aptly set env`. Notifications never install updates.
|
|
61
61
|
|
|
62
|
+
<a id="command-help"></a>
|
|
63
|
+
|
|
64
|
+
### Command help (0.1.8+)
|
|
65
|
+
|
|
66
|
+
Consistent per-command and nested help is supported from Aptly 0.1.8. Use these forms:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
aptly --help
|
|
70
|
+
aptly setup -h
|
|
71
|
+
aptly set default --help
|
|
72
|
+
aptly set env OPENAI_API_KEY --help
|
|
73
|
+
aptly budget status --help
|
|
74
|
+
aptly help catalog refresh
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`--help`, `-h` and `aptly help <command path>` only show usage. They do not read settings, supplied files, stdin or credential stores; prompt; change settings; call APIs or model metadata endpoints; install/update; or run update notifications. Help can follow valid options, but unknown paths/options, invalid supplied values and contradictory option combinations remain errors. Required positional arguments may be omitted to discover usage. A form such as `--output --help` is a missing option value, not a help request that supplies an output path.
|
|
78
|
+
|
|
62
79
|
### Configure with the CLI
|
|
63
80
|
|
|
64
81
|
The `set` commands require 0.1.1 or later. Commands do not automatically switch existing launch paths. API-key setup accepts only the current package’s standard Node/server registration with a verified OS-source-compatible runtime. Custom wrappers, older versions, and other installation prefixes are rejected with `credential_launcher_unverified`; explicitly switch the registration or upgrade it before trying again.
|
|
@@ -227,15 +244,72 @@ For genuinely independent work, the caller can intentionally choose a fresh chil
|
|
|
227
244
|
| `retry_spawn_recommendation` | Accepts one task-description supplement using a Hook-issued retry_id |
|
|
228
245
|
| `prepare_fresh_delegation` | Prepares a separate independent Codex call from completed inherited advice; never executes it |
|
|
229
246
|
|
|
230
|
-
###
|
|
247
|
+
### Confidence and abstention
|
|
248
|
+
|
|
249
|
+
`confidence` is metadata and has not been validated here as a calibrated probability of correctness. It is not currently used as an automatic-application threshold. Zero and low values are currently allowed when other application conditions hold. A missing value in a live Decisions response is rejected as an error; it remains optional in generic Router and stored results. `keep_current` and `needs_context` are separate outcomes with existing abstention and context-recovery rules. Explicit model, effort, history and permissions are preserved. A small classification pilot does not establish improved child-task quality or total cost.
|
|
250
|
+
|
|
251
|
+
<a id="budget-limits"></a>
|
|
252
|
+
|
|
253
|
+
### Budget limits and usage (0.1.8+)
|
|
254
|
+
|
|
255
|
+
Budget environment settings and usage status are supported from Aptly 0.1.8. `aptly set default` also fills missing budget environment settings for selected hosts. It adds no budget questionnaire, preserves existing values including explicit `0`, and does not reset usage, ledgers or caches. The existing transmission-scope question is separate. Existing registrations without budget variables also use the new runtime defaults after upgrade. The old implicit 20-call/50-call/$0.50 ceilings are not retained; configure any limits you require explicitly.
|
|
256
|
+
|
|
257
|
+
| Environment variable | Default | Meaning |
|
|
258
|
+
|---|---:|---|
|
|
259
|
+
| `APTLY_MAX_DAILY_CALLS` | `200` | Per-ledger UTC daily classification-attempt ceiling |
|
|
260
|
+
| `APTLY_MAX_TOTAL_CALLS` | `0` | Per-ledger cumulative attempt ceiling |
|
|
261
|
+
| `APTLY_MAX_ESTIMATED_USD` | `0` | Cumulative local reservation ceiling |
|
|
262
|
+
| `APTLY_ESTIMATED_CALL_USD` | `0.002` | Estimated dollars reserved for each new classification attempt |
|
|
263
|
+
|
|
264
|
+
Zero means unlimited for the three ceilings. The per-attempt reservation is a rate and must stay positive. Only literal `0` means unlimited; forms such as `0.0` and `0.00` are rejected. Unset uses defaults; empty, negative, malformed or exponent notation values are rejected. Calls use whole integers; money uses fixed decimal notation with at most six fractional digits. Maximum finite settings are 100,000 daily calls, 1,000,000 cumulative calls and 100 for monetary values. A finite cost ceiling must cover one reservation. Existing invalid settings are not silently overwritten.
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
aptly set env APTLY_MAX_DAILY_CALLS
|
|
268
|
+
aptly set env APTLY_MAX_TOTAL_CALLS
|
|
269
|
+
aptly set env APTLY_MAX_ESTIMATED_USD
|
|
270
|
+
aptly set env APTLY_ESTIMATED_CALL_USD
|
|
271
|
+
aptly budget status --client codex
|
|
272
|
+
aptly budget status --client claude
|
|
273
|
+
```
|
|
231
274
|
|
|
232
|
-
|
|
275
|
+
Setting commands support `--client codex|claude|all`, hidden input and explicit `--stdin`. Restart MCP after changes. Defaults also preserve existing Codex budget passthrough bindings in `env_vars` and Claude budget values observed in this CLI process environment, listed as `inherited`. Direct `recommend`/`capabilities` use the CLI process environment and do not automatically read host settings files. Status briefly holds the existing gate, so a concurrent request can receive temporary `ledger_locked`. Status is a snapshot of registration and permitted current environment settings, not verification of custom wrappers or the running host. It reads no keys, API or task text and creates no ledger or gate. Unlimited ceilings display `Unlimited` with `null` remaining. Sessions sharing a ledger share its budget; other ledgers and account-wide OpenAI usage are not aggregated.
|
|
276
|
+
|
|
277
|
+
`budget_exhausted` is local, not an OpenAI authentication or account-credit error. Direct/retry responses identify `budget_limit`; status lists `exhausted_by`. Reservations are not an actual billing cap and do not reset monthly. Changing the rate does not reprice past reservations; replacing a key or applying defaults does not refund them.
|
|
278
|
+
|
|
279
|
+
New pre-HTTP budget denials are not cached. Only verifiable known-unpaid legacy default-policy denials can be reevaluated with the same ID; completed recommendations, abstentions, context outcomes and `unknown` remain protected. Budget recovery does not extend the original five-minute retry reference or process lifetime and does not remove history or permission constraints. Arbitrary historical custom-policy digests are not guessed; do not bypass conflicts/unknowns with new IDs or ledger deletion.
|
|
280
|
+
|
|
281
|
+
<a id="outbound-data-and-disabling-automatic-sharing"></a>
|
|
282
|
+
|
|
283
|
+
### Decisions API transmission scope
|
|
284
|
+
|
|
285
|
+
The transmission commands in this section are supported from Aptly 0.1.7.
|
|
286
|
+
|
|
287
|
+
Transmission means **sending local task information to the OpenAI Decisions API**, not providing tasks to Aptly developers. Application mode `defaults/advisory` and transmission scope are independent. New registrations use v2 policy with `unselected` scope and make no automatic transmission. Interactive `aptly set default` asks only for unselected hosts; Enter selects `none`. Noninteractive runs and postinstall neither prompt nor count as consent.
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
aptly set transmission --show
|
|
291
|
+
aptly set transmission none
|
|
292
|
+
aptly set transmission description
|
|
293
|
+
aptly set transmission excerpt
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The change commands above show alternatives; run only the one you want. Use `--client codex|claude|all` to select hosts. `none` disables automatic transmission and preserves the original call. `description` permits only a parent-supplied description. Without one, it requests context before calling the API and never falls back to native body or label. `defaults` denies the unresolved spawn; `advisory` supplies feedback only. `excerpt` permits existing native excerpts and explicit descriptions. Source, size and known-secret checks establish neither non-sensitive content nor user consent.
|
|
297
|
+
|
|
298
|
+
Existing v1 policies remain byte-identical and report `excerpt` with `legacy` provenance. An explicit change migrates the policy to v2 and updates its ownership receipt together. Modified policies and custom launchers are not silently adopted; conflicts preserve them. Keys, ledgers and unknown records are not deleted. Restart MCP after changes. Already-started transmission cannot be recalled; changed policy prevents in-flight results, retry and fresh preparation from applying. Do not bypass an old call-binding conflict with a new paid identity. Explicit `recommend_agent` and `aptly recommend` requests remain separate and are not prohibited by this automatic-transmission setting.
|
|
299
|
+
|
|
300
|
+
Manually setting `enabled: false` remains an emergency stop, but can conflict with ownership records. Use the commands above for normal changes and never edit ownership receipts to bypass checks.
|
|
301
|
+
|
|
302
|
+
### Outbound content and filtering limits
|
|
303
|
+
|
|
304
|
+
Under `excerpt` scope, Without prepared context, automatic classification `summary` is an **excerpt assembled from an accepted task label and the clipped first paragraph** of the body. It is not a semantic rewrite or anonymization. Its UTF-8 size is at most `min(4000, max_summary_bytes)`; this is not a limit on the whole HTTP request. The opaque-message fallback in Codex uses only a sufficiently descriptive `task_name`, without decoding or transmitting that body. Labels can also contain sensitive information.
|
|
305
|
+
|
|
306
|
+
A valid `prepare_spawn_context` description and fixed prefix replace the native excerpt for classification; registration itself makes no API call. After a needs-context response, `retry_spawn_recommendation` can classify one new supplement with a fixed prefix, without appending the earlier body. Both paths limit the raw description to `min(3800, max_summary_bytes - 96)` bytes and the prefixed summary to `min(4000, max_summary_bytes)` bytes. `prepare_fresh_delegation` itself reuses completed advice without another classification and returns standalone instructions as local next-call arguments. A Codex call submitted with the returned explicit model and effort is currently preserved by the Hook as `explicit_model`, without classification. Checking a later call does not imply another classification. None of these paths establishes that descriptions are non-sensitive or automatically anonymized.
|
|
233
307
|
|
|
234
308
|
Decisions receives `client`, `task.summary`, `task.operation`, `task.context_sufficient`, candidate profile IDs, model/effort descriptions, and configured model facts. The classification API key is sent in `Authorization`; the request ID is sent in `X-Client-Request-Id`. Automatic IDs are hashes; direct recommendation IDs are caller-supplied. Do not put secrets in IDs or candidate descriptions.
|
|
235
309
|
|
|
236
310
|
To disable automatic sharing, change **only `enabled` to `false`** in the existing private policy file referenced by `APTLY_HOOK_POLICY_PATH`. Preserve the other fields and ownership record. Subsequent automatic Hook calls preserve the original call before classification or creation of a call-binding file. This cannot undo a transmission already started or recall information received by the server. Editing a generated policy can cause ownership conflicts in setup, configuration, or removal commands; those commands do not overwrite the disabled policy. Do not edit ownership records to bypass the checks.
|
|
237
311
|
|
|
238
|
-
`mode: advisory` still transmits classification data; it is not a privacy opt-out. Removing `APTLY_HOOK_POLICY_PATH` can activate the older strict path, so do not use removal as an alternative. `enabled: false` does not block explicit `recommend_agent` or `aptly recommend` requests.
|
|
312
|
+
When the transmission scope permits it, `mode: advisory` still transmits classification data; it is not a privacy opt-out. Removing `APTLY_HOOK_POLICY_PATH` can activate the older strict path, so do not use removal as an alternative. `enabled: false` does not block explicit `recommend_agent` or `aptly recommend` requests.
|
|
239
313
|
|
|
240
314
|
For control over the shared summary, disable automatic sharing and write only the information needed for a direct recommendation. Aptly does not automatically fetch documents at URLs or attach source files mentioned in the summary. Checks for known key and Bearer patterns do not provide complete secret detection or establish that text is safe to transmit.
|
|
241
315
|
|
|
@@ -255,6 +329,8 @@ One supplement is allowed per original call. Duplicate input reuses the cache; c
|
|
|
255
329
|
|
|
256
330
|
The retry response includes `next_call.set_if_unspecified` with concrete fields for the next native call. It excludes already specified model/effort fields and never adds Claude effort. Blocked history/application results omit `next_call`. These fields are neither execution evidence nor permission approval.
|
|
257
331
|
|
|
332
|
+
Cache reuse requires a completed first result. An unknown outcome remains `outcome_unknown`; do not repeat a paid call with a new ID.
|
|
333
|
+
|
|
258
334
|
`context_retry_allowed: false` ends further context supplementation. For a compatible recommendation, `caller_review_required` means the parent reviews arguments; it does not request new user approval. Existing delegation authorization and host permission checks still apply.
|
|
259
335
|
|
|
260
336
|
### Automatic routing guarantees and blocked outcomes (0.1.5+)
|
package/docs/guide/ja.md
CHANGED
|
@@ -14,7 +14,7 @@ Node.js 24 以上と Claude Code または Codex が必要です。npm の最新
|
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
npm install -g aptly@latest --allow-scripts=aptly
|
|
17
|
-
aptly
|
|
17
|
+
aptly set default
|
|
18
18
|
aptly --version
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ aptly --version
|
|
|
34
34
|
|
|
35
35
|
```sh
|
|
36
36
|
npm install -g aptly@latest --ignore-scripts
|
|
37
|
-
aptly setup --client all
|
|
37
|
+
aptly setup --client all
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
スクリプトの実行にかかわらず、明示的な `setup` を利用できます。既存の起動パスは保持するため、旧パスのエラーは以下の復旧手順に従ってください。キー設定・MCP の再起動と Codex の `/hooks` 信頼確認は別途必要です。
|
|
@@ -47,7 +47,7 @@ aptly setup --client all --mode defaults
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
aptly update
|
|
50
|
-
aptly setup --client all
|
|
50
|
+
aptly setup --client all
|
|
51
51
|
aptly --version
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -59,6 +59,23 @@ aptly --version
|
|
|
59
59
|
|
|
60
60
|
公開 npm レジストリから Aptly のバージョン情報のみを取得し、キー・タスク要約・ホスト設定は送信しません。ネットワークと応答読み取りは 800ms・16KiB に制限し、結果を `~/.cache/aptly/update-check.json` に 24 時間キャッシュします。失敗後は 1 時間待機し、通信・キャッシュエラーで元のコマンドを失敗させません。CLI の環境に `APTLY_NO_UPDATE_NOTIFIER=1` を設定すると確認を停止できます。この変数は `aptly set env` の対象ではありません。通知による自動更新は行いません。
|
|
61
61
|
|
|
62
|
+
<a id="command-help"></a>
|
|
63
|
+
|
|
64
|
+
### コマンドヘルプ(0.1.8 以降)
|
|
65
|
+
|
|
66
|
+
コマンド・サブコマンドごとの統一されたヘルプは Aptly 0.1.8 以降で利用できます。次の形式を使えます。
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
aptly --help
|
|
70
|
+
aptly setup -h
|
|
71
|
+
aptly set default --help
|
|
72
|
+
aptly set env OPENAI_API_KEY --help
|
|
73
|
+
aptly budget status --help
|
|
74
|
+
aptly help catalog refresh
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`--help`・`-h`・`aptly help <コマンド経路>` は使用法だけを表示します。設定・指定ファイル・stdin・資格情報ストアの読み取り、質問、設定変更、API・モデル情報取得、インストール・更新、更新通知は実行しません。有効なオプションの後にもヘルプを付けられますが、不明な経路・オプション、不正な指定値、矛盾する組み合わせはエラーです。必須の位置引数を省略して使用法を調べられます。`--output --help` のようにヘルプをオプション値の位置に置くと、値の欠落として扱います。
|
|
78
|
+
|
|
62
79
|
### CLI による設定
|
|
63
80
|
|
|
64
81
|
`set` コマンドは 0.1.1 以降で利用できます。既存の起動パスは自動で切り替えません。API キー設定は、現在のパッケージの標準 Node/サーバー登録で、OS 資格情報の参照に対応する実行環境だと確認できた場合にのみ使用できます。独自ラッパー、旧バージョン、別のインストール先は `credential_launcher_unverified` で拒否します。登録を明示的に切り替えるかアップグレードしてから、再度実行してください。
|
|
@@ -227,15 +244,72 @@ Codex の本文が不透明な場合、`cleanup_merged_worktrees` のような
|
|
|
227
244
|
| `retry_spawn_recommendation` | Hook が返す retry_id を使い、タスク説明を一度補って再推薦します |
|
|
228
245
|
| `prepare_fresh_delegation` | 完了済みの継承推薦から別の独立 Codex 呼び出し引数を準備し、実行はしません |
|
|
229
246
|
|
|
230
|
-
###
|
|
247
|
+
### confidence と推薦の保留
|
|
248
|
+
|
|
249
|
+
`confidence` はメタデータであり、校正された正解確率としては検証されていません。現在、自動適用の閾値としては使用しません。現在は他の適用条件を満たせば、0 や低い値も許容します。実際の Decisions 応答で値が欠けている場合はエラーとして拒否しますが、汎用 Router と保存結果では任意項目です。`keep_current` と `needs_context` は数値とは別の結果であり、既存の保留・文脈補足規則に従います。明示されたモデル・effort・履歴・権限は保持します。小規模な分類評価だけで、子タスクの品質や総費用の改善を主張しません。
|
|
250
|
+
|
|
251
|
+
<a id="budget-limits"></a>
|
|
252
|
+
|
|
253
|
+
### 予算上限と使用量(0.1.8 以降)
|
|
254
|
+
|
|
255
|
+
予算環境設定と使用量照会は Aptly 0.1.8 以降で利用できます。`aptly set default` は選択したホストの未設定の予算環境変数も補います。予算に関する追加の質問はなく、明示的な `0` を含む既存値を保持し、使用量・台帳・キャッシュをリセットしません。既存の送信範囲の質問は別です。予算変数がない既存登録も、アップグレード後は新しいランタイム既定値を使います。従来の暗黙の 20 回・50 回・$0.50 の上限は維持されないため、必要な上限を明示的に設定してください。
|
|
256
|
+
|
|
257
|
+
| 環境変数 | 既定値 | 意味 |
|
|
258
|
+
|---|---:|---|
|
|
259
|
+
| `APTLY_MAX_DAILY_CALLS` | `200` | 台帳ごとの UTC 日次分類試行上限 |
|
|
260
|
+
| `APTLY_MAX_TOTAL_CALLS` | `0` | 台帳ごとの累積分類試行上限 |
|
|
261
|
+
| `APTLY_MAX_ESTIMATED_USD` | `0` | 累積ローカル予約額の上限 |
|
|
262
|
+
| `APTLY_ESTIMATED_CALL_USD` | `0.002` | 新しい分類試行ごとに予約する推定ドル額 |
|
|
263
|
+
|
|
264
|
+
三つの上限では `0` が無制限を意味します。試行ごとの予約単価は上限ではないため正数が必要です。無制限には厳密な `0` を使い、`0.0` や `0.00` は拒否します。未設定なら既定値を使い、空文字・負数・不正な数値・指数表記は拒否します。呼び出し数は整数、金額は小数点以下最大 6 桁の十進表記です。有限値の上限は日次 100,000 回・累積 1,000,000 回・金額設定 100 です。有限の金額上限は 1 回分の予約額以上である必要があります。既存の不正な値を自動で置き換えません。
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
aptly set env APTLY_MAX_DAILY_CALLS
|
|
268
|
+
aptly set env APTLY_MAX_TOTAL_CALLS
|
|
269
|
+
aptly set env APTLY_MAX_ESTIMATED_USD
|
|
270
|
+
aptly set env APTLY_ESTIMATED_CALL_USD
|
|
271
|
+
aptly budget status --client codex
|
|
272
|
+
aptly budget status --client claude
|
|
273
|
+
```
|
|
231
274
|
|
|
232
|
-
|
|
275
|
+
設定コマンドは `--client codex|claude|all`、非表示入力と明示的な `--stdin` に対応します。変更後は MCP を再起動してください。既存の Codex `env_vars` による予算変数の転送設定と、この CLI 実行環境で確認できる Claude の継承予算値も既定値で隠さず、`inherited` に表示します。直接の `recommend`・`capabilities` は CLI プロセスの環境を使い、ホスト設定ファイルを自動参照しません。状態照会は既存 gate を短時間占有するため、同時要求では一時的に `ledger_locked` が返る場合があります。状態は登録と許可された現在の環境のスナップショットであり、独自ラッパーや実行中ホストの値を認証しません。キー・API・タスク原文を参照せず、台帳や gate を作成しません。無制限は `Unlimited`、残量は `null` で表示します。同じ台帳を使うセッションは予算を共有しますが、他の台帳や OpenAI アカウント全体の使用量は合算しません。
|
|
276
|
+
|
|
277
|
+
`budget_exhausted` はローカル制限であり、OpenAI 認証や残高のエラーではありません。直接推薦・文脈補足の応答の `budget_limit` と状態の `exhausted_by` で上限を区別します。予約額は実際の請求上限ではなく、月次で自動リセットしません。単価変更で過去の予約を再計算せず、キー再入力や既定値適用で返金しません。
|
|
278
|
+
|
|
279
|
+
HTTP 前の新しい予算拒否はキャッシュしません。検証可能な既存の既定ポリシーによる未課金の拒否だけを同じ ID で再評価し、完了した推薦・保留・文脈不足の結果と `unknown` は保持します。予算回復は元の retry 参照の 5 分やプロセス寿命を延長せず、履歴や権限の制約も解除しません。任意の過去の独自ポリシーの digest を推測せず、新しい ID や台帳削除で競合・不明結果を回避しないでください。
|
|
280
|
+
|
|
281
|
+
<a id="外部送信と自動共有の無効化"></a>
|
|
282
|
+
|
|
283
|
+
### Decisions API への送信範囲
|
|
284
|
+
|
|
285
|
+
この節の送信範囲コマンドは Aptly 0.1.7 以降で利用できます。
|
|
286
|
+
|
|
287
|
+
ここでの送信は、**ローカルのタスク情報を OpenAI Decisions API に送ること**であり、Aptly の開発者にタスクを提供する機能ではありません。適用モード `defaults/advisory` と送信範囲は別の設定です。新規登録は v2 ポリシーの `unselected` となり、自動送信しません。対話形式の `aptly set default` は未選択のホストだけに範囲を尋ね、Enter では `none` を選択します。非対話実行と postinstall は質問せず、同意したものとして扱いません。
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
aptly set transmission --show
|
|
291
|
+
aptly set transmission none
|
|
292
|
+
aptly set transmission description
|
|
293
|
+
aptly set transmission excerpt
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
変更コマンドは選択肢を示しています。希望する一つだけを実行してください。`--client codex|claude|all` で対象を選べます。`none` は自動送信を停止し、元の呼び出しを保持します。`description` は親エージェントが提供した説明だけを許可します。説明がなければ API 呼び出し前に文脈補足を求め、native 本文やラベルには自動で切り替えません。`defaults` は未解決の spawn を拒否し、`advisory` は案内のみを返します。`excerpt` は既存の native 抜粋と明示的な説明を許可します。出所・サイズ・既知の秘密パターンの検査は、非機密性やユーザーの同意を証明しません。
|
|
297
|
+
|
|
298
|
+
既存の v1 ポリシーはバイト単位で保持され、出所 `legacy` の `excerpt` と表示されます。明示的な変更時だけ v2 に移行し、所有権記録も同時に更新します。変更済みポリシーや独自ランチャーを自動で引き継がず、競合時は保持します。キー・台帳・不明な記録は削除しません。変更後は MCP を再起動してください。開始済みの送信は回収できず、ポリシー変更前の処理中結果・retry・fresh 準備は適用されません。既存の結合競合を新しい有料 ID で回避しないでください。明示的な `recommend_agent` と `aptly recommend` は別の要求であり、この自動送信設定では禁止しません。
|
|
299
|
+
|
|
300
|
+
手動の `enabled: false` は緊急停止として有効ですが、所有権記録と競合する場合があります。通常の変更には上記コマンドを使い、検査を回避するために所有権記録を編集しないでください。
|
|
301
|
+
|
|
302
|
+
### 送信内容とフィルターの限界
|
|
303
|
+
|
|
304
|
+
`excerpt` の範囲では、事前登録された説明がない場合、自動分類の `summary` は、有効なタスクラベルと本文の**最初の段落を切り詰めて組み合わせた抜粋**です。意味を再要約したものでも、匿名化したものでもありません。UTF-8 のサイズは `min(4000, max_summary_bytes)` 以下ですが、HTTP リクエスト全体の上限ではありません。Codex の opaque メッセージへのフォールバックでは、本文を復号・送信せず、十分に具体的な `task_name` だけを使用します。ラベルにも機密情報が含まれる可能性があります。
|
|
305
|
+
|
|
306
|
+
有効な `prepare_spawn_context` の説明は、固定の接頭辞とともに native の抜粋に代わって分類に使用されます。登録自体は API を呼び出しません。文脈不足の応答後、`retry_spawn_recommendation` は以前の本文を付け加えず、固定の接頭辞と新しい補足説明で一度だけ再推薦できます。両経路とも説明原文は `min(3800, max_summary_bytes - 96)` バイト以下、接頭辞を含む説明は `min(4000, max_summary_bytes)` バイト以下です。`prepare_fresh_delegation` 自体は完了済みの推薦を再利用し、追加の分類を呼び出さず、独立した指示をローカルの次回呼び出し引数として返します。返されたモデルと effort をそのまま明示した Codex 呼び出しは、現在の Hook で `explicit_model` として分類せずに保持されます。後続の呼び出しを検査することは、追加の分類を意味しません。どの経路も、説明に機密情報が含まれないことや自動的な匿名化を保証しません。
|
|
233
307
|
|
|
234
308
|
Decisions には `client`、`task.summary`、`task.operation`、`task.context_sufficient` と、候補プロファイル ID・モデルと effort の説明・設定したモデル特性を送信します。分類用 API キーは `Authorization` ヘッダー、リクエスト ID は `X-Client-Request-Id` ヘッダーで送信します。自動経路の ID はハッシュで、直接推薦の ID は呼び出し元が指定します。ID や候補の説明にも秘密情報を含めないでください。
|
|
235
309
|
|
|
236
310
|
自動共有を無効にするには、`APTLY_HOOK_POLICY_PATH` が指す既存の非公開ポリシーファイルで、**`enabled` だけを `false` に変更**してください。他のフィールドと所有権の記録は保持してください。その後の自動 Hook 呼び出しは、分類や呼び出しバインディングファイルの作成前に元の呼び出しを保持します。開始済みの送信を取り消したり、サーバーが受信した情報を回収したりすることはできません。生成済みのポリシーを変更すると、登録・設定・削除コマンドの所有権検査で競合する場合があり、それらのコマンドは無効化したポリシーを上書きしません。検査を回避するために所有権の記録を編集しないでください。
|
|
237
311
|
|
|
238
|
-
`mode: advisory` でも分類データは送信されるため、プライバシー上の共有停止にはなりません。`APTLY_HOOK_POLICY_PATH` を削除すると従来の strict 経路が有効になる場合があるため、共有停止の代わりにしないでください。`enabled: false` は、明示的な `recommend_agent` や `aptly recommend` のリクエストを止めるものではありません。
|
|
312
|
+
送信範囲で許可されていれば `mode: advisory` でも分類データは送信されるため、プライバシー上の共有停止にはなりません。`APTLY_HOOK_POLICY_PATH` を削除すると従来の strict 経路が有効になる場合があるため、共有停止の代わりにしないでください。`enabled: false` は、明示的な `recommend_agent` や `aptly recommend` のリクエストを止めるものではありません。
|
|
239
313
|
|
|
240
314
|
共有する要約を自分で選ぶ場合は、自動共有を無効にしてから直接推薦に必要な情報だけを記述してください。Aptly は要約中の URL の文書や、言及されたソースファイルを自動取得・添付しません。既知のキーや Bearer のパターン検査は、完全な秘密情報の検出や送信の安全性を保証しません。
|
|
241
315
|
|
|
@@ -255,6 +329,8 @@ Decisions には `client`、`task.summary`、`task.operation`、`task.context_su
|
|
|
255
329
|
|
|
256
330
|
再推薦の応答は `next_call.set_if_unspecified` に次の native 呼び出しで補う具体的な未指定フィールドを返します。明示済みのモデル・effort は含めず、Claude に effort を追加しません。履歴などで適用できない結果には `next_call` を返しません。実行証拠や権限承認ではありません。
|
|
257
331
|
|
|
332
|
+
キャッシュを再利用できるのは最初の結果が完了した場合です。結果が不明なら `outcome_unknown` を保持し、新しい ID で有料呼び出しを繰り返さないでください。
|
|
333
|
+
|
|
258
334
|
`context_retry_allowed: false` は追加の文脈補足を終了する意味です。互換性のある推薦の `caller_review_required` は親が引数を確認する意味であり、新しいユーザー承認の要求ではありません。既存の委任権限とホストの権限確認は引き続き適用されます。
|
|
259
335
|
|
|
260
336
|
### 自動ルーティングの保証範囲と拒否結果(0.1.5 以降)
|