aiterm-mcp 0.47.1 → 0.48.0
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/CHANGELOG.md +13 -1
- package/README.ja.md +12 -1
- package/README.md +13 -1
- package/dist/index.js +3 -0
- package/dist/runtime-error-os.js +44 -0
- package/dist/runtime-error-report.js +260 -0
- package/dist/runtime-error-store.js +11 -1
- package/dist/runtime-error-worker.js +10 -8
- package/dist/runtime-errors-cli.js +42 -7
- package/docs/DESIGN.md +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.48.0] - 2026-10-03
|
|
11
|
+
|
|
12
|
+
### 追加
|
|
13
|
+
|
|
14
|
+
- 実行時エラーをBugHubへ報告する仕組み。既定では無効で、何も送らない。`aiterm-runtime-errors reporting enable`で明示して有効にし、かつBugHubの持ち主が置いた合鍵のファイルがある端末だけが送る。宛先は合鍵のファイルから読む。送るのは別processで、きっかけはエラーの記録・解決や開き直し・MCPの起動(未報告がある時だけ、多くても1時間に1回)と`aiterm-runtime-errors report`。応答の署名まで確かめた時だけ受け取り済みにする。`aiterm-runtime-errors reporting status`で状態を見られる。
|
|
15
|
+
- 報告を有効にした端末は、工場の収集設定が無くても実行時エラーの記録が有効になる。
|
|
16
|
+
|
|
17
|
+
### 修正
|
|
18
|
+
|
|
19
|
+
- 試験が、わざと起こした失敗を利用者の実行時エラーの記録へ書いていた(CIを走らせる端末で、試験のたびに1件増えていた)。試験の記録先を一時フォルダへ向けた。製品の動きは変わらない。
|
|
20
|
+
|
|
10
21
|
## [0.47.1] - 2026-10-03
|
|
11
22
|
|
|
12
23
|
### 修正
|
|
@@ -1983,7 +1994,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
1983
1994
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
1984
1995
|
provenance.
|
|
1985
1996
|
|
|
1986
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.
|
|
1997
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.48.0...HEAD
|
|
1998
|
+
[0.48.0]: https://github.com/kitepon/aiterm-mcp/compare/v0.47.1...v0.48.0
|
|
1987
1999
|
[0.47.1]: https://github.com/kitepon/aiterm-mcp/compare/v0.47.0...v0.47.1
|
|
1988
2000
|
[0.47.0]: https://github.com/kitepon/aiterm-mcp/compare/v0.46.1...v0.47.0
|
|
1989
2001
|
[0.46.1]: https://github.com/kitepon/aiterm-mcp/compare/v0.46.0...v0.46.1
|
package/README.ja.md
CHANGED
|
@@ -209,7 +209,7 @@ runtime-error store は canonical dotagents config の `collection.enabled: true
|
|
|
209
209
|
場合だけ収集し、既定OFF、network送信は行いません。tag起点CIのnpm provenance(OIDC Trusted
|
|
210
210
|
Publishing)で公開し、GitHub Release が Official MCP Registry を再登録します。
|
|
211
211
|
|
|
212
|
-
**状態:** 開発継続中 · 現行公開版 **v0.
|
|
212
|
+
**状態:** 開発継続中 · 現行公開版 **v0.48.0** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
213
213
|
|
|
214
214
|
### 更新と巻き戻し
|
|
215
215
|
|
|
@@ -554,6 +554,17 @@ Claudeの相関済み承認は既存の`claude_approval`を使う。
|
|
|
554
554
|
|
|
555
555
|
consumer は `aiterm-runtime-errors snapshot` を読み、durable ingestion 後に `aiterm-runtime-errors ack --cursor N` を呼ぶ。運用上の明示操作は `resolve|reopen --fingerprint SHA256`。MCP からの収集・diagnostic read は timeout 付き child process に隔離し、FIFOや停止 filesystem が端末本体を止めない。store mutation は期限付き bakery ticket queue で直列化する。各waiterは PID+process start identity+owner token を持つ再利用されない固有ticketを所有するため、死んだownerだけを固有名で除去でき、固定path回収のABAを作らない。queueの期限は正常な前任者を含む総待ち時間ではなく、同じ先頭ownerが進まない時間を測る。通常pollはprocessの生存確認だけを行い、process start identityはblockerがstallした時に照合する。POSIX state は `$XDG_STATE_HOME/aiterm-mcp/`(既定 `~/.local/state/aiterm-mcp/`)へ atomic replacement で置き、every read で owner/mode を再検証する。Windows native は `%LOCALAPPDATA%\aiterm-mcp\` で current SID の非継承 FullControl ACE 1件だけへ DACL を再構築し readback する。今回 Windows は path/DACL/timeout の純粋テストだけであり、新しい実機統合成功は主張しない。
|
|
556
556
|
|
|
557
|
+
### BugHubへの報告(既定では無効)
|
|
558
|
+
|
|
559
|
+
Aitermは、既定では実行時エラーをどこへも送らない。送るのは、次の2つがそろった端末だけ。
|
|
560
|
+
|
|
561
|
+
1. `aiterm-runtime-errors reporting enable` で明示して有効にした。
|
|
562
|
+
2. BugHubの持ち主が置いた合鍵のファイルがある(POSIXは `~/.config/bughub/product-credentials/aiterm-mcp.json`、Windowsは `%LOCALAPPDATA%\bughub\product-credentials\aiterm-mcp.json`)。本人だけが読める通常のファイルでなければ読まない。
|
|
563
|
+
|
|
564
|
+
宛先は合鍵のファイルから読む。送る中身は、エラーのコード・回数・最初と最後の時刻・版・重さ・解決の印だけで、prompt・path・stackは保存も送信もしない。送るのは別processで、MCP processは通信しない。きっかけは、エラーを記録した時・解決や開き直しをした時・MCPの起動時(未報告がある時だけ、多くても1時間に1回)と、`aiterm-runtime-errors report`(その場で1回、1分に1回まで)。応答の署名まで確かめた時だけ受け取り済みにし、確かめられない時は次の機会に送り直す。
|
|
565
|
+
|
|
566
|
+
`aiterm-runtime-errors reporting status` は、有効・無効、合鍵の状態(`ready`/`missing`/`rejected`)、未報告の件数、最後の送信の結果を返す。止める時は `aiterm-runtime-errors reporting disable`。報告を有効にした端末は、工場の収集設定が無くても記録が有効になる。
|
|
567
|
+
|
|
557
568
|
### 対話エージェントharness
|
|
558
569
|
|
|
559
570
|
`agent_launch`は選んだharnessの対話TUIを新しい永続PTYに起動し、`session_id`を返す。harnessはagent loop・認証・hook・session・transcriptを所有し、modelは独立。以後は他sessionと同じ`pty_read`/`pty_send`で操作する。
|
package/README.md
CHANGED
|
@@ -223,7 +223,7 @@ collection is off by default and performs no network I/O. It ships via
|
|
|
223
223
|
tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
|
|
224
224
|
Release re-registers the Official MCP Registry entry.
|
|
225
225
|
|
|
226
|
-
**Status:** actively maintained · current public release **v0.
|
|
226
|
+
**Status:** actively maintained · current public release **v0.48.0** · runs on Linux · WSL2 · macOS · native Windows (tmux on POSIX, the tmux-CLI-compatible [psmux](https://github.com/psmux/psmux) on native Windows — no WSL required) · MIT · see the [CHANGELOG](CHANGELOG.md).
|
|
227
227
|
|
|
228
228
|
### Update and rollback
|
|
229
229
|
|
|
@@ -589,6 +589,18 @@ snapshotの`product_version`は各recordの最終実発生時の版を表す。s
|
|
|
589
589
|
|
|
590
590
|
Consumer flow is `aiterm-runtime-errors snapshot`, then `aiterm-runtime-errors ack --cursor N` after durable ingestion. Operators can use `resolve|reopen --fingerprint SHA256`. MCP collection and diagnostic reads run in timeout-bounded child processes, so a FIFO or stalled filesystem cannot block terminal work; child failure emits only the fixed store diagnostic. Store mutation uses a bounded bakery ticket queue: every waiter owns a never-reused ticket containing PID, process-start identity, and an owner token, so dead owners are removed by unique filename without fixed-path reclaim ABA. The queue deadline measures lack of progress by the same head owner, not total wait behind healthy predecessors; normal polling uses the native process-liveness check and validates process-start identity only when a blocker stalls. Worker deadlines use forced termination so a SIGTERM-ignoring child cannot mutate state after timeout. POSIX state is atomically replaced under `$XDG_STATE_HOME/aiterm-mcp/` (default `~/.local/state/aiterm-mcp/`) with owner/mode rechecked on every read. Windows native uses `%LOCALAPPDATA%\aiterm-mcp\`; each DACL is rebuilt and read back as one non-inherited FullControl ACE for the current SID. Windows path/DACL/timeout behavior is covered by pure tests in this change; no new Windows integration success is claimed.
|
|
591
591
|
|
|
592
|
+
**Reporting to BugHub is off by default.** Aiterm sends runtime errors nowhere unless both hold: the user ran
|
|
593
|
+
`aiterm-runtime-errors reporting enable`, and a credential file placed by the BugHub owner exists
|
|
594
|
+
(`~/.config/bughub/product-credentials/aiterm-mcp.json`, or `%LOCALAPPDATA%\bughub\product-credentials\aiterm-mcp.json` on Windows;
|
|
595
|
+
it is read only when it is a regular file readable by its owner alone). The destination comes from that file. The payload is the
|
|
596
|
+
cumulative error codes, counts, first/last timestamps, versions, severity, and resolution marks; prompts, paths, and stacks are neither
|
|
597
|
+
stored nor sent. A separate process does the sending, never the MCP process, and there is no polling: a report is attempted when an error
|
|
598
|
+
is recorded, when a record is resolved or reopened, and when the MCP server starts (only while something is unreported, at most once per
|
|
599
|
+
hour), or on `aiterm-runtime-errors report` (once, at most once per minute). A record becomes acknowledged only after the response
|
|
600
|
+
signature is verified; otherwise the next attempt resends the then-current totals. `aiterm-runtime-errors reporting status` shows the
|
|
601
|
+
switch, the credential state, the unreported count, and the last attempt; `reporting disable` turns it off. Enabling reporting also
|
|
602
|
+
enables collection on that host.
|
|
603
|
+
|
|
592
604
|
### Interactive agent harnesses
|
|
593
605
|
|
|
594
606
|
`agent_launch` starts a selected harness's interactive coding-agent TUI inside a fresh persistent PTY and returns its `session_id`. The harness owns the agent loop, authentication, hooks, session, and transcript; `model` is independent. The TUI is a full-screen app, so read it with `pty_read({ screen: true })` for the rendered view.
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { z } from "zod";
|
|
|
15
15
|
import { agentModelsResult } from "./model-catalog.js";
|
|
16
16
|
import * as core from "./core.js";
|
|
17
17
|
import { runtimeErrorStoreDiagnostic } from "./runtime-error-store.js";
|
|
18
|
+
import { triggerRuntimeErrorReport } from "./runtime-error-report.js";
|
|
18
19
|
import { createRequire } from "node:module";
|
|
19
20
|
import { ParentDeliveryManager, deliveryKey } from "./parent-delivery.js";
|
|
20
21
|
import { acceptRemote, callRemoteTool, observeRemoteAgentDone, remoteInputDescription, remoteInputSchema, remoteLabel, remoteWaitProcess } from "./remote.js";
|
|
@@ -1120,6 +1121,8 @@ async function main() {
|
|
|
1120
1121
|
};
|
|
1121
1122
|
const transport = new StdioServerTransport();
|
|
1122
1123
|
await server.connect(transport);
|
|
1124
|
+
// 受け口がまだ受け取っていない実行時エラーがあれば、別processで送る(明示して有効にした端末だけ。既定では何も起動しない)。
|
|
1125
|
+
triggerRuntimeErrorReport();
|
|
1123
1126
|
}
|
|
1124
1127
|
main().catch((e) => {
|
|
1125
1128
|
console.error("aiterm-mcp fatal:", e);
|
package/dist/runtime-error-os.js
CHANGED
|
@@ -23,6 +23,50 @@ export function defaultRuntimeErrorPaths(options = {}) {
|
|
|
23
23
|
storePath: path.join(stateHome, "aiterm-mcp", "runtime-errors.json"),
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
// BugHubへの報告で使う場所。有効スイッチはAiterm自身の設定、合鍵はBugHubの持ち主が端末へ置くファイル。
|
|
27
|
+
export function defaultRuntimeErrorReportPaths(options = {}) {
|
|
28
|
+
const platform = options.platform ?? process.platform;
|
|
29
|
+
const home = options.home ?? os.homedir();
|
|
30
|
+
if (platform === "win32") {
|
|
31
|
+
const base = options.localAppData ?? process.env.LOCALAPPDATA ?? path.win32.join(home, "AppData", "Local");
|
|
32
|
+
return {
|
|
33
|
+
reportingConfigPath: path.win32.join(base, "aiterm-mcp", "runtime-error-reporting.json"),
|
|
34
|
+
credentialPath: path.win32.join(base, "bughub", "product-credentials", "aiterm-mcp.json"),
|
|
35
|
+
reportStatePath: path.win32.join(base, "aiterm-mcp", "runtime-errors-report.json"),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const configHome = options.xdgConfigHome ?? process.env.XDG_CONFIG_HOME ?? path.join(home, ".config");
|
|
39
|
+
const stateHome = options.xdgStateHome ?? process.env.XDG_STATE_HOME ?? path.join(home, ".local", "state");
|
|
40
|
+
return {
|
|
41
|
+
reportingConfigPath: path.join(configHome, "aiterm-mcp", "runtime-error-reporting.json"),
|
|
42
|
+
credentialPath: path.join(configHome, "bughub", "product-credentials", "aiterm-mcp.json"),
|
|
43
|
+
reportStatePath: path.join(stateHome, "aiterm-mcp", "runtime-errors-report.json"),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const MAX_REPORTING_CONFIG_BYTES = 4 * 1024;
|
|
47
|
+
/** 報告の有効スイッチの状態。ファイルが無ければ無効(既定)。形が違うファイルは有効とみなさない。 */
|
|
48
|
+
export function runtimeErrorReportingStatus(file, platform = process.platform) {
|
|
49
|
+
let text;
|
|
50
|
+
try {
|
|
51
|
+
text = readBoundedFile(file, MAX_REPORTING_CONFIG_BYTES, platform, false);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return error.code === "ENOENT" ? "disabled" : "malformed";
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const config = JSON.parse(text);
|
|
58
|
+
if (typeof config !== "object" || config === null || Array.isArray(config))
|
|
59
|
+
return "malformed";
|
|
60
|
+
const keys = Object.keys(config);
|
|
61
|
+
const value = config;
|
|
62
|
+
if (keys.length !== 2 || value.schema_version !== "1.0" || typeof value.enabled !== "boolean")
|
|
63
|
+
return "malformed";
|
|
64
|
+
return value.enabled ? "enabled" : "disabled";
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return "malformed";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
26
70
|
const WINDOWS_DACL_VERIFY_SCRIPT = String.raw `
|
|
27
71
|
$ErrorActionPreference='Stop'
|
|
28
72
|
$target=$env:AITERMMCP_ACL_PATH; $kind=$env:AITERMMCP_ACL_KIND
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// BugHubへの実行時エラーの報告。明示して有効にした端末だけが、合鍵のファイルにある宛先へ累計を送る。
|
|
2
|
+
// 既定では通信しない。送るのは常に別processで、MCP processは通信しない。判断はADR 0079。
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { defaultRuntimeErrorReportPaths, readBoundedFile, runtimeErrorReportingStatus } from "./runtime-error-os.js";
|
|
10
|
+
import { RuntimeErrorStore } from "./runtime-error-store.js";
|
|
11
|
+
const pkg = createRequire(import.meta.url)("../package.json");
|
|
12
|
+
const WORKER = fileURLToPath(new URL("./runtime-error-worker.js", import.meta.url));
|
|
13
|
+
const REPORT_SCHEMA = "1.0";
|
|
14
|
+
const REPORT_STATE_SCHEMA = "1.0";
|
|
15
|
+
const MAX_REPORT_RECORDS = 500;
|
|
16
|
+
const MAX_REPORT_BYTES = 512 * 1024;
|
|
17
|
+
const MAX_CREDENTIAL_BYTES = 8 * 1024;
|
|
18
|
+
const MAX_RESPONSE_BYTES = 64 * 1024;
|
|
19
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
20
|
+
// 受け口の上限は端末×製品ごとに1分に1回。自動の送信は、未受領がある時だけ、多くても1時間に1回。
|
|
21
|
+
const MANUAL_MIN_INTERVAL_MS = 60_000;
|
|
22
|
+
const AUTO_MIN_INTERVAL_MS = 60 * 60_000;
|
|
23
|
+
const LOCK_STALE_MS = 2 * 60_000;
|
|
24
|
+
/** 契約にある項目だけを載せる。端末名・OS・arch・保存用の連番は送らない(端末は合鍵から決まる)。 */
|
|
25
|
+
export function buildRuntimeErrorReport(records, options) {
|
|
26
|
+
if (records.length > MAX_REPORT_RECORDS)
|
|
27
|
+
throw new Error(`1回のreportは${MAX_REPORT_RECORDS}件までです`);
|
|
28
|
+
return {
|
|
29
|
+
schema_version: REPORT_SCHEMA,
|
|
30
|
+
report_id: options.reportId,
|
|
31
|
+
product_id: "aiterm-mcp",
|
|
32
|
+
installed_version: options.installedVersion,
|
|
33
|
+
observed_at: options.observedAt,
|
|
34
|
+
runtime_errors: records.map((record) => ({
|
|
35
|
+
fingerprint: record.fingerprint, error_code: record.error_code, component: record.component,
|
|
36
|
+
message_template: record.message_template, severity: record.severity, status: record.status,
|
|
37
|
+
occurrence_count: record.occurrence_count, first_seen: record.first_seen, last_seen: record.last_seen,
|
|
38
|
+
product_version: record.product_version, state_schema_version: record.state_schema_version,
|
|
39
|
+
})),
|
|
40
|
+
resolutions: records.filter((record) => record.status === "resolved" && record.resolved_at !== null && record.reason_code !== null)
|
|
41
|
+
.map((record) => ({ fingerprint: record.fingerprint, resolved_at: record.resolved_at, reason_code: record.reason_code })),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function reportBodyDigest(body) {
|
|
45
|
+
return createHash("sha256").update(body).digest("hex");
|
|
46
|
+
}
|
|
47
|
+
/** sig = HMAC-SHA256(secret, ts + "\n" + 送ったバイト列のSHA-256の16進)。secretは文字列をそのままUTF-8で鍵にする。 */
|
|
48
|
+
export function signReport(secret, ts, body) {
|
|
49
|
+
return createHmac("sha256", Buffer.from(secret, "utf8")).update(`${ts}\n${reportBodyDigest(body)}`).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
export function reportAuthorization(keyId, ts, sig) {
|
|
52
|
+
return `BugHub-HMAC-SHA256 key_id=${keyId}, ts=${ts}, sig=${sig}`;
|
|
53
|
+
}
|
|
54
|
+
/** 受領とみなすのは、accepted・report_idの一致・応答の署名がそろった時だけ。別の機器が返した200を受領にしない。 */
|
|
55
|
+
export function verifyReportResponse(secret, reportId, response) {
|
|
56
|
+
if (typeof response !== "object" || response === null || Array.isArray(response))
|
|
57
|
+
return false;
|
|
58
|
+
const value = response;
|
|
59
|
+
if (value.accepted !== true || value.report_id !== reportId)
|
|
60
|
+
return false;
|
|
61
|
+
if (typeof value.received_at !== "string" || typeof value.sig !== "string" || !/^[0-9a-f]{64}$/.test(value.sig))
|
|
62
|
+
return false;
|
|
63
|
+
const expected = createHmac("sha256", Buffer.from(secret, "utf8")).update(`${reportId}\n${value.received_at}`).digest();
|
|
64
|
+
return timingSafeEqual(expected, Buffer.from(value.sig, "hex"));
|
|
65
|
+
}
|
|
66
|
+
/** 合鍵のファイルは、本人だけが読める通常のファイルだけを読む。無い端末は「無い」と返し、失敗にしない。 */
|
|
67
|
+
export function readProductCredential(file, platform = process.platform) {
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = readBoundedFile(file, MAX_CREDENTIAL_BYTES, platform, true);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return error.code === "ENOENT" ? { status: "missing" } : { status: "rejected", reason: "unsafe_file" };
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const value = JSON.parse(text);
|
|
77
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
78
|
+
return { status: "rejected", reason: "malformed" };
|
|
79
|
+
const credential = value;
|
|
80
|
+
if (Object.keys(credential).sort().join(",") !== "key_id,secret,url")
|
|
81
|
+
return { status: "rejected", reason: "malformed" };
|
|
82
|
+
if (typeof credential.url !== "string" || typeof credential.key_id !== "string" || typeof credential.secret !== "string"
|
|
83
|
+
|| !/^[A-Za-z0-9._-]{1,128}$/.test(credential.key_id) || credential.secret.length < 1 || credential.secret.length > 1024) {
|
|
84
|
+
return { status: "rejected", reason: "malformed" };
|
|
85
|
+
}
|
|
86
|
+
const url = new URL(credential.url);
|
|
87
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
88
|
+
return { status: "rejected", reason: "malformed" };
|
|
89
|
+
return { status: "ready", credential: { url: credential.url, key_id: credential.key_id, secret: credential.secret } };
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return { status: "rejected", reason: "malformed" };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function setRuntimeErrorReporting(file, enabled) {
|
|
96
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
97
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
98
|
+
fs.writeFileSync(temp, `${JSON.stringify({ schema_version: "1.0", enabled })}\n`, { mode: 0o600 });
|
|
99
|
+
fs.renameSync(temp, file);
|
|
100
|
+
}
|
|
101
|
+
const EMPTY_REPORT_STATE = () => ({
|
|
102
|
+
schema_version: REPORT_STATE_SCHEMA, last_attempt_at: null, last_status: null, last_http_status: null,
|
|
103
|
+
last_accepted_at: null, halted_credential_mtime_ms: null,
|
|
104
|
+
});
|
|
105
|
+
export function readReportState(file) {
|
|
106
|
+
try {
|
|
107
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
108
|
+
if (value?.schema_version !== REPORT_STATE_SCHEMA)
|
|
109
|
+
return EMPTY_REPORT_STATE();
|
|
110
|
+
return { ...EMPTY_REPORT_STATE(), ...value };
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return EMPTY_REPORT_STATE();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function writeReportState(file, state) {
|
|
117
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
118
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
119
|
+
fs.writeFileSync(temp, `${JSON.stringify(state)}\n`, { mode: 0o600 });
|
|
120
|
+
fs.renameSync(temp, file);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 未受領の記録がある時に、その時点の累計を1回送る。受領を確かめられた時だけ受け取り済みにする。
|
|
124
|
+
* 届いたか分からない時は何も進めない。次の機会に、その時点の累計を新しいreport_idで送り直す。
|
|
125
|
+
*/
|
|
126
|
+
export async function reportRuntimeErrors(options) {
|
|
127
|
+
const platform = options.platform ?? process.platform;
|
|
128
|
+
const paths = options.paths ?? defaultRuntimeErrorReportPaths({ platform });
|
|
129
|
+
const now = options.now ?? (() => new Date());
|
|
130
|
+
const result = (status, extra = {}) => ({ status, http_status: null, reported_records: 0, acknowledged_cursor: null, ...extra });
|
|
131
|
+
if (runtimeErrorReportingStatus(paths.reportingConfigPath, platform) !== "enabled")
|
|
132
|
+
return result("disabled");
|
|
133
|
+
const credential = readProductCredential(paths.credentialPath, platform);
|
|
134
|
+
if (credential.status === "missing")
|
|
135
|
+
return result("no_credential");
|
|
136
|
+
if (credential.status === "rejected")
|
|
137
|
+
return result("credential_rejected");
|
|
138
|
+
const store = options.store ?? new RuntimeErrorStore();
|
|
139
|
+
const snapshot = store.snapshot();
|
|
140
|
+
if (snapshot.collection !== "enabled" || snapshot.cursor <= snapshot.acknowledged_cursor)
|
|
141
|
+
return result("nothing_to_report");
|
|
142
|
+
const lock = `${paths.reportStatePath}.lock`;
|
|
143
|
+
fs.mkdirSync(path.dirname(lock), { recursive: true, mode: 0o700 });
|
|
144
|
+
try {
|
|
145
|
+
fs.mkdirSync(lock);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error.code !== "EEXIST")
|
|
149
|
+
throw error;
|
|
150
|
+
// 別のprocessが送っている。途中で落ちたprocessの残りだけ、時間を置いて引き取る。
|
|
151
|
+
let stale = false;
|
|
152
|
+
try {
|
|
153
|
+
stale = now().getTime() - fs.statSync(lock).mtimeMs > LOCK_STALE_MS;
|
|
154
|
+
}
|
|
155
|
+
catch { /* 相手が外した */ }
|
|
156
|
+
if (!stale)
|
|
157
|
+
return result("deferred");
|
|
158
|
+
try {
|
|
159
|
+
fs.rmdirSync(lock);
|
|
160
|
+
fs.mkdirSync(lock);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return result("deferred");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const state = readReportState(paths.reportStatePath);
|
|
168
|
+
const started = now();
|
|
169
|
+
const sinceLast = state.last_attempt_at === null ? Infinity : started.getTime() - Date.parse(state.last_attempt_at);
|
|
170
|
+
if (sinceLast < (options.trigger === "auto" ? AUTO_MIN_INTERVAL_MS : MANUAL_MIN_INTERVAL_MS))
|
|
171
|
+
return result("deferred");
|
|
172
|
+
let credentialMtime = null;
|
|
173
|
+
try {
|
|
174
|
+
credentialMtime = fs.statSync(paths.credentialPath).mtimeMs;
|
|
175
|
+
}
|
|
176
|
+
catch { /* 読めた直後に消えた時は下の送信結果に任せる */ }
|
|
177
|
+
if (options.trigger === "auto" && state.halted_credential_mtime_ms !== null && state.halted_credential_mtime_ms === credentialMtime) {
|
|
178
|
+
return result("halted");
|
|
179
|
+
}
|
|
180
|
+
// tsとobserved_atは同じ時刻から作る(受け口は両者が10分より離れたreportを断る)。
|
|
181
|
+
const ts = String(Math.floor(started.getTime() / 1000));
|
|
182
|
+
const reportId = randomUUID();
|
|
183
|
+
const report = buildRuntimeErrorReport(snapshot.records, {
|
|
184
|
+
installedVersion: options.installedVersion ?? pkg.version, reportId,
|
|
185
|
+
observedAt: new Date(Number(ts) * 1000).toISOString(),
|
|
186
|
+
});
|
|
187
|
+
const body = Buffer.from(JSON.stringify(report), "utf8");
|
|
188
|
+
if (body.byteLength > MAX_REPORT_BYTES)
|
|
189
|
+
throw new Error("reportが大きすぎます");
|
|
190
|
+
const finish = (status, httpStatus, acknowledged = null) => {
|
|
191
|
+
writeReportState(paths.reportStatePath, {
|
|
192
|
+
...state, last_attempt_at: started.toISOString(), last_status: status, last_http_status: httpStatus,
|
|
193
|
+
last_accepted_at: status === "accepted" ? started.toISOString() : state.last_accepted_at,
|
|
194
|
+
halted_credential_mtime_ms: status === "halted" ? credentialMtime : null,
|
|
195
|
+
});
|
|
196
|
+
return result(status, { http_status: httpStatus, reported_records: report.runtime_errors.length, acknowledged_cursor: acknowledged });
|
|
197
|
+
};
|
|
198
|
+
let response;
|
|
199
|
+
let text;
|
|
200
|
+
try {
|
|
201
|
+
response = await (options.fetch ?? fetch)(credential.credential.url, {
|
|
202
|
+
method: "POST", redirect: "error", signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
203
|
+
headers: {
|
|
204
|
+
"content-type": "application/json",
|
|
205
|
+
authorization: reportAuthorization(credential.credential.key_id, ts, signReport(credential.credential.secret, ts, body)),
|
|
206
|
+
},
|
|
207
|
+
body,
|
|
208
|
+
});
|
|
209
|
+
text = (await response.text()).slice(0, MAX_RESPONSE_BYTES);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return finish("delivery_unknown", null);
|
|
213
|
+
}
|
|
214
|
+
if (response.status === 200) {
|
|
215
|
+
let parsed = null;
|
|
216
|
+
try {
|
|
217
|
+
parsed = JSON.parse(text);
|
|
218
|
+
}
|
|
219
|
+
catch { /* 署名を確かめられない200は受領にしない */ }
|
|
220
|
+
if (!verifyReportResponse(credential.credential.secret, reportId, parsed))
|
|
221
|
+
return finish("delivery_unknown", 200);
|
|
222
|
+
store.acknowledge(snapshot.cursor);
|
|
223
|
+
return finish("accepted", 200, snapshot.cursor);
|
|
224
|
+
}
|
|
225
|
+
// 合鍵が無効な間は、同じファイルのまま自動で送り続けない。時刻のずれ(401 timestamp_skew)は合鍵の問題ではない。
|
|
226
|
+
if ((response.status === 401 && !/skew/i.test(text)) || response.status === 403)
|
|
227
|
+
return finish("halted", response.status);
|
|
228
|
+
if (response.status === 429)
|
|
229
|
+
return finish("rate_limited", 429);
|
|
230
|
+
if (response.status >= 500)
|
|
231
|
+
return finish("delivery_unknown", response.status);
|
|
232
|
+
return finish("rejected", response.status);
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
try {
|
|
236
|
+
fs.rmdirSync(lock);
|
|
237
|
+
}
|
|
238
|
+
catch { /* 古いlockとして引き取られた */ }
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 自動の送信を別processへ頼む。呼ぶ側(MCP process・記録のworker・CLI)は通信しない。
|
|
243
|
+
* 有効でない端末では何も起動しない。node:testの子で動く時も起動しない(試験が、その端末の本物の記録を
|
|
244
|
+
* 開発中の版の名前で送らないように)。
|
|
245
|
+
*/
|
|
246
|
+
export function triggerRuntimeErrorReport(env = process.env) {
|
|
247
|
+
if (env.NODE_TEST_CONTEXT)
|
|
248
|
+
return false;
|
|
249
|
+
try {
|
|
250
|
+
if (runtimeErrorReportingStatus(defaultRuntimeErrorReportPaths().reportingConfigPath) !== "enabled")
|
|
251
|
+
return false;
|
|
252
|
+
const child = spawn(process.execPath, [WORKER, "report"], { stdio: "ignore", detached: true, windowsHide: true, env });
|
|
253
|
+
child.once("error", () => { });
|
|
254
|
+
child.unref();
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -3,6 +3,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
+
import { defaultRuntimeErrorReportPaths, runtimeErrorReportingStatus } from "./runtime-error-os.js";
|
|
6
7
|
import { defaultRuntimeErrorPaths, windowsPrivateDaclCommand, expectedHostProfiles, readBoundedFile, processStartIdentity, forceKill } from "./runtime-error-os.js";
|
|
7
8
|
export { defaultRuntimeErrorPaths, windowsPrivateDaclCommand, windowsPrivateDaclVerifyCommand } from "./runtime-error-os.js";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
@@ -183,6 +184,7 @@ function validateState(value, maxRecords = 256) {
|
|
|
183
184
|
export class RuntimeErrorStore {
|
|
184
185
|
configPath;
|
|
185
186
|
storePath;
|
|
187
|
+
reportingConfigPath;
|
|
186
188
|
platform;
|
|
187
189
|
arch;
|
|
188
190
|
productVersion;
|
|
@@ -194,6 +196,9 @@ export class RuntimeErrorStore {
|
|
|
194
196
|
const defaults = defaultRuntimeErrorPaths(options);
|
|
195
197
|
this.configPath = options.configPath ?? defaults.configPath;
|
|
196
198
|
this.storePath = options.storePath ?? defaults.storePath;
|
|
199
|
+
this.reportingConfigPath = options.reportingConfigPath !== undefined ? options.reportingConfigPath
|
|
200
|
+
: options.configPath !== undefined || options.storePath !== undefined ? null
|
|
201
|
+
: defaultRuntimeErrorReportPaths(options).reportingConfigPath;
|
|
197
202
|
this.platform = options.platform ?? process.platform;
|
|
198
203
|
if (!ARCHES.has(options.arch ?? process.arch))
|
|
199
204
|
throw new Error("arch が不正です");
|
|
@@ -206,7 +211,12 @@ export class RuntimeErrorStore {
|
|
|
206
211
|
if (!Number.isInteger(this.maxRecords) || this.maxRecords < 1 || this.maxRecords > 256)
|
|
207
212
|
throw new Error("maxRecords は 1..256 必須です");
|
|
208
213
|
}
|
|
209
|
-
|
|
214
|
+
// 報告を有効にした端末は、記録も有効。工場の収集設定が無くても、製品が自分の記録を持てる。
|
|
215
|
+
collectionStatus() {
|
|
216
|
+
if (this.reportingConfigPath !== null && runtimeErrorReportingStatus(this.reportingConfigPath, this.platform) === "enabled")
|
|
217
|
+
return "enabled";
|
|
218
|
+
return collectionStatus(this.configPath, this.platform);
|
|
219
|
+
}
|
|
210
220
|
assertPrivateDirectory(dir) {
|
|
211
221
|
const info = fs.lstatSync(dir);
|
|
212
222
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { RuntimeErrorStore, validateRuntimeObservation } from "./runtime-error-store.js";
|
|
4
|
-
|
|
4
|
+
import { reportRuntimeErrors, triggerRuntimeErrorReport } from "./runtime-error-report.js";
|
|
5
|
+
async function main() {
|
|
5
6
|
const [action, code, ...rest] = process.argv.slice(2);
|
|
6
7
|
if (rest.length > 0)
|
|
7
8
|
throw new Error("invalid args");
|
|
9
|
+
if (action === "report" && code === undefined) {
|
|
10
|
+
await reportRuntimeErrors({ trigger: "auto" });
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
8
13
|
const store = new RuntimeErrorStore();
|
|
9
14
|
if (action === "record" && code) {
|
|
10
|
-
|
|
15
|
+
// 記録できた時だけ、受け口への報告を別processへ頼む(有効にした端末だけ)。このworkerは通信しない。
|
|
16
|
+
if (store.record(validateRuntimeObservation({ code })))
|
|
17
|
+
triggerRuntimeErrorReport();
|
|
11
18
|
return;
|
|
12
19
|
}
|
|
13
20
|
if (action === "diagnostic" && code === undefined) {
|
|
@@ -16,9 +23,4 @@ function main() {
|
|
|
16
23
|
}
|
|
17
24
|
throw new Error("invalid action");
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
main();
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
process.exitCode = 1;
|
|
24
|
-
}
|
|
26
|
+
main().catch(() => { process.exitCode = 1; });
|
|
@@ -3,6 +3,8 @@ import process from "node:process";
|
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { RuntimeErrorStore } from "./runtime-error-store.js";
|
|
6
|
+
import { defaultRuntimeErrorReportPaths, runtimeErrorReportingStatus } from "./runtime-error-os.js";
|
|
7
|
+
import { readProductCredential, readReportState, reportRuntimeErrors, setRuntimeErrorReporting, triggerRuntimeErrorReport, } from "./runtime-error-report.js";
|
|
6
8
|
function parseArgs(argv) {
|
|
7
9
|
const [name, flag, value, ...rest] = argv;
|
|
8
10
|
if (rest.length > 0)
|
|
@@ -18,13 +20,46 @@ function parseArgs(argv) {
|
|
|
18
20
|
if (/^[0-9a-f]{64}$/.test(value))
|
|
19
21
|
return { name, fingerprint: value };
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
if (name === "report" && flag === undefined)
|
|
24
|
+
return { name };
|
|
25
|
+
if (name === "reporting" && (flag === "enable" || flag === "disable" || flag === "status") && value === undefined) {
|
|
26
|
+
return { name, action: flag };
|
|
27
|
+
}
|
|
28
|
+
throw new Error("使い方: aiterm-runtime-errors snapshot | ack --cursor N | resolve|reopen --fingerprint SHA256 | report | reporting enable|disable|status");
|
|
22
29
|
}
|
|
23
30
|
function emit(value) {
|
|
24
31
|
process.stdout.write(`${JSON.stringify(value)}\n`);
|
|
25
32
|
}
|
|
26
|
-
|
|
33
|
+
// 報告の状態。宛先・合鍵・pathは出さない。
|
|
34
|
+
function reportingStatus() {
|
|
35
|
+
const paths = defaultRuntimeErrorReportPaths();
|
|
36
|
+
const snapshot = new RuntimeErrorStore().snapshot();
|
|
37
|
+
const state = readReportState(paths.reportStatePath);
|
|
38
|
+
return {
|
|
39
|
+
reporting: runtimeErrorReportingStatus(paths.reportingConfigPath),
|
|
40
|
+
credential: readProductCredential(paths.credentialPath).status,
|
|
41
|
+
collection: snapshot.collection,
|
|
42
|
+
unreported: Math.max(0, snapshot.cursor - snapshot.acknowledged_cursor),
|
|
43
|
+
last_attempt_at: state.last_attempt_at, last_status: state.last_status,
|
|
44
|
+
last_http_status: state.last_http_status, last_accepted_at: state.last_accepted_at,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
27
48
|
const command = parseArgs(argv);
|
|
49
|
+
if (command.name === "report") {
|
|
50
|
+
const result = await reportRuntimeErrors({ trigger: "manual" });
|
|
51
|
+
emit({ ok: result.status === "accepted" || result.status === "nothing_to_report", command: command.name, result });
|
|
52
|
+
if (result.status !== "accepted" && result.status !== "nothing_to_report")
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (command.name === "reporting") {
|
|
57
|
+
if (command.action !== "status") {
|
|
58
|
+
setRuntimeErrorReporting(defaultRuntimeErrorReportPaths().reportingConfigPath, command.action === "enable");
|
|
59
|
+
}
|
|
60
|
+
emit({ ok: true, command: command.name, action: command.action, status: reportingStatus() });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
28
63
|
const store = new RuntimeErrorStore();
|
|
29
64
|
if (command.name === "snapshot") {
|
|
30
65
|
emit({ ok: true, command: command.name, snapshot: store.snapshot() });
|
|
@@ -38,6 +73,9 @@ export function main(argv = process.argv.slice(2)) {
|
|
|
38
73
|
? store.resolve(command.fingerprint)
|
|
39
74
|
: store.reopen(command.fingerprint);
|
|
40
75
|
emit({ ok: true, command: command.name, changed, snapshot: store.snapshot() });
|
|
76
|
+
// 解決・開き直しも受け口へ知らせる(有効にした端末だけ。送るのは別process)。
|
|
77
|
+
if (changed)
|
|
78
|
+
triggerRuntimeErrorReport();
|
|
41
79
|
}
|
|
42
80
|
function isDirectExecution() {
|
|
43
81
|
if (!process.argv[1])
|
|
@@ -54,13 +92,10 @@ function isDirectExecution() {
|
|
|
54
92
|
}
|
|
55
93
|
}
|
|
56
94
|
if (isDirectExecution()) {
|
|
57
|
-
|
|
58
|
-
main();
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
95
|
+
main().catch(() => {
|
|
61
96
|
// CLI も privacy allowlist を守り、store/config の生例外や path を stdout/stderr に反射しない。
|
|
62
97
|
process.stderr.write("aiterm-runtime-errors: operation failed\n");
|
|
63
98
|
emit({ ok: false, code: "AITERM_RUNTIME_ERROR_STORE_OPERATION_FAILED" });
|
|
64
99
|
process.exitCode = 1;
|
|
65
|
-
}
|
|
100
|
+
});
|
|
66
101
|
}
|
package/docs/DESIGN.md
CHANGED
|
@@ -320,7 +320,9 @@ privacy案内は現在の枠付きcomposerとmodel footerが見える場合だ
|
|
|
320
320
|
## Diagnostics and local error state
|
|
321
321
|
|
|
322
322
|
`diagnostics`はread-onlyで、PTY backendとagent dependencyを検査する。runtime error aggregateは
|
|
323
|
-
製品所有のlocal stateに固定codeと集約metadata
|
|
323
|
+
製品所有のlocal stateに固定codeと集約metadataだけを保存し、既定ではnetwork I/Oを持たない。
|
|
324
|
+
BugHubへの報告は、利用者が明示して有効にし、合鍵のファイルがある端末だけが、別processで行う。
|
|
325
|
+
きっかけは記録・解決・起動・手動の4つで、定期的な見張りは置かない。受け取り済みにするのは応答の署名まで確かめた時だけ(ADR 0079)。工場reporterとの
|
|
324
326
|
連携は明示opt-inの任意adapterであり、未設定時もAiterm本体は単独動作する。raw error、prompt、出力、
|
|
325
327
|
transcript、path、credentialを保存・公開しない。
|
|
326
328
|
親配送hook(Claude Code・Cursor)の登録状態は`src/parent-hook-diagnostic.ts`が利用者設定の読取りだけで要約し、
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"mcpName": "io.github.kitepon/aiterm-mcp",
|
|
5
5
|
"description": "Persistent terminal MCP with one harness-based launcher for Claude Code, Codex CLI, Grok CLI, and Cursor Agent CLI, plus durable PTYs for SSH, containers, and REPLs.",
|
|
6
6
|
"keywords": [
|