aptly 0.1.20 → 0.1.22
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 -10
- package/README.ja.md +3 -10
- package/README.md +3 -10
- package/README.zh-CN.md +3 -10
- package/dist/bin/aptly.js +32 -8
- package/dist/src/automatic-hook.js +4 -4
- package/dist/src/cli-help.js +4 -2
- package/dist/src/context-retry.js +1 -1
- package/dist/src/core.d.ts +2 -2
- package/dist/src/core.js +39 -9
- package/dist/src/doctor.d.ts +1 -0
- package/dist/src/doctor.js +1 -1
- package/dist/src/provider.js +9 -3
- package/dist/src/server.js +16 -2
- package/dist/src/setup.d.ts +2 -1
- package/dist/src/setup.js +64 -27
- package/dist/src/stable-runtime.d.ts +4 -0
- package/dist/src/stable-runtime.js +119 -18
- package/dist/src/update.d.ts +19 -0
- package/dist/src/update.js +84 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/docs/guide/en/configuration.md +16 -1
- package/docs/guide/en/installation.md +40 -3
- package/docs/guide/ja/configuration.md +16 -1
- package/docs/guide/ja/installation.md +40 -3
- package/docs/guide/ko/configuration.md +16 -1
- package/docs/guide/ko/installation.md +40 -3
- package/docs/guide/zh-CN/configuration.md +16 -1
- package/docs/guide/zh-CN/installation.md +40 -3
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -24,22 +24,15 @@ aptly set default
|
|
|
24
24
|
aptly set env OPENAI_API_KEY
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Choose the transmission scope in `set default` and enter your API key through the hidden prompt. Restart the host, then **review and approve the new Hook in `/hooks` for Codex**. See [installation and
|
|
27
|
+
Choose the transmission scope in `set default` and enter your API key through the hidden prompt. Restart the host, then **review and approve the new Hook in `/hooks` for Codex**. See [installation and setup verification](docs/guide/en/installation.md#guide-verify-setup) to check the registration.
|
|
28
28
|
|
|
29
29
|
## Update
|
|
30
30
|
|
|
31
|
-
Stop the
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
aptly update
|
|
35
|
-
aptly setup --client all
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Restart the host. You do not need to re-enter the key. If migrating a stable launcher or an older version, see [updates](docs/guide/en/installation.md#guide-package-updates).
|
|
31
|
+
Stop the related hosts, MCP servers, and CLI processes, then run `aptly update`. On macOS and Linux, the update migrates existing Aptly-owned registrations to managed npx. On Windows, it updates the package. When upgrading from 0.1.21, run `aptly update` again with the new CLI. Approve changed Codex Hooks in `/hooks` and restart the host. [Update guide](docs/guide/en/installation.md#guide-package-updates)
|
|
39
32
|
|
|
40
33
|
## Documentation
|
|
41
34
|
|
|
42
35
|
- [User guide](docs/guide/en.md): configuration, automatic recommendations, budgets, statistics, and troubleshooting
|
|
43
36
|
- [Model candidates](docs/guide/en/configuration.md#guide-models-and-environment)
|
|
44
37
|
- [Transmission scope](docs/guide/en/transmission.md): information sent to the Decisions API
|
|
45
|
-
- [Measured costs](docs/guide/en/benchmarks.md) —
|
|
38
|
+
- [Measured costs](docs/guide/en/benchmarks.md) — For one README review task with three runs per condition, subagent review and Decisions classification costs at Standard API rates were about 52–58% lower with explicit MCP recommendations.
|
package/README.ja.md
CHANGED
|
@@ -24,22 +24,15 @@ aptly set default
|
|
|
24
24
|
aptly set env OPENAI_API_KEY
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`set default` で送信範囲を選び、API キーは非表示入力で登録します。ホストを再起動した後、**Codex では `/hooks` で新しい Hook
|
|
27
|
+
`set default` で送信範囲を選び、API キーは非表示入力で登録します。ホストを再起動した後、**Codex では `/hooks` で新しい Hook を確認・承認**してください。登録状況の確認方法は[インストールと設定の確認](docs/guide/ja/installation.md#guide-verify-setup)を参照してください。
|
|
28
28
|
|
|
29
29
|
## 更新
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
aptly update
|
|
35
|
-
aptly setup --client all
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
ホストを再起動してください。キーの再入力は不要です。stable ランチャーや以前のバージョンから移行する場合は、[更新案内](docs/guide/ja/installation.md#guide-package-updates)を確認してください。
|
|
31
|
+
関連するホスト・MCP サーバー・CLI を停止してから `aptly update` を実行してください。macOS と Linux では Aptly が所有する既存登録を管理型 npx に移行し、Windows ではパッケージを更新します。0.1.21 から更新する場合は、新しい CLI で `aptly update` をもう一度実行してください。変更された Codex Hook を `/hooks` で承認し、ホストを再起動してください。[更新ガイド](docs/guide/ja/installation.md#guide-package-updates)
|
|
39
32
|
|
|
40
33
|
## ドキュメント
|
|
41
34
|
|
|
42
35
|
- [使用ガイド](docs/guide/ja.md): 設定・自動推薦・予算・統計・トラブルシューティング
|
|
43
36
|
- [候補モデルの設定](docs/guide/ja/configuration.md#guide-models-and-environment)
|
|
44
37
|
- [送信範囲](docs/guide/ja/transmission.md): Decisions API に送る情報
|
|
45
|
-
- [費用実測](docs/guide/ja/benchmarks.md) —
|
|
38
|
+
- [費用実測](docs/guide/ja/benchmarks.md) — 1 つの README レビュー課題を各条件で 3 回ずつ実行しました。明示的な MCP 推薦を使った場合、サブエージェントのレビューと Decisions の分類にかかる費用は、Standard API の単価で換算すると約 52~58% 低くなりました。
|
package/README.md
CHANGED
|
@@ -24,22 +24,15 @@ aptly set default
|
|
|
24
24
|
aptly set env OPENAI_API_KEY
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`set default`에서 전송 범위를 선택하고 API 키는 숨김 입력으로 등록합니다. 호스트를 재시작한 뒤 **Codex는 `/hooks`에서 새 Hook을 검토·승인**하십시오. [
|
|
27
|
+
`set default`에서 전송 범위를 선택하고 API 키는 숨김 입력으로 등록합니다. 호스트를 재시작한 뒤 **Codex는 `/hooks`에서 새 Hook을 검토·승인**하십시오. [설치·설정 확인](docs/guide/ko/installation.md#guide-verify-setup)에서 등록 상태를 점검할 수 있습니다.
|
|
28
28
|
|
|
29
29
|
## 업데이트
|
|
30
30
|
|
|
31
|
-
관련 호스트·MCP
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
aptly update
|
|
35
|
-
aptly setup --client all
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
호스트를 재시작하십시오. 키를 다시 입력할 필요는 없습니다. stable 실행기나 이전 버전에서 전환하는 경우 [업데이트 안내](docs/guide/ko/installation.md#guide-package-updates)를 확인하십시오.
|
|
31
|
+
관련 호스트·MCP·CLI를 중지한 뒤 `aptly update`를 실행하십시오. macOS·Linux에서는 기존 Aptly 소유 등록을 관리형 npx로 전환하고, Windows에서는 패키지를 갱신합니다. 0.1.21에서 올리는 경우 새 CLI로 `aptly update`를 한 번 더 실행하십시오. 변경된 Codex Hook을 `/hooks`에서 승인하고 호스트를 재시작하십시오. [업데이트 안내](docs/guide/ko/installation.md#guide-package-updates)
|
|
39
32
|
|
|
40
33
|
## 문서
|
|
41
34
|
|
|
42
35
|
- [사용 가이드](docs/guide/ko.md): 설정·자동 추천·예산·통계·문제 해결
|
|
43
36
|
- [모델 후보 설정](docs/guide/ko/configuration.md#guide-models-and-environment)
|
|
44
37
|
- [전송 범위](docs/guide/ko/transmission.md): Decisions API에 보내는 정보
|
|
45
|
-
- [비용 실측](docs/guide/ko/benchmarks.md) —
|
|
38
|
+
- [비용 실측](docs/guide/ko/benchmarks.md) — README 검토 과제 하나를 조건별로 3회씩 실행했습니다. 명시적 MCP 추천을 사용했을 때 서브에이전트 검토와 Decisions 분류의 Standard API 환산 비용이 약 52~58% 낮았습니다.
|
package/README.zh-CN.md
CHANGED
|
@@ -24,22 +24,15 @@ aptly set default
|
|
|
24
24
|
aptly set env OPENAI_API_KEY
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
请在 `set default` 中选择传输范围,并通过隐藏输入注册 API 密钥。重启宿主后,**请在 Codex 的 `/hooks` 中审核并批准新 Hook
|
|
27
|
+
请在 `set default` 中选择传输范围,并通过隐藏输入注册 API 密钥。重启宿主后,**请在 Codex 的 `/hooks` 中审核并批准新 Hook**。如需检查注册状态,请参阅[安装与设置验证](docs/guide/zh-CN/installation.md#guide-verify-setup)。
|
|
28
28
|
|
|
29
29
|
## 更新
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
aptly update
|
|
35
|
-
aptly setup --client all
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
请重启宿主,无需重新输入密钥。如果从 stable 启动器或旧版本迁移,请参阅[更新指南](docs/guide/zh-CN/installation.md#guide-package-updates)。
|
|
31
|
+
关闭相关宿主、MCP 服务器和 CLI 后,运行 `aptly update`。在 macOS 和 Linux 上,更新会将 Aptly 管理的现有注册迁移到托管 npx。在 Windows 上,更新会升级软件包。从 0.1.21 升级时,请使用新的 CLI 再运行一次 `aptly update`。请在 Codex 的 `/hooks` 中批准变更后的 Hook,然后重启宿主。[更新指南](docs/guide/zh-CN/installation.md#guide-package-updates)
|
|
39
32
|
|
|
40
33
|
## 文档
|
|
41
34
|
|
|
42
35
|
- [使用指南](docs/guide/zh-CN.md):设置、自动推荐、预算、统计与问题排查
|
|
43
36
|
- [候选模型设置](docs/guide/zh-CN/configuration.md#guide-models-and-environment)
|
|
44
37
|
- [传输范围](docs/guide/zh-CN/transmission.md):发送给 Decisions API 的信息
|
|
45
|
-
- [成本实测](docs/guide/zh-CN/benchmarks.md)
|
|
38
|
+
- [成本实测](docs/guide/zh-CN/benchmarks.md):对同一个 README 审阅任务,每种条件各运行 3 次。使用显式 MCP 推荐时,按 Standard API 单价折算的子代理审阅和 Decisions 分类费用低了约 52%~58%。
|
package/dist/bin/aptly.js
CHANGED
|
@@ -15,7 +15,7 @@ import { checkSetup, setupHosts, removeSetup, setDefaults, setEnvironment, confi
|
|
|
15
15
|
import { readEnvironmentValue } from '../src/cli-input.js';
|
|
16
16
|
import { prepareApiKey } from '../src/credential-setup.js';
|
|
17
17
|
import { linuxStoreReadiness } from '../src/linux-store-readiness.js';
|
|
18
|
-
import {
|
|
18
|
+
import { updateGlobalAndMigrate } from '../src/update.js';
|
|
19
19
|
import { updateNotification } from '../src/update-notifier.js';
|
|
20
20
|
import { resolveCliHelp } from '../src/cli-help.js';
|
|
21
21
|
import { runTransmissionReview, reviewAfterSetup } from '../src/transmission-review-cli.js';
|
|
@@ -34,15 +34,39 @@ try {
|
|
|
34
34
|
process.stdout.write(help.text);
|
|
35
35
|
}
|
|
36
36
|
else if (command === 'update') {
|
|
37
|
-
|
|
37
|
+
let updateClient;
|
|
38
|
+
let updateLauncher = false;
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (let i = 0; i < args.length; i++) {
|
|
41
|
+
const flag = args[i];
|
|
42
|
+
if (seen.has(flag))
|
|
43
|
+
throw new Error('update_invalid_options');
|
|
44
|
+
seen.add(flag);
|
|
45
|
+
const value = args[++i];
|
|
46
|
+
if (flag === '--client' && (value === 'codex' || value === 'claude'))
|
|
47
|
+
updateClient = value;
|
|
48
|
+
else if (flag === '--launcher' && value === 'npx')
|
|
49
|
+
updateLauncher = true;
|
|
50
|
+
else
|
|
51
|
+
throw new Error('update_invalid_options');
|
|
52
|
+
}
|
|
53
|
+
if (!!updateClient !== updateLauncher)
|
|
38
54
|
throw new Error('update_invalid_options');
|
|
39
55
|
const packageRoot = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? '../' : '../../', import.meta.url));
|
|
40
|
-
const result =
|
|
41
|
-
|
|
56
|
+
const result = updateGlobalAndMigrate({ packageRoot, client: updateClient });
|
|
57
|
+
const setupRequired = result.status === 'complete' && result.codes.includes('setup_required');
|
|
58
|
+
output(setupRequired ? { ...result, next_steps: ['aptly setup', 'aptly set transmission --review'] } : result);
|
|
42
59
|
if (result.status === 'error')
|
|
43
60
|
process.exitCode = 1;
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
if (process.stderr.isTTY && !process.env.CI) {
|
|
62
|
+
if (setupRequired)
|
|
63
|
+
process.stderr.write('Run aptly setup to register a new host. Use aptly set transmission --review to review the transmission scope, then restart MCP.\n');
|
|
64
|
+
const configured = (result.migrations ?? (result.migration ? [result.migration] : [])).filter(host => host.status === 'configured');
|
|
65
|
+
if (configured.some(host => host.requires_hook_review))
|
|
66
|
+
process.stderr.write('Approve changed Codex Hooks in /hooks.\n');
|
|
67
|
+
if (configured.length)
|
|
68
|
+
process.stderr.write('Restart the migrated hosts to load the new launcher.\n');
|
|
69
|
+
}
|
|
46
70
|
}
|
|
47
71
|
else if (command === 'doctor') {
|
|
48
72
|
let clients = ['codex', 'claude'];
|
|
@@ -250,8 +274,8 @@ try {
|
|
|
250
274
|
const value = args[++i];
|
|
251
275
|
if (flag === '--client' && ['codex', 'claude', 'all'].includes(value))
|
|
252
276
|
clients = value === 'all' ? ['codex', 'claude'] : [value];
|
|
253
|
-
else if (flag === '--launcher' && command === 'setup' && value === 'stable')
|
|
254
|
-
launcher =
|
|
277
|
+
else if (flag === '--launcher' && command === 'setup' && (value === 'stable' || value === 'npx'))
|
|
278
|
+
launcher = value;
|
|
255
279
|
else if (flag === '--policy-source' && command === 'setup' && value === 'codex-home')
|
|
256
280
|
policySource = true;
|
|
257
281
|
else if (flag === '--transmission' && command === 'setup' && ['none', 'description', 'excerpt'].includes(value))
|
|
@@ -298,7 +298,7 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
298
298
|
const reason = summary.reason ?? 'insufficient_context';
|
|
299
299
|
if (reason !== 'insufficient_context' || !onNeedsContext)
|
|
300
300
|
return preserve(reason);
|
|
301
|
-
if (signal?.aborted || (stillCurrent && await stillCurrent() !== true))
|
|
301
|
+
if (signal?.aborted || (stillCurrent && (await stillCurrent() !== true || signal?.aborted)))
|
|
302
302
|
return preserve('call_cancelled');
|
|
303
303
|
const currentPolicy = loadAutomaticHookPolicy(policyPath), currentCall = readCall(client, event), currentContext = context?.();
|
|
304
304
|
if (!currentPolicy.policy?.enabled || currentPolicy.fingerprint !== loaded.fingerprint)
|
|
@@ -320,7 +320,7 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
320
320
|
const bound = bindCall(call, loaded.policy, loaded.fingerprint, catalogFingerprint(router.policy), supplied?.fingerprint);
|
|
321
321
|
return bound.request_id ? needsContext('insufficient_context', bound.request_id) : preserve(bound.reason ?? 'automatic_state_unavailable');
|
|
322
322
|
}
|
|
323
|
-
if (signal?.aborted || (stillCurrent && await stillCurrent() !== true))
|
|
323
|
+
if (signal?.aborted || (stillCurrent && (await stillCurrent() !== true || signal?.aborted)))
|
|
324
324
|
return preserve('call_cancelled');
|
|
325
325
|
// Installing an operator policy must not bypass a historical strict-path
|
|
326
326
|
// unknown/complete record for this same native call with a new paid ID.
|
|
@@ -360,7 +360,7 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
360
360
|
task: { summary: summary.summary, operation: 'analysis', context_sufficient: true },
|
|
361
361
|
eligible_profile_ids: classifyProfiles.map(profile => profile.id),
|
|
362
362
|
constraints: { model_pinned: false, effort_pinned: false, role_pinned: false, fork_inherits: false },
|
|
363
|
-
});
|
|
363
|
+
}, signal);
|
|
364
364
|
if (recommendation.reason === 'budget_exhausted' && ['max_daily_calls', 'max_total_calls', 'max_estimated_usd'].includes(recommendation.budget_limit ?? ''))
|
|
365
365
|
budgetLimit = recommendation.budget_limit;
|
|
366
366
|
observation.classification = recommendation.cached ? 'cache_hit' : typeof recommendation.latency_ms === 'number' ? 'provider_requested' : 'local_outcome';
|
|
@@ -370,7 +370,7 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
370
370
|
observation.profile_id = profile.id;
|
|
371
371
|
observation.application = 'blocked';
|
|
372
372
|
}
|
|
373
|
-
if (signal?.aborted || (stillCurrent && await stillCurrent() !== true))
|
|
373
|
+
if (signal?.aborted || (stillCurrent && (await stillCurrent() !== true || signal?.aborted)))
|
|
374
374
|
return preserve('call_cancelled', request_id);
|
|
375
375
|
const currentContext = context?.();
|
|
376
376
|
if (currentContext?.reason || currentContext?.fingerprint !== supplied?.fingerprint)
|
package/dist/src/cli-help.js
CHANGED
|
@@ -20,9 +20,9 @@ const entries = {
|
|
|
20
20
|
'stats disable': { usage: 'aptly stats disable [--client codex|claude|all]', description: 'Disable Aptly collection and remove unchanged product-owned observer definitions. Preserve statistics/key/history, custom or modified observers and all routing settings. Retained modified definitions are reported for local review.', options: { '--client': client } },
|
|
21
21
|
budget: { usage: 'aptly budget status [--client codex|claude|all]', description: 'Inspect local per-ledger budget limits and reserved usage. No reset/refill command is provided.' },
|
|
22
22
|
'budget status': { usage: 'aptly budget status [--client codex|claude|all]', description: 'Read registered host budget settings and ledger metadata; defaults to both clients. No credentials, provider calls, configuration writes or ledger/gate initialization.\nLiteral 0 ceilings display Unlimited; reservations are not OpenAI billing. This is a registration/permitted-environment snapshot, not verification of running custom launchers. An existing gate is held briefly and can be busy.', options: { '--client': client } },
|
|
23
|
-
setup: { usage: 'aptly setup [--client codex|claude|all] [--mode defaults|advisory] [--transmission none|description|excerpt] [--launcher stable] [--automatic]\n aptly setup --check [--client codex|claude|all]\n aptly setup --client codex|claude --migrate-launcher [--launcher stable] [--include-existing] [--dry-run]\n aptly setup --client codex --policy-source codex-home [--dry-run]', description: 'Register MCP and PreToolUse Hooks while preserving unrelated settings and existing launchers. --launcher stable explicitly selects a
|
|
23
|
+
setup: { usage: 'aptly setup [--client codex|claude|all] [--mode defaults|advisory] [--transmission none|description|excerpt] [--launcher stable|npx] [--automatic]\n aptly setup --check [--client codex|claude|all]\n aptly setup --client codex|claude --migrate-launcher [--launcher stable|npx] [--include-existing] [--dry-run]\n aptly setup --client codex --policy-source codex-home [--dry-run]', description: 'Register MCP and PreToolUse Hooks while preserving unrelated settings and existing launchers. --launcher stable or npx explicitly selects a private immutable runtime on macOS and Linux outside versioned Node installs; for existing direct registrations combine it with --migrate-launcher. The snapshot includes the package and production dependencies, not Node itself. A supported installed Node is still required. Existing managed registrations keep their selected launcher. Managed npx requires a trusted Node.js 24+ installation with npm and is unavailable with --automatic. Default/automatic installations keep direct Node registrations. Modified/custom launchers remain unchanged. Stable migration updates owned statistics observers in the same host transaction; direct-to-direct legacy migration retains its separate observer refresh contract and may report statistics_observer_migration_required; keys, history and collection/native-metadata choices remain unchanged. Old/shared snapshots are retained after remove. Windows managed mode is unsupported; the existing direct mode remains available. Omitted --mode preserves an existing mode; a new policy defaults to defaults. New transmission remains unselected unless explicitly chosen.\n--check snapshots the normal setup plan without writing; only --client may be combined with it. It does not verify a running host.\n--automatic skips CI, APTLY_SKIP_SETUP=1 and absent host directories.\n--migrate-launcher reviews a single owned standard launcher; --include-existing explicitly includes an eligible preserved registration. --dry-run validates migration without writing. Do not combine migration with --automatic, --mode or --transmission. --include-existing requires --migrate-launcher. --policy-source codex-home explicitly binds an existing owned Codex setup to the runtime CODEX_HOME using a reserved selector and forwarded CODEX_HOME; it preserves policy, ledger and statistics state. CLI commands and MCP startup select ~/.codex under the OS user home when CODEX_HOME is absent; an explicit absolute override takes precedence. Explicitly empty, relative or control-character-containing overrides are rejected. A custom host that omits CODEX_HOME uses the default home policy and transmission scope. Custom account homes are not discovered automatically; account managers must forward the intended CODEX_HOME. This default-home MCP fallback is available starting with 0.1.15; published 0.1.14 requires explicit forwarding even for the default home. Use it in the canonical registration and intended account homes when a manager mirrors MCP tables. --dry-run validates either migration without writing. Policy-source migration requires --client codex and cannot combine with other setup actions. Upgrade all MCP backends first; restart MCP afterward.\nOrdinary interactive setup reviews unreviewed transmission choices, including existing registrations; Enter keeps configured scopes or selects none for unselected clients. --automatic, --check and launcher migration never prompt. Explicit --transmission records that choice without asking. No keys are stored. Restart the host/MCP; Codex requires native /hooks trust review.', options: { '--client': client, '--launcher': ['stable', 'npx'], '--mode': ['defaults', 'advisory'], '--transmission': scope, '--automatic': true, '--check': true, '--migrate-launcher': true, '--policy-source': ['codex-home'], '--include-existing': true, '--dry-run': true } },
|
|
24
24
|
remove: { usage: 'aptly remove [--client codex|claude|all]', description: 'Remove only unchanged Aptly-owned registration for both clients by default. Preserve modified/user-owned entries, keys and ledger history. Restart host/MCP after removal.', options: { '--client': client } },
|
|
25
|
-
update: { usage: 'aptly update', description: 'Update this verified global npm installation within the same prefix. Stop other hosts/MCP/CLI writers first.
|
|
25
|
+
update: { usage: 'aptly update [--client codex|claude --launcher npx]', options: { '--client': ['codex', 'claude'], '--launcher': ['npx'] }, description: 'Update this verified global npm installation within the same prefix. Stop other hosts/MCP/CLI writers first. On macOS and Linux, the fresh CLI migrates existing Aptly-owned Codex and Claude Code registrations to managed npx. Absent or unowned registrations are skipped, and each host reports its migration result. The explicit --client and --launcher npx pair selects only one host. The package update is retained if a later migration fails. Windows updates the package only. Lifecycle scripts are disabled. Older releases first need an ordinary update to install the new CLI. Then run aptly update again to migrate existing hosts. Recheck changed Codex Hooks in /hooks and restart the host. Review transmission choices with aptly set transmission --review.' },
|
|
26
26
|
doctor: { usage: 'aptly doctor [--client codex|claude|all]', description: 'Read local registration, policy, package version and bounded ledger metadata as JSON. No launcher execution, credential-store query, provider/network call, state creation or update notification. Complete (exit 0) means the query completed, not host readiness; partial (exit 1) means an observation failed. Runtime version, Hook trust/execution, restart need and retry ticket usage remain unknown. Ledgers above 4 MiB are not scanned. A missing first-use ledger has unknown history. Scan time includes validation/rechecks; write timing is not measured. Existing report exports are separate and unchanged.', options: { '--client': client } },
|
|
27
27
|
report: { usage: 'aptly report [--format md|json|both] [--output-dir DIR]', description: 'Write redacted local diagnostic attachments. Default format: both; directory: reports. No uploads or classification API probes. Review attachments before sharing.', options: { '--format': ['md', 'json', 'both'], '--output-dir': 'path' } },
|
|
28
28
|
};
|
|
@@ -94,6 +94,8 @@ export function resolveCliHelp(argv, { environmentKeys = [] } = {}) {
|
|
|
94
94
|
return { kind: 'error', code: 'invalid_help_options' };
|
|
95
95
|
if (path === 'stats enable' && seen.has('--codex-native-metadata') && values.get('--client') === 'claude')
|
|
96
96
|
return { kind: 'error', code: 'invalid_help_options' };
|
|
97
|
+
if (path === 'update' && (seen.has('--client') !== seen.has('--launcher')))
|
|
98
|
+
return { kind: 'error', code: 'invalid_help_options' };
|
|
97
99
|
if (path === 'setup') {
|
|
98
100
|
const migrate = seen.has('--migrate-launcher'), policySource = seen.has('--policy-source');
|
|
99
101
|
if (seen.has('--check') && [...seen].some(flag => !['--check', '--client'].includes(flag)))
|
|
@@ -155,7 +155,7 @@ export class ContextRetries {
|
|
|
155
155
|
try {
|
|
156
156
|
const result = await this.router.advise({ request_id, client: entry.seed.client,
|
|
157
157
|
task: { summary, operation: 'analysis', context_sufficient: true }, eligible_profile_ids: entry.seed.eligible_profile_ids,
|
|
158
|
-
constraints: { model_pinned: false, effort_pinned: false, role_pinned: false, fork_inherits: false } });
|
|
158
|
+
constraints: { model_pinned: false, effort_pinned: false, role_pinned: false, fork_inherits: false } }, signal);
|
|
159
159
|
const after = check();
|
|
160
160
|
if (after)
|
|
161
161
|
return unavailable(after);
|
package/dist/src/core.d.ts
CHANGED
|
@@ -70,10 +70,10 @@ export declare class Router {
|
|
|
70
70
|
}): void;
|
|
71
71
|
save(): void;
|
|
72
72
|
/** Strict native-routing path: preserves existing host-evidence and digest semantics. */
|
|
73
|
-
recommend(input: unknown): Promise<RoutingResult>;
|
|
73
|
+
recommend(input: unknown, signal?: AbortSignal): Promise<RoutingResult>;
|
|
74
74
|
/** Independent task advice. Omitted constraints mean no caller-declared pins,
|
|
75
75
|
* not verified host settings. A legacy provenance flag grants no authority. */
|
|
76
|
-
advise(input: unknown): Promise<RoutingResult>;
|
|
76
|
+
advise(input: unknown, signal?: AbortSignal): Promise<RoutingResult>;
|
|
77
77
|
private route;
|
|
78
78
|
}
|
|
79
79
|
export {};
|
package/dist/src/core.js
CHANGED
|
@@ -242,12 +242,12 @@ export class Router {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
/** Strict native-routing path: preserves existing host-evidence and digest semantics. */
|
|
245
|
-
async recommend(input) {
|
|
246
|
-
return this.route(input, 'hook');
|
|
245
|
+
async recommend(input, signal) {
|
|
246
|
+
return this.route(input, 'hook', signal);
|
|
247
247
|
}
|
|
248
248
|
/** Independent task advice. Omitted constraints mean no caller-declared pins,
|
|
249
249
|
* not verified host settings. A legacy provenance flag grants no authority. */
|
|
250
|
-
async advise(input) {
|
|
250
|
+
async advise(input, signal) {
|
|
251
251
|
const invalid = () => this.result('unavailable', 'invalid_input');
|
|
252
252
|
if (!keysOnly(input, ['request_id', 'client', 'task', 'eligible_profile_ids', 'constraints']) || !isClient(input.client))
|
|
253
253
|
return invalid();
|
|
@@ -258,9 +258,12 @@ export class Router {
|
|
|
258
258
|
return this.route({ ...input,
|
|
259
259
|
eligible_profile_ids: own(input, 'eligible_profile_ids') ? input.eligible_profile_ids : this.policy.profiles.filter(profile => profile.client === input.client).map(profile => profile.id),
|
|
260
260
|
constraints: declared,
|
|
261
|
-
}, 'advisory');
|
|
261
|
+
}, 'advisory', signal);
|
|
262
262
|
}
|
|
263
|
-
async route(input, kind) {
|
|
263
|
+
async route(input, kind, signal) {
|
|
264
|
+
const cancelled = () => this.result('unavailable', 'call_cancelled');
|
|
265
|
+
if (signal?.aborted)
|
|
266
|
+
return cancelled();
|
|
264
267
|
const invalid = () => this.result('unavailable', 'invalid_input');
|
|
265
268
|
if (!keysOnly(input, ['request_id', 'client', 'task', 'eligible_profile_ids', 'constraints']) ||
|
|
266
269
|
typeof input.request_id !== 'string' || !/^[A-Za-z0-9_-]{1,96}$/.test(input.request_id) || !isClient(input.client) ||
|
|
@@ -316,6 +319,8 @@ export class Router {
|
|
|
316
319
|
// Only this known completion can proceed again under the same ID.
|
|
317
320
|
}
|
|
318
321
|
const complete = (result) => {
|
|
322
|
+
if (signal?.aborted)
|
|
323
|
+
return this.result('unavailable', 'call_cancelled', { latency_ms: result.latency_ms });
|
|
319
324
|
this.state.requests[req.request_id] = { digest: hash, state: 'complete', result };
|
|
320
325
|
this.save();
|
|
321
326
|
return clone(result);
|
|
@@ -331,8 +336,12 @@ export class Router {
|
|
|
331
336
|
this.provider.preflight?.();
|
|
332
337
|
}
|
|
333
338
|
catch (e) {
|
|
339
|
+
if (signal?.aborted)
|
|
340
|
+
return cancelled();
|
|
334
341
|
return this.result('unavailable', errorCode(e) === 'unauthorized' ? 'unauthorized' : 'provider_error');
|
|
335
342
|
}
|
|
343
|
+
if (signal?.aborted)
|
|
344
|
+
return cancelled();
|
|
336
345
|
const day = new Date().toISOString().slice(0, 10);
|
|
337
346
|
const exhausted = this.budgetSnapshot(day).exhausted_by;
|
|
338
347
|
if (exhausted.length)
|
|
@@ -343,14 +352,32 @@ export class Router {
|
|
|
343
352
|
this.state.requests[req.request_id] = { digest: hash, state: 'unknown' };
|
|
344
353
|
this.save();
|
|
345
354
|
const controller = new AbortController();
|
|
346
|
-
|
|
355
|
+
const { promise: interrupted, reject } = Promise.withResolvers();
|
|
356
|
+
let stopped;
|
|
357
|
+
const stop = (code) => {
|
|
358
|
+
if (stopped)
|
|
359
|
+
return;
|
|
360
|
+
stopped = code;
|
|
361
|
+
const error = Object.assign(new Error(code), { code });
|
|
362
|
+
reject(error);
|
|
363
|
+
controller.abort(error);
|
|
364
|
+
};
|
|
365
|
+
const onAbort = () => stop('call_cancelled');
|
|
366
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
367
|
+
if (signal?.aborted)
|
|
368
|
+
onAbort();
|
|
369
|
+
const timer = setTimeout(() => stop('timeout'), this.policy.timeout_ms);
|
|
347
370
|
const started = performance.now();
|
|
348
371
|
const latency = () => Math.round((performance.now() - started) * 1000) / 1000;
|
|
349
372
|
try {
|
|
350
373
|
const response = await Promise.race([
|
|
351
|
-
|
|
352
|
-
|
|
374
|
+
interrupted,
|
|
375
|
+
Promise.resolve().then(() => {
|
|
376
|
+
controller.signal.throwIfAborted();
|
|
377
|
+
return this.provider({ input: clone(req), profiles: clone(profiles), signal: controller.signal });
|
|
378
|
+
}),
|
|
353
379
|
]);
|
|
380
|
+
controller.signal.throwIfAborted();
|
|
354
381
|
if (!isRecord(response) || typeof response.choice !== 'string' || (own(response, 'confidence') && (typeof response.confidence !== 'number' || !Number.isFinite(response.confidence) || response.confidence < 0 || response.confidence > 1)))
|
|
355
382
|
return complete(this.result('keep_current', 'invalid_response', { latency_ms: latency() }));
|
|
356
383
|
const metadata = { latency_ms: latency() };
|
|
@@ -374,13 +401,16 @@ export class Router {
|
|
|
374
401
|
return complete(this.result('recommended', 'allowed_profile', { profile_id: profile.id, profile: clone(profile), ...metadata }));
|
|
375
402
|
}
|
|
376
403
|
catch (e) {
|
|
377
|
-
//
|
|
404
|
+
// The slot and gate protect local work. A remote request may outlive cancellation.
|
|
405
|
+
if (stopped)
|
|
406
|
+
return this.result('unavailable', stopped, { latency_ms: latency() });
|
|
378
407
|
const allowed = ['timeout', 'refused', 'truncated', 'invalid_json', 'unauthorized', 'rate_limited', 'network', 'ledger_error'];
|
|
379
408
|
const code = errorCode(e);
|
|
380
409
|
return this.result('unavailable', code !== undefined && allowed.includes(code) ? code : 'provider_error', { latency_ms: latency() });
|
|
381
410
|
}
|
|
382
411
|
finally {
|
|
383
412
|
clearTimeout(timer);
|
|
413
|
+
signal?.removeEventListener('abort', onAbort);
|
|
384
414
|
}
|
|
385
415
|
}
|
|
386
416
|
catch {
|
package/dist/src/doctor.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare function collectDoctor(options?: DoctorOptions): {
|
|
|
56
56
|
stable_snapshot_outdated?: boolean | undefined;
|
|
57
57
|
recovery?: string[] | undefined;
|
|
58
58
|
registration: string;
|
|
59
|
+
runtime_launcher?: import("./stable-runtime.ts").ManagedLauncher | undefined;
|
|
59
60
|
registered_package: {
|
|
60
61
|
status: string;
|
|
61
62
|
version: string | null;
|
package/dist/src/doctor.js
CHANGED
|
@@ -164,7 +164,7 @@ export function collectDoctor(options = {}) {
|
|
|
164
164
|
ledger = { status: 'not_declared', counts: null, write_timing: 'not_measured' };
|
|
165
165
|
}
|
|
166
166
|
snapshot.verify();
|
|
167
|
-
return { ...base, status: 'complete', ...(stable && stable.version !== VERSION ? { stable_snapshot_outdated: true, recovery: [`aptly setup --client ${client} --migrate-launcher
|
|
167
|
+
return { ...base, status: 'complete', ...(stable && stable.version !== VERSION ? { stable_snapshot_outdated: true, recovery: [`aptly setup --client ${client} --migrate-launcher --launcher ${stable.launcher} --dry-run`] } : {}), registration: stable ? 'stable_runtime_registration' : standard ? 'standard_node_registration' : 'custom_or_remote_launcher', ...(stable ? { runtime_launcher: stable.launcher } : {}), registered_package: target, policy: { source_kind: source, status: policyStatus, transmission }, hook_registration: hook, credential_reference: settings.APTLY_SECRET_BACKEND === 'os' ? 'os_reference' : Object.hasOwn(settings, 'OPENAI_API_KEY') ? 'inline_environment_present' : permitted('OPENAI_API_KEY') ? 'runtime_environment_permitted' : 'not_declared', ledger: { ...ledger, diagnostic_scan_ms: Math.max(0, performance.now() - started), timing_scope: 'full_client_observation_and_rechecks' } };
|
|
168
168
|
}
|
|
169
169
|
catch (error) {
|
|
170
170
|
// A changed observation takes precedence over a parse/validation failure.
|
package/dist/src/provider.js
CHANGED
|
@@ -38,19 +38,25 @@ export function decisionsProvider({ key, fetchImpl = fetch, descriptions = {} }
|
|
|
38
38
|
throw fail(response.status === 401 || response.status === 403 ? 'unauthorized' : response.status === 429 ? 'rate_limited' : 'provider_error');
|
|
39
39
|
}
|
|
40
40
|
// Bounded response, never expose raw provider text or headers in diagnostics.
|
|
41
|
-
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let bytes = 0;
|
|
42
43
|
try {
|
|
43
44
|
if (!response.body)
|
|
44
45
|
throw fail('network');
|
|
45
46
|
for await (const chunk of response.body) {
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (!(chunk instanceof Uint8Array))
|
|
48
|
+
throw fail('network');
|
|
49
|
+
bytes += chunk.byteLength;
|
|
50
|
+
if (bytes > 65_536)
|
|
48
51
|
throw fail('truncated');
|
|
52
|
+
if (chunk.byteLength)
|
|
53
|
+
chunks.push(chunk);
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
catch (e) {
|
|
52
57
|
throw fail(errorCode(e) === 'truncated' ? 'truncated' : signal?.aborted ? 'timeout' : 'network');
|
|
53
58
|
}
|
|
59
|
+
const body = Buffer.concat(chunks, bytes).toString('utf8');
|
|
54
60
|
let data;
|
|
55
61
|
try {
|
|
56
62
|
data = JSON.parse(body);
|
package/dist/src/server.js
CHANGED
|
@@ -105,7 +105,12 @@ export function createServer({ env: inputEnv = process.env } = {}) {
|
|
|
105
105
|
server.registerTool('recommend_agent', {
|
|
106
106
|
description: 'Recommend an allowlisted profile for a supplied task only; never inspects host settings, spawns, or authorizes an agent. Optional constraints describe caller-declared choices to preserve; omitted flags are not claims about current host settings. Decisions mode may incur a bounded classification request.', annotations,
|
|
107
107
|
inputSchema: { request_id: z.string().min(1).max(96), client: z.enum(['codex', 'claude']), task: taskSchema, eligible_profile_ids: z.array(z.string()).min(1).max(20).optional(), constraints: constraintsSchema.optional() }
|
|
108
|
-
}, async (input
|
|
108
|
+
}, async (input, extra) => {
|
|
109
|
+
const result = await router.advise(input, extra.signal);
|
|
110
|
+
if (!extra.signal.aborted)
|
|
111
|
+
await trackStatistics(input.client, { requestId: input.request_id, recommendation: result });
|
|
112
|
+
return content({ ...result, provider: mode });
|
|
113
|
+
});
|
|
109
114
|
server.registerTool('retry_spawn_recommendation', {
|
|
110
115
|
description: 'Supply one bounded task description after an Aptly Hook returns needs_context and a retry_id. Use the same MCP process within five minutes; no native call IDs are needed. May make one paid classification; duplicate input reuses its request identity, changed input conflicts. Never spawns or changes history. If still needs_context/unavailable, stop; do not create another ID. A blocked spawn_application remains advisory. When next_call is supplied, required_fields and next_action describe only missing profile arguments. Apply them only under existing user/host permissions; if forbidden or unclear, stop and report. Existing-agent reuse is an alternative, not proof of applying this recommendation.',
|
|
111
116
|
annotations, inputSchema: { retry_id: z.string().regex(/^[a-f0-9]{64}$/), description: z.string().max(4000) }
|
|
@@ -163,7 +168,16 @@ export function createServer({ env: inputEnv = process.env } = {}) {
|
|
|
163
168
|
input.constraints = before.precedence.constraints;
|
|
164
169
|
if (task)
|
|
165
170
|
input.task = task;
|
|
166
|
-
const recommendation = await router.recommend(input);
|
|
171
|
+
const recommendation = await router.recommend(input, extra.signal);
|
|
172
|
+
if (extra.signal.aborted) {
|
|
173
|
+
// Keep any already committed recommendation distinct from native application.
|
|
174
|
+
const produced = recommendation.status === 'recommended';
|
|
175
|
+
observations.record({ ...initialHookObservation(client, event), status: 'preserved', reason: 'call_cancelled', request_id: input.request_id,
|
|
176
|
+
classification: recommendation.cached ? 'cache_hit' : typeof recommendation.latency_ms === 'number' ? 'provider_requested' : 'local_outcome',
|
|
177
|
+
recommendation: produced ? 'produced' : 'not_produced', application: produced ? 'blocked' : 'not_attempted',
|
|
178
|
+
...(recommendation.profile_id ? { profile_id: recommendation.profile_id } : {}) });
|
|
179
|
+
return { content: [{ type: 'text', text: '{}' }] };
|
|
180
|
+
}
|
|
167
181
|
// Revalidate binding, expiry, source fingerprints and operator configuration
|
|
168
182
|
// after an asynchronous provider call. A changed source cannot enable apply.
|
|
169
183
|
const after = evidence(client, event);
|
package/dist/src/setup.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type ManagedLauncher } from './stable-runtime.ts';
|
|
1
2
|
type Client = 'codex' | 'claude';
|
|
2
3
|
export interface SetupOptions {
|
|
3
4
|
home?: string;
|
|
4
5
|
env?: NodeJS.ProcessEnv;
|
|
5
6
|
packageRoot?: string;
|
|
6
|
-
launcher?:
|
|
7
|
+
launcher?: ManagedLauncher;
|
|
7
8
|
automatic?: boolean;
|
|
8
9
|
clients?: Client[];
|
|
9
10
|
mode?: 'defaults' | 'advisory';
|