* chore(npm): rebrand packages to @opengsd scope Rename: - get-shit-done-redux → @opengsd/get-shit-done-redux - @gsd-redux/sdk → @opengsd/gsd-sdk Add publishConfig.access=public for first-time scoped publish. CLI binary names (get-shit-done-redux, gsd-sdk, gsd-tools) unchanged. Sweeps install commands, npx invocations, CI publish/version-check workflows, tests, docs, READMEs (all translations), and the PACKAGE_NAME constant in check-latest-version. Bumps qs 6.15.1 → 6.15.2 to clear a moderate advisory surfaced by the audit-clean test (GHSA-q8mj-m7cp-5q26). Closes #126 * chore: pin 2.0.0 release + remove canary workflow - Bump both packages 1.50.0-canary.0 → 2.0.0 for first @opengsd publish - Remove .github/workflows/canary.yml and canary dist-tag handling in release.yml / release-sdk.yml - Drop canary section from VERSIONING.md Refs #126 * chore: address review findings + harden tarball-smoke timeout - .changeset/opengsd-org-rename.md: match project's custom parse.cjs frontmatter (type: Changed / pr: 127); the scoped @changesets/cli keys were silently rejected. - CONTEXT.md: drop two canary-stream policy lines and a dangling DEFECT.CANARY-VERSION-LEAK.cross-ref now that canary.yml is gone. - tests/release-tarball-smoke.install.test.cjs: pass timeout: 600_000 for npm pack + global install; the 3-minute runNpm default was timing out on slower Docker hosts (cartographer). Refs #126 * fix(sdk): add missing type/runtime devDependencies for build prepublishOnly invokes tsc which couldn't resolve @types/node, @types/ws, or synckit. They had been hoisted from root but were not declared in sdk/'s own package.json — first publish from a clean SDK tree failed. Refs #126 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ci): use npm pack stdout instead of glob to find tarball `npm pack --silent` for a scoped package (@opengsd/get-shit-done-redux) produces `opengsd-get-shit-done-redux-*.tgz`, not `get-shit-done-redux-*.tgz`. Capture the filename from stdout instead of a hardcoded glob so the step works regardless of package name format. Fixes smoke (ubuntu-latest, 22, false) CI failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * ci: treat workflow-file changes as test-skip eligible `.github/workflows/install-smoke.yml` (and other workflow files) were in neither `test.yml` paths nor `test-skip.yml` paths-ignore, so neither workflow ran on a workflow-only commit — leaving the required test-skip check perpetually missing. Refs #126 * chore: reset version to 1.0.0 for first @opengsd publish Nothing has been published yet under the @opengsd scope, so the inaugural release uses 1.0.0 rather than 2.0.0. The "major bump" in the changeset reflects the breaking install-command change for users migrating from the prior unscoped `get-shit-done-redux`, not a numeric continuation from a 1.x line under the new identity. Refs #126 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
116 lines
4.0 KiB
Markdown
116 lines
4.0 KiB
Markdown
# コンテキストウィンドウモニター
|
||
|
||
ツール使用後に実行されるフック(Claude Code では `PostToolUse`、Gemini CLI では `AfterTool`)で、コンテキストウィンドウの使用量が高くなった際にエージェントに警告します。
|
||
|
||
## 課題
|
||
|
||
ステータスラインはコンテキスト使用量を**ユーザー**に表示しますが、**エージェント**自身はコンテキストの制限を認識していません。コンテキストが不足すると、エージェントは限界に達するまで作業を続行し、タスクの途中で状態を保存できないまま停止する可能性があります。
|
||
|
||
## 仕組み
|
||
|
||
1. ステータスラインフックがコンテキストメトリクスを `/tmp/claude-ctx-{session_id}.json` に書き込む
|
||
2. 各ツール使用後、コンテキストモニターがこのメトリクスを読み取る
|
||
3. 残りコンテキストがしきい値を下回ると、`additionalContext` として警告を注入する
|
||
4. エージェントが会話内で警告を受け取り、適切に対応できる
|
||
|
||
## しきい値
|
||
|
||
| レベル | 残量 | エージェントの動作 |
|
||
|--------|------|------------------|
|
||
| Normal | > 35% | 警告なし |
|
||
| WARNING | <= 35% | 現在のタスクをまとめ、新しい複雑な作業の開始を避ける |
|
||
| CRITICAL | <= 25% | 即座に停止し、状態を保存する(`/gsd-pause-work`) |
|
||
|
||
## デバウンス
|
||
|
||
エージェントへの繰り返し警告を防ぐため:
|
||
- 最初の警告は即座に発火
|
||
- 以降の警告は間に5回のツール使用が必要
|
||
- 深刻度のエスカレーション(WARNING -> CRITICAL)はデバウンスをバイパス
|
||
|
||
## アーキテクチャ
|
||
|
||
```
|
||
ステータスラインフック (gsd-statusline.js)
|
||
| 書き込み
|
||
v
|
||
/tmp/claude-ctx-{session_id}.json
|
||
^ 読み取り
|
||
|
|
||
コンテキストモニター (gsd-context-monitor.js, PostToolUse/AfterTool)
|
||
| 注入
|
||
v
|
||
additionalContext -> エージェントが警告を確認
|
||
```
|
||
|
||
ブリッジファイルはシンプルな JSON オブジェクトです:
|
||
|
||
```json
|
||
{
|
||
"session_id": "abc123",
|
||
"remaining_percentage": 28.5,
|
||
"used_pct": 71,
|
||
"timestamp": 1708200000
|
||
}
|
||
```
|
||
|
||
## GSD との統合
|
||
|
||
GSD の `/gsd-pause-work` コマンドは実行状態を保存します。WARNING メッセージはこのコマンドの使用を提案し、CRITICAL メッセージは即座の状態保存を指示します。
|
||
|
||
## セットアップ
|
||
|
||
両フックは `npx @opengsd/get-shit-done-redux` のインストール時に自動的に登録されます:
|
||
|
||
- **ステータスライン**(ブリッジファイルの書き込み): settings.json の `statusLine` として登録
|
||
- **コンテキストモニター**(ブリッジファイルの読み取り): settings.json の `PostToolUse` フックとして登録(Gemini では `AfterTool`)
|
||
|
||
`~/.claude/settings.json`(Claude Code)への手動登録:
|
||
|
||
```json
|
||
{
|
||
"statusLine": {
|
||
"type": "command",
|
||
"command": "node ~/.claude/hooks/gsd-statusline.js"
|
||
},
|
||
"hooks": {
|
||
"PostToolUse": [
|
||
{
|
||
"hooks": [
|
||
{
|
||
"type": "command",
|
||
"command": "node ~/.claude/hooks/gsd-context-monitor.js"
|
||
}
|
||
]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
|
||
Gemini CLI(`~/.gemini/settings.json`)の場合、`PostToolUse` の代わりに `AfterTool` を使用します:
|
||
|
||
```json
|
||
{
|
||
"hooks": {
|
||
"AfterTool": [
|
||
{
|
||
"hooks": [
|
||
{
|
||
"type": "command",
|
||
"command": "node ~/.gemini/hooks/gsd-context-monitor.js"
|
||
}
|
||
]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
|
||
## 安全性
|
||
|
||
- フックは全体を try/catch で囲み、エラー時はサイレントに終了
|
||
- ツール実行をブロックしない — モニターの故障がエージェントのワークフローを壊してはならない
|
||
- 古いメトリクス(60秒以上前)は無視
|
||
- ブリッジファイルが存在しない場合も正常に処理(サブエージェント、新規セッション)
|