@code-yeongyu/senpi 2026.9.2 → 2026.9.3
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 +124 -2
- package/dist/beta/omo-local-update-fingerprint.d.ts.map +1 -1
- package/dist/beta/omo-local-update-fingerprint.js +0 -1
- package/dist/beta/omo-local-update-fingerprint.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/build.js +2 -5
- package/dist/core/dynamic-prompt/build.js.map +1 -1
- package/dist/core/dynamic-prompt/index.d.ts +1 -2
- package/dist/core/dynamic-prompt/index.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/index.js +1 -2
- package/dist/core/dynamic-prompt/index.js.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.js +9 -24
- package/dist/core/dynamic-prompt/intent-gate.js.map +1 -1
- package/dist/core/dynamic-prompt/policies.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/policies.js +3 -7
- package/dist/core/dynamic-prompt/policies.js.map +1 -1
- package/dist/core/dynamic-prompt/style.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/style.js +6 -8
- package/dist/core/dynamic-prompt/style.js.map +1 -1
- package/dist/core/dynamic-prompt/verification.js +1 -1
- package/dist/core/dynamic-prompt/verification.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.d.ts +2 -0
- package/dist/core/dynamic-prompt/working-task.d.ts.map +1 -0
- package/dist/core/dynamic-prompt/working-task.js +10 -0
- package/dist/core/dynamic-prompt/working-task.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js +6 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +2 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js +27 -9
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +52 -50
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +50 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +66 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +5 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +6 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +8 -2
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +8 -3
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts +4 -3
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +18 -18
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +7 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +37 -8
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +17 -13
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js +14 -2
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +27 -10
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +17 -8
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -3
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/index.d.ts +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +6 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
- package/dist/modes/rpc/host-ensure.js +36 -9
- package/dist/modes/rpc/host-ensure.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +16 -4
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.d.ts +7 -4
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +7 -4
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +8 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +62 -7
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +22 -0
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +132 -94
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-fanout.d.ts +40 -0
- package/dist/modes/rpc/session-event-fanout.d.ts.map +1 -0
- package/dist/modes/rpc/session-event-fanout.js +146 -0
- package/dist/modes/rpc/session-event-fanout.js.map +1 -0
- package/dist/modes/rpc/session-event-writer.d.ts +6 -13
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +48 -96
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +9 -8
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +14 -42
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-teardown.d.ts +12 -0
- package/dist/modes/rpc/session-teardown.d.ts.map +1 -0
- package/dist/modes/rpc/session-teardown.js +117 -0
- package/dist/modes/rpc/session-teardown.js.map +1 -0
- package/docs/rpc.md +10 -6
- package/docs/settings.md +4 -4
- package/docs/terminal-tools.md +26 -6
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +57 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +4 -2
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/skill-contribution.ts +43 -9
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +4 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +10 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/SKILL.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/references/runtime-apis.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +3 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -2
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +26 -4
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
- package/dist/core/dynamic-prompt/exploration.d.ts +0 -2
- package/dist/core/dynamic-prompt/exploration.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/exploration.js +0 -6
- package/dist/core/dynamic-prompt/exploration.js.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.d.ts +0 -2
- package/dist/core/dynamic-prompt/parallel-tools.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.js +0 -8
- package/dist/core/dynamic-prompt/parallel-tools.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-notify.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-notify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAA6B,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AACjD,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AACnD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,gCAAgC,GAAG,4BAA4B,CAAC;AACtE,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAQ3C,MAAM,eAAe,GAAiC;IACrD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,UAAU,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC;IAChE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAsC,CAAC;CAC7E,CAAC;AAcF,SAAS,kBAAkB,CAAC,KAAa,EAAE,QAAgB,EAAE,OAAe,EAAE,OAAe;IAC5F,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;A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E,CAAC;IACvG,CAAC;CACD","sourcesContent":["import type { MonitorEvent } from \"./monitor-registry.ts\";\nimport { getTerminalNotificationDelivery, type TerminalNotifierDeps } from \"./notify.ts\";\nimport { sanitizeTerminalOutput } from \"./output-format.ts\";\nimport type { MonitorDeliverySettings } from \"./settings.ts\";\n\nconst SYSTEM_REMINDER_OPEN = \"<system-reminder>\";\nconst SYSTEM_REMINDER_CLOSE = \"</system-reminder>\";\nconst QUEUE_OVERHEAD_CHARS = 512;\nconst MONITOR_NOTIFICATION_CUSTOM_TYPE = \"senpi-monitor:notification\";\nconst WAKE_STREAK_QUIET_GAP_MULTIPLIER = 2;\n\nexport interface MonitorNotificationScheduler {\n\tnow(): number;\n\tsetTimeout(callback: () => void, delayMs: number): unknown;\n\tclearTimeout(timer: unknown): void;\n}\n\nconst systemScheduler: MonitorNotificationScheduler = {\n\tnow: () => Date.now(),\n\tsetTimeout: (callback, delayMs) => setTimeout(callback, delayMs),\n\tclearTimeout: (timer) => clearTimeout(timer as ReturnType<typeof setTimeout>),\n};\n\nexport interface MonitorNotifierDeps extends TerminalNotifierDeps {\n\treadonly getSettings: () => MonitorDeliverySettings;\n\t/** Pause live monitors when their shared wake budget is exhausted. */\n\treadonly pauseMonitors: () => readonly string[];\n\treadonly scheduler?: MonitorNotificationScheduler;\n}\n\ninterface Overflow {\n\treadonly id: string;\n\tcount: number;\n}\n\nfunction boundedPositiveInt(value: number, fallback: number, minimum: number, maximum: number): number {\n\tif (!Number.isFinite(value)) return fallback;\n\treturn Math.min(Math.max(Math.trunc(value), minimum), maximum);\n}\n\nfunction resolveSettings(settings: MonitorDeliverySettings): MonitorDeliverySettings {\n\treturn {\n\t\tcoalesceWindowMs: boundedPositiveInt(settings.coalesceWindowMs, 2000, 1, 60_000),\n\t\trateLimitMs: boundedPositiveInt(settings.rateLimitMs, 5000, 1, 3_600_000),\n\t\tmaxLinesPerInjection: boundedPositiveInt(settings.maxLinesPerInjection, 50, 1, 200),\n\t\tmaxCharsPerInjection: boundedPositiveInt(settings.maxCharsPerInjection, 4096, 512, 16_384),\n\t\twakeBudget: boundedPositiveInt(settings.wakeBudget, 5, 1, 100),\n\t};\n}\n\nfunction eventBody(event: MonitorEvent): string {\n\tconst value = event.type === \"line\" ? event.line : event.summary;\n\treturn sanitizeTerminalOutput(value)\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.trimEnd();\n}\n\nfunction clip(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tif (maxChars <= 3) return text.slice(0, maxChars);\n\treturn `${text.slice(0, maxChars - 3)}...`;\n}\n\nfunction formatEvents(events: readonly MonitorEvent[]): string {\n\tconst groups = new Map<string, { description: string; bodies: string[] }>();\n\tfor (const event of events) {\n\t\tconst group = groups.get(event.id) ?? { description: event.description, bodies: [] };\n\t\tgroup.bodies.push(eventBody(event));\n\t\tgroups.set(event.id, group);\n\t}\n\treturn [...groups.values()]\n\t\t.map((group) => `Monitor event(${group.description}): ${group.bodies.join(\"\\n\")}`)\n\t\t.join(\"\\n\");\n}\n\n/**\n * Session-scoped monitor delivery queue. It preserves the terminal runtime as the authoritative,\n * bounded event history while retaining only one capped coalescing batch for chat injection.\n */\nexport class MonitorNotifier {\n\treadonly #deps: MonitorNotifierDeps;\n\treadonly #scheduler: MonitorNotificationScheduler;\n\t#events: MonitorEvent[] = [];\n\t#eventChars = 0;\n\t#overflow = new Map<string, Overflow>();\n\t#lastInjectionAt = new Map<string, number>();\n\t#lastInjectedBatch = new Map<string, string>();\n\t#timer: unknown;\n\t#scheduledAt: number | undefined;\n\t#consecutiveWakes = 0;\n\t#lastWakeAt: number | undefined;\n\t#wakeBudgetPaused = false;\n\n\tconstructor(deps: MonitorNotifierDeps) {\n\t\tthis.#deps = deps;\n\t\tthis.#scheduler = deps.scheduler ?? systemScheduler;\n\t}\n\n\tnotifyEvent(event: MonitorEvent): void {\n\t\tif (this.#wakeBudgetPaused) {\n\t\t\tif (event.type === \"line\") return;\n\t\t\tthis.#wakeBudgetPaused = false;\n\t\t\tthis.#consecutiveWakes = 0;\n\t\t\tthis.#lastInjectionAt.delete(event.id);\n\t\t}\n\t\tif (!getTerminalNotificationDelivery(this.#deps, MONITOR_NOTIFICATION_CUSTOM_TYPE)) return;\n\t\tconst settings = resolveSettings(this.#deps.getSettings());\n\t\tconst rendered = `Monitor event(${event.description}): ${eventBody(event)}`;\n\t\tconst queueLimit = Math.max(1, settings.maxCharsPerInjection - QUEUE_OVERHEAD_CHARS);\n\t\tif (this.#events.length >= settings.maxLinesPerInjection || this.#eventChars + rendered.length > queueLimit) {\n\t\t\tthis.#recordOverflow(event.id);\n\t\t} else {\n\t\t\tthis.#events.push(event);\n\t\t\tthis.#eventChars += rendered.length;\n\t\t}\n\t\tthis.#schedule(settings.coalesceWindowMs);\n\t}\n\n\t/** Any explicit user or tool activity breaks a consecutive monitor-only wake streak. */\n\tnoteActivity(): void {\n\t\tthis.#consecutiveWakes = 0;\n\t}\n\n\t/** Explicit rearm resumes intermediate line delivery after the session-global wake pause. */\n\trearm(id: string): void {\n\t\tthis.#wakeBudgetPaused = false;\n\t\tthis.#consecutiveWakes = 0;\n\t\tthis.#lastInjectionAt.delete(id);\n\t\tthis.#lastInjectedBatch.delete(id);\n\t}\n\n\tdispose(): void {\n\t\tif (this.#timer !== undefined) this.#scheduler.clearTimeout(this.#timer);\n\t\tthis.#timer = undefined;\n\t\tthis.#scheduledAt = undefined;\n\t\tthis.#events = [];\n\t\tthis.#eventChars = 0;\n\t\tthis.#overflow.clear();\n\t\tthis.#lastInjectedBatch.clear();\n\t}\n\n\t#recordOverflow(id: string): void {\n\t\tconst overflow = this.#overflow.get(id) ?? { id, count: 0 };\n\t\toverflow.count++;\n\t\tthis.#overflow.set(id, overflow);\n\t}\n\n\t#schedule(delayMs: number): void {\n\t\tconst due = this.#scheduler.now() + delayMs;\n\t\tif (this.#timer !== undefined && this.#scheduledAt !== undefined && this.#scheduledAt <= due) return;\n\t\tif (this.#timer !== undefined) this.#scheduler.clearTimeout(this.#timer);\n\t\tthis.#scheduledAt = due;\n\t\tthis.#timer = this.#scheduler.setTimeout(() => this.#flush(), delayMs);\n\t}\n\n\t#flush(): void {\n\t\tthis.#timer = undefined;\n\t\tthis.#scheduledAt = undefined;\n\t\tif (this.#wakeBudgetPaused) {\n\t\t\tthis.dispose();\n\t\t\treturn;\n\t\t}\n\t\tconst delivery = getTerminalNotificationDelivery(this.#deps, MONITOR_NOTIFICATION_CUSTOM_TYPE);\n\t\tif (!delivery) {\n\t\t\tthis.dispose();\n\t\t\treturn;\n\t\t}\n\n\t\tconst settings = resolveSettings(this.#deps.getSettings());\n\t\tconst now = this.#scheduler.now();\n\t\tconst pendingIds = new Set([...this.#events.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (pendingIds.size === 0) return;\n\t\tconst ready = new Set(\n\t\t\t[...pendingIds].filter((id) => {\n\t\t\t\tconst last = this.#lastInjectionAt.get(id);\n\t\t\t\treturn last === undefined || now - last >= settings.rateLimitMs;\n\t\t\t}),\n\t\t);\n\t\tif (ready.size === 0) {\n\t\t\tthis.#scheduleNextRateLimit(pendingIds, now, settings);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fingerprints = this.#batchFingerprints(ready);\n\t\tconst suppressedIds = new Set(\n\t\t\t[...fingerprints]\n\t\t\t\t.filter(([id, fingerprint]) => this.#lastInjectedBatch.get(id) === fingerprint)\n\t\t\t\t.map(([id]) => id),\n\t\t);\n\t\tconst injectedIds = new Set([...ready].filter((id) => !suppressedIds.has(id)));\n\t\tconst selected = this.#events.filter((event) => injectedIds.has(event.id));\n\t\tconst deferred = this.#events.filter((event) => !ready.has(event.id));\n\t\tif (injectedIds.size === 0) {\n\t\t\tthis.#discardSuppressed(deferred, now, settings);\n\t\t\treturn;\n\t\t}\n\t\tconst overflowCount = [...this.#overflow.values()]\n\t\t\t.filter((overflow) => injectedIds.has(overflow.id))\n\t\t\t.reduce((total, overflow) => total + overflow.count, 0);\n\t\tif (\n\t\t\tthis.#lastWakeAt !== undefined &&\n\t\t\tnow - this.#lastWakeAt > settings.rateLimitMs * WAKE_STREAK_QUIET_GAP_MULTIPLIER\n\t\t) {\n\t\t\tthis.#consecutiveWakes = 0;\n\t\t}\n\t\tconst deliversSummary = selected.some((event) => event.type === \"summary\");\n\t\tconst reachesBudget = !deliversSummary && this.#consecutiveWakes + 1 >= settings.wakeBudget;\n\t\tconst pauseNotice = reachesBudget\n\t\t\t? \"Monitor paused after repeated updates. Completion still wakes this session; peek bash_output or re-arm only for intermediate events.\"\n\t\t\t: \"\";\n\t\tconst content = this.#buildMessage(selected, overflowCount, pauseNotice, settings.maxCharsPerInjection);\n\n\t\tdelivery.send(content, reachesBudget ? { forceWake: true } : undefined);\n\t\tthis.#lastWakeAt = now;\n\t\tfor (const id of injectedIds) {\n\t\t\tthis.#lastInjectionAt.set(id, now);\n\t\t\tthis.#overflow.delete(id);\n\t\t\tconst fingerprint = fingerprints.get(id);\n\t\t\tif (fingerprint === undefined) this.#lastInjectedBatch.delete(id);\n\t\t\telse this.#lastInjectedBatch.set(id, fingerprint);\n\t\t}\n\t\tthis.#events = deferred;\n\t\tthis.#eventChars = deferred.reduce(\n\t\t\t(total, event) => total + `Monitor event(${event.description}): ${eventBody(event)}`.length,\n\t\t\t0,\n\t\t);\n\t\tthis.#consecutiveWakes = deliversSummary ? 0 : this.#consecutiveWakes + 1;\n\n\t\tif (reachesBudget) {\n\t\t\tthis.#wakeBudgetPaused = true;\n\t\t\tthis.#deps.pauseMonitors();\n\t\t\tthis.#events = [];\n\t\t\tthis.#eventChars = 0;\n\t\t\tthis.#overflow.clear();\n\t\t\treturn;\n\t\t}\n\t\tconst remainingIds = new Set([...this.#events.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (remainingIds.size > 0) this.#scheduleNextRateLimit(remainingIds, now, settings);\n\t}\n\n\t#scheduleNextRateLimit(ids: ReadonlySet<string>, now: number, settings: MonitorDeliverySettings): void {\n\t\tconst nextAt = Math.min(...[...ids].map((id) => (this.#lastInjectionAt.get(id) ?? now) + settings.rateLimitMs));\n\t\tthis.#schedule(Math.max(1, nextAt - now));\n\t}\n\n\t/** A ready monitor whose line-only batch matches its previous injection carries no new information. */\n\t#batchFingerprints(ids: ReadonlySet<string>): Map<string, string> {\n\t\tconst fingerprints = new Map<string, string>();\n\t\tfor (const id of ids) {\n\t\t\tif ((this.#overflow.get(id)?.count ?? 0) > 0) continue;\n\t\t\tconst batch = this.#events.filter((event) => event.id === id);\n\t\t\tif (batch.length === 0 || batch.some((event) => event.type !== \"line\")) continue;\n\t\t\tfingerprints.set(id, batch.map(eventBody).join(\"\\n\"));\n\t\t}\n\t\treturn fingerprints;\n\t}\n\n\t#discardSuppressed(deferred: MonitorEvent[], now: number, settings: MonitorDeliverySettings): void {\n\t\tthis.#events = deferred;\n\t\tthis.#eventChars = deferred.reduce(\n\t\t\t(total, event) => total + `Monitor event(${event.description}): ${eventBody(event)}`.length,\n\t\t\t0,\n\t\t);\n\t\tconst remainingIds = new Set([...deferred.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (remainingIds.size > 0) this.#scheduleNextRateLimit(remainingIds, now, settings);\n\t}\n\n\t#buildMessage(\n\t\tevents: readonly MonitorEvent[],\n\t\toverflowCount: number,\n\t\tpauseNotice: string,\n\t\tmaxChars: number,\n\t): string {\n\t\tconst overflowNotice =\n\t\t\toverflowCount > 0\n\t\t\t\t? `[${overflowCount} additional event lines omitted; peek bash_output for full history.]`\n\t\t\t\t: \"\";\n\t\tconst suffix = [overflowNotice, pauseNotice].filter(Boolean).join(\"\\n\");\n\t\tconst fixedChars = SYSTEM_REMINDER_OPEN.length + SYSTEM_REMINDER_CLOSE.length + (suffix ? suffix.length + 1 : 0);\n\t\tconst body = clip(formatEvents(events), Math.max(0, maxChars - fixedChars));\n\t\treturn `${SYSTEM_REMINDER_OPEN}${body}${body && suffix ? \"\\n\" : \"\"}${suffix}${SYSTEM_REMINDER_CLOSE}`;\n\t}\n}\n"]}
|
|
1
|
+
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,GAAG,qBAAqB,EAAE,CAAC;IACvG,CAAC;CACD","sourcesContent":["import type { MonitorEvent } from \"./monitor-registry.ts\";\nimport { getTerminalNotificationDelivery, type TerminalNotifierDeps } from \"./notify.ts\";\nimport { sanitizeTerminalOutput } from \"./output-format.ts\";\nimport type { MonitorDeliverySettings } from \"./settings.ts\";\n\nconst SYSTEM_REMINDER_OPEN = \"<system-reminder>\";\nconst SYSTEM_REMINDER_CLOSE = \"</system-reminder>\";\nconst QUEUE_OVERHEAD_CHARS = 512;\nconst MONITOR_NOTIFICATION_CUSTOM_TYPE = \"senpi-monitor:notification\";\nconst WAKE_STREAK_QUIET_GAP_MULTIPLIER = 2;\n\nexport interface MonitorNotificationScheduler {\n\tnow(): number;\n\tsetTimeout(callback: () => void, delayMs: number): unknown;\n\tclearTimeout(timer: unknown): void;\n}\n\nconst systemScheduler: MonitorNotificationScheduler = {\n\tnow: () => Date.now(),\n\tsetTimeout: (callback, delayMs) => setTimeout(callback, delayMs),\n\tclearTimeout: (timer) => clearTimeout(timer as ReturnType<typeof setTimeout>),\n};\n\nexport interface MonitorNotifierDeps extends TerminalNotifierDeps {\n\treadonly getSettings: () => MonitorDeliverySettings;\n\t/** Pause the monitors contributing to a shared wake-budget exhaustion. */\n\treadonly pauseMonitors: (ids: readonly string[]) => readonly string[];\n\treadonly scheduler?: MonitorNotificationScheduler;\n}\n\ninterface Overflow {\n\treadonly id: string;\n\tcount: number;\n}\n\nfunction boundedPositiveInt(value: number, fallback: number, minimum: number, maximum: number): number {\n\tif (!Number.isFinite(value)) return fallback;\n\treturn Math.min(Math.max(Math.trunc(value), minimum), maximum);\n}\n\nfunction resolveSettings(settings: MonitorDeliverySettings): MonitorDeliverySettings {\n\treturn {\n\t\tcoalesceWindowMs: boundedPositiveInt(settings.coalesceWindowMs, 2000, 1, 60_000),\n\t\trateLimitMs: boundedPositiveInt(settings.rateLimitMs, 5000, 1, 3_600_000),\n\t\tmaxLinesPerInjection: boundedPositiveInt(settings.maxLinesPerInjection, 50, 1, 200),\n\t\tmaxCharsPerInjection: boundedPositiveInt(settings.maxCharsPerInjection, 4096, 512, 16_384),\n\t\twakeBudget: boundedPositiveInt(settings.wakeBudget, 5, 1, 100),\n\t};\n}\n\nfunction eventBody(event: MonitorEvent): string {\n\tconst value = event.type === \"line\" ? event.line : event.summary;\n\treturn sanitizeTerminalOutput(value)\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.trimEnd();\n}\n\nfunction clip(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tif (maxChars <= 3) return text.slice(0, maxChars);\n\treturn `${text.slice(0, maxChars - 3)}...`;\n}\n\nfunction formatEvents(events: readonly MonitorEvent[]): string {\n\tconst groups = new Map<string, { description: string; bodies: string[] }>();\n\tfor (const event of events) {\n\t\tconst group = groups.get(event.id) ?? { description: event.description, bodies: [] };\n\t\tgroup.bodies.push(eventBody(event));\n\t\tgroups.set(event.id, group);\n\t}\n\treturn [...groups.values()]\n\t\t.map((group) => `Monitor event(${group.description}): ${group.bodies.join(\"\\n\")}`)\n\t\t.join(\"\\n\");\n}\n\n/**\n * Session-scoped monitor delivery queue. It preserves the terminal runtime as the authoritative,\n * bounded event history while retaining only one capped coalescing batch for chat injection.\n */\nexport class MonitorNotifier {\n\treadonly #deps: MonitorNotifierDeps;\n\treadonly #scheduler: MonitorNotificationScheduler;\n\t#events: MonitorEvent[] = [];\n\t#eventChars = 0;\n\t#overflow = new Map<string, Overflow>();\n\t#lastInjectionAt = new Map<string, number>();\n\t#lastInjectedBatch = new Map<string, string>();\n\t#timer: unknown;\n\t#scheduledAt: number | undefined;\n\t#consecutiveWakes = 0;\n\t#lastWakeAt: number | undefined;\n\n\tconstructor(deps: MonitorNotifierDeps) {\n\t\tthis.#deps = deps;\n\t\tthis.#scheduler = deps.scheduler ?? systemScheduler;\n\t}\n\n\tnotifyEvent(event: MonitorEvent): void {\n\t\tif (event.type === \"summary\") {\n\t\t\tthis.#lastInjectionAt.delete(event.id);\n\t\t\tthis.#lastInjectedBatch.delete(event.id);\n\t\t}\n\t\tif (!getTerminalNotificationDelivery(this.#deps, MONITOR_NOTIFICATION_CUSTOM_TYPE)) return;\n\t\tconst settings = resolveSettings(this.#deps.getSettings());\n\t\tconst rendered = `Monitor event(${event.description}): ${eventBody(event)}`;\n\t\tconst queueLimit = Math.max(1, settings.maxCharsPerInjection - QUEUE_OVERHEAD_CHARS);\n\t\tif (\n\t\t\tevent.type !== \"summary\" &&\n\t\t\t(this.#events.length >= settings.maxLinesPerInjection || this.#eventChars + rendered.length > queueLimit)\n\t\t) {\n\t\t\tthis.#recordOverflow(event.id);\n\t\t} else {\n\t\t\tthis.#events.push(event);\n\t\t\tthis.#eventChars += rendered.length;\n\t\t}\n\t\tthis.#schedule(settings.coalesceWindowMs);\n\t}\n\n\t/** Any explicit user or tool activity breaks a consecutive monitor-only wake streak. */\n\tnoteActivity(): void {\n\t\tthis.#consecutiveWakes = 0;\n\t}\n\n\t/** Clear delivery bookkeeping for monitors explicitly resumed by the registry. */\n\tresume(ids: readonly string[]): void {\n\t\tfor (const id of ids) {\n\t\t\tthis.#lastInjectionAt.delete(id);\n\t\t\tthis.#lastInjectedBatch.delete(id);\n\t\t}\n\t\tthis.#consecutiveWakes = 0;\n\t}\n\n\trearm(id: string): void {\n\t\tthis.resume([id]);\n\t}\n\n\tdispose(): void {\n\t\tif (this.#timer !== undefined) this.#scheduler.clearTimeout(this.#timer);\n\t\tthis.#timer = undefined;\n\t\tthis.#scheduledAt = undefined;\n\t\tthis.#events = [];\n\t\tthis.#eventChars = 0;\n\t\tthis.#overflow.clear();\n\t\tthis.#lastInjectedBatch.clear();\n\t}\n\n\t#recordOverflow(id: string): void {\n\t\tconst overflow = this.#overflow.get(id) ?? { id, count: 0 };\n\t\toverflow.count++;\n\t\tthis.#overflow.set(id, overflow);\n\t}\n\n\t#schedule(delayMs: number): void {\n\t\tconst due = this.#scheduler.now() + delayMs;\n\t\tif (this.#timer !== undefined && this.#scheduledAt !== undefined && this.#scheduledAt <= due) return;\n\t\tif (this.#timer !== undefined) this.#scheduler.clearTimeout(this.#timer);\n\t\tthis.#scheduledAt = due;\n\t\tthis.#timer = this.#scheduler.setTimeout(() => this.#flush(), delayMs);\n\t}\n\n\t#flush(): void {\n\t\tthis.#timer = undefined;\n\t\tthis.#scheduledAt = undefined;\n\t\tconst delivery = getTerminalNotificationDelivery(this.#deps, MONITOR_NOTIFICATION_CUSTOM_TYPE);\n\t\tif (!delivery) {\n\t\t\tthis.dispose();\n\t\t\treturn;\n\t\t}\n\n\t\tconst settings = resolveSettings(this.#deps.getSettings());\n\t\tconst now = this.#scheduler.now();\n\t\tconst pendingIds = new Set([...this.#events.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (pendingIds.size === 0) return;\n\t\tconst summaryIds = new Set(this.#events.filter((event) => event.type === \"summary\").map((event) => event.id));\n\t\tconst ready = new Set(\n\t\t\t[...pendingIds].filter((id) => {\n\t\t\t\tif (summaryIds.has(id)) return true;\n\t\t\t\tconst last = this.#lastInjectionAt.get(id);\n\t\t\t\treturn last === undefined || now - last >= settings.rateLimitMs;\n\t\t\t}),\n\t\t);\n\t\tif (ready.size === 0) {\n\t\t\tthis.#scheduleNextRateLimit(pendingIds, now, settings);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fingerprints = this.#batchFingerprints(ready);\n\t\tconst suppressedIds = new Set(\n\t\t\t[...fingerprints]\n\t\t\t\t.filter(([id, fingerprint]) => this.#lastInjectedBatch.get(id) === fingerprint)\n\t\t\t\t.map(([id]) => id),\n\t\t);\n\t\tconst injectedIds = new Set([...ready].filter((id) => !suppressedIds.has(id)));\n\t\tconst selected = this.#events.filter((event) => injectedIds.has(event.id));\n\t\tconst deferred = this.#events.filter((event) => !ready.has(event.id));\n\t\tif (injectedIds.size === 0) {\n\t\t\tthis.#discardSuppressed(deferred, now, settings);\n\t\t\treturn;\n\t\t}\n\t\tconst overflowCount = [...this.#overflow.values()]\n\t\t\t.filter((overflow) => injectedIds.has(overflow.id))\n\t\t\t.reduce((total, overflow) => total + overflow.count, 0);\n\t\tif (\n\t\t\tthis.#lastWakeAt !== undefined &&\n\t\t\tnow - this.#lastWakeAt > settings.rateLimitMs * WAKE_STREAK_QUIET_GAP_MULTIPLIER\n\t\t) {\n\t\t\tthis.#consecutiveWakes = 0;\n\t\t}\n\t\tconst deliversSummary = selected.some((event) => event.type === \"summary\");\n\t\tconst reachesBudget = !deliversSummary && this.#consecutiveWakes + 1 >= settings.wakeBudget;\n\t\tconst pauseNotice = reachesBudget\n\t\t\t? \"Monitor paused after repeated updates. Completion still wakes this session; peek bash_output or re-arm only for intermediate events.\"\n\t\t\t: \"\";\n\t\tconst content = this.#buildMessage(selected, overflowCount, pauseNotice, settings.maxCharsPerInjection);\n\n\t\tdelivery.send(content, reachesBudget ? { forceWake: true } : undefined);\n\t\tthis.#lastWakeAt = now;\n\t\tfor (const id of injectedIds) {\n\t\t\tthis.#lastInjectionAt.set(id, now);\n\t\t\tthis.#overflow.delete(id);\n\t\t\tconst fingerprint = fingerprints.get(id);\n\t\t\tif (fingerprint === undefined) this.#lastInjectedBatch.delete(id);\n\t\t\telse this.#lastInjectedBatch.set(id, fingerprint);\n\t\t}\n\t\tthis.#events = deferred;\n\t\tthis.#eventChars = deferred.reduce(\n\t\t\t(total, event) => total + `Monitor event(${event.description}): ${eventBody(event)}`.length,\n\t\t\t0,\n\t\t);\n\t\tthis.#consecutiveWakes = deliversSummary ? 0 : this.#consecutiveWakes + 1;\n\n\t\tif (reachesBudget) {\n\t\t\tthis.#deps.pauseMonitors([...injectedIds]);\n\t\t\tthis.#events = [];\n\t\t\tthis.#eventChars = 0;\n\t\t\tthis.#overflow.clear();\n\t\t\tthis.#consecutiveWakes = 0;\n\t\t\treturn;\n\t\t}\n\t\tconst remainingIds = new Set([...this.#events.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (remainingIds.size > 0) this.#scheduleNextRateLimit(remainingIds, now, settings);\n\t}\n\n\t#scheduleNextRateLimit(ids: ReadonlySet<string>, now: number, settings: MonitorDeliverySettings): void {\n\t\tconst nextAt = Math.min(...[...ids].map((id) => (this.#lastInjectionAt.get(id) ?? now) + settings.rateLimitMs));\n\t\tthis.#schedule(Math.max(1, nextAt - now));\n\t}\n\n\t/** A ready monitor whose line-only batch matches its previous injection carries no new information. */\n\t#batchFingerprints(ids: ReadonlySet<string>): Map<string, string> {\n\t\tconst fingerprints = new Map<string, string>();\n\t\tfor (const id of ids) {\n\t\t\tif ((this.#overflow.get(id)?.count ?? 0) > 0) continue;\n\t\t\tconst batch = this.#events.filter((event) => event.id === id);\n\t\t\tif (batch.length === 0 || batch.some((event) => event.type !== \"line\")) continue;\n\t\t\tfingerprints.set(id, batch.map(eventBody).join(\"\\n\"));\n\t\t}\n\t\treturn fingerprints;\n\t}\n\n\t#discardSuppressed(deferred: MonitorEvent[], now: number, settings: MonitorDeliverySettings): void {\n\t\tthis.#events = deferred;\n\t\tthis.#eventChars = deferred.reduce(\n\t\t\t(total, event) => total + `Monitor event(${event.description}): ${eventBody(event)}`.length,\n\t\t\t0,\n\t\t);\n\t\tconst remainingIds = new Set([...deferred.map((event) => event.id), ...this.#overflow.keys()]);\n\t\tif (remainingIds.size > 0) this.#scheduleNextRateLimit(remainingIds, now, settings);\n\t}\n\n\t#buildMessage(\n\t\tevents: readonly MonitorEvent[],\n\t\toverflowCount: number,\n\t\tpauseNotice: string,\n\t\tmaxChars: number,\n\t): string {\n\t\tconst overflowNotice =\n\t\t\toverflowCount > 0\n\t\t\t\t? `[${overflowCount} additional event lines omitted; peek bash_output for full history.]`\n\t\t\t\t: \"\";\n\t\tconst suffix = [overflowNotice, pauseNotice].filter(Boolean).join(\"\\n\");\n\t\tconst fixedChars = SYSTEM_REMINDER_OPEN.length + SYSTEM_REMINDER_CLOSE.length + (suffix ? suffix.length + 1 : 0);\n\t\tconst body = clip(formatEvents(events), Math.max(0, maxChars - fixedChars));\n\t\treturn `${SYSTEM_REMINDER_OPEN}${body}${body && suffix ? \"\\n\" : \"\"}${suffix}${SYSTEM_REMINDER_CLOSE}`;\n\t}\n}\n"]}
|
|
@@ -13,6 +13,10 @@ export interface MonitorSummaryEvent {
|
|
|
13
13
|
}
|
|
14
14
|
export type MonitorEvent = MonitorLineEvent | MonitorSummaryEvent;
|
|
15
15
|
export type MonitorRearmResult = "rearmed" | "not_paused" | "not_found";
|
|
16
|
+
export interface MonitorResumeResult {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly mutedDropped: number;
|
|
19
|
+
}
|
|
16
20
|
export interface MonitorSnapshotEntry {
|
|
17
21
|
readonly id: string;
|
|
18
22
|
readonly description: string;
|
|
@@ -53,7 +57,10 @@ export declare class MonitorRegistry {
|
|
|
53
57
|
stopFile(id: string): Promise<boolean>;
|
|
54
58
|
stopAllFiles(): Promise<number>;
|
|
55
59
|
register(options: RegisterMonitorOptions): void;
|
|
60
|
+
pause(ids: readonly string[]): string[];
|
|
56
61
|
pauseAll(): string[];
|
|
62
|
+
resume(ids?: readonly string[]): MonitorResumeResult[];
|
|
63
|
+
mutedDropped(id: string): number;
|
|
57
64
|
rearm(id: string): MonitorRearmResult;
|
|
58
65
|
dispose(): void;
|
|
59
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGnE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,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IAIhC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB;IAQrC,OAAO,IAAI,IAAI;CA8Hf"}
|
|
@@ -365,6 +365,7 @@ export class MonitorRegistry {
|
|
|
365
365
|
runtime: options.runtime,
|
|
366
366
|
filter: options.filter,
|
|
367
367
|
lineBuffer: "",
|
|
368
|
+
mutedDropped: 0,
|
|
368
369
|
paused: false,
|
|
369
370
|
settled: false,
|
|
370
371
|
unsubscribeOutput: undefined,
|
|
@@ -380,10 +381,11 @@ export class MonitorRegistry {
|
|
|
380
381
|
if (record.runtime.exited)
|
|
381
382
|
this.#settle(record);
|
|
382
383
|
}
|
|
383
|
-
|
|
384
|
+
pause(ids) {
|
|
384
385
|
const paused = [];
|
|
385
|
-
for (const
|
|
386
|
-
|
|
386
|
+
for (const id of ids) {
|
|
387
|
+
const record = this.#records.get(id) ?? this.#files.get(id);
|
|
388
|
+
if (!record || record.paused)
|
|
387
389
|
continue;
|
|
388
390
|
record.paused = true;
|
|
389
391
|
paused.push(record.id);
|
|
@@ -392,16 +394,38 @@ export class MonitorRegistry {
|
|
|
392
394
|
this.#notifyChange();
|
|
393
395
|
return paused;
|
|
394
396
|
}
|
|
397
|
+
pauseAll() {
|
|
398
|
+
return this.pause([...this.#records.keys(), ...this.#files.keys()]);
|
|
399
|
+
}
|
|
400
|
+
resume(ids) {
|
|
401
|
+
const candidates = ids ?? [...this.#records.keys(), ...this.#files.keys()];
|
|
402
|
+
const resumed = [];
|
|
403
|
+
for (const id of candidates) {
|
|
404
|
+
const record = this.#records.get(id) ?? this.#files.get(id);
|
|
405
|
+
if (!record?.paused)
|
|
406
|
+
continue;
|
|
407
|
+
record.paused = false;
|
|
408
|
+
const mutedDropped = "mutedDropped" in record ? record.mutedDropped : 0;
|
|
409
|
+
if ("mutedDropped" in record)
|
|
410
|
+
record.mutedDropped = 0;
|
|
411
|
+
resumed.push({ id: record.id, mutedDropped });
|
|
412
|
+
if ("pendingChange" in record && record.pendingChange)
|
|
413
|
+
void this.#checkFile(record.id);
|
|
414
|
+
}
|
|
415
|
+
if (resumed.length > 0)
|
|
416
|
+
this.#notifyChange();
|
|
417
|
+
return resumed;
|
|
418
|
+
}
|
|
419
|
+
mutedDropped(id) {
|
|
420
|
+
return this.#records.get(id)?.mutedDropped ?? 0;
|
|
421
|
+
}
|
|
395
422
|
rearm(id) {
|
|
396
423
|
const record = this.#records.get(id) ?? this.#files.get(id);
|
|
397
424
|
if (!record)
|
|
398
425
|
return "not_found";
|
|
399
426
|
if (!record.paused)
|
|
400
427
|
return "not_paused";
|
|
401
|
-
|
|
402
|
-
this.#notifyChange();
|
|
403
|
-
if ("pendingChange" in record && record.pendingChange)
|
|
404
|
-
void this.#checkFile(record.id);
|
|
428
|
+
this.resume([id]);
|
|
405
429
|
return "rearmed";
|
|
406
430
|
}
|
|
407
431
|
dispose() {
|
|
@@ -485,8 +509,13 @@ export class MonitorRegistry {
|
|
|
485
509
|
const rawLine = remaining.slice(0, newline);
|
|
486
510
|
remaining = remaining.slice(newline + 1);
|
|
487
511
|
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
488
|
-
|
|
512
|
+
const matchesFilter = !record.filter || record.filter.test(line);
|
|
513
|
+
if (!matchesFilter)
|
|
489
514
|
continue;
|
|
515
|
+
if (record.paused) {
|
|
516
|
+
record.mutedDropped += 1;
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
490
519
|
this.#emit({ type: "line", id: record.id, description: record.description, line });
|
|
491
520
|
}
|
|
492
521
|
record.lineBuffer = remaining;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-registry.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAkB,KAAK,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,MAAM,EAAmB,KAAK,EAAE,IAAI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,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,IAAI,GAAG,CAAC;QACnF,IAAI,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,SAAS;YACf,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,OAAO,EAAE,WAAW,MAAM,GAAG,QAAQ,EAAE;SACvC,CAAC,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,MAAqB;QACnC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC7B,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;IAC5B,CAAC;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { type FSWatcher, watch } from \"node:fs\";\nimport { access, type FileHandle, lstat, open, realpath, stat } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { describeExit } from \"./tools/spawn.ts\";\n\nexport interface MonitorLineEvent {\n\treadonly type: \"line\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly line: string;\n}\n\nexport interface MonitorSummaryEvent {\n\treadonly type: \"summary\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly summary: string;\n}\n\nexport type MonitorEvent = MonitorLineEvent | MonitorSummaryEvent;\n\nexport type MonitorRearmResult = \"rearmed\" | \"not_paused\" | \"not_found\";\n\nexport interface MonitorSnapshotEntry {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly paused: boolean;\n\t/** Epoch milliseconds when the watch registered; feeds the footer's live elapsed label. */\n\treadonly startedAtMs: number;\n}\n\nexport interface MonitorRegistryOptions {\n\t/** Observes every registry transition (register/pause/rearm/settle/dispose) with the live snapshot. */\n\treadonly onChange?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Reserves one shared terminal capacity slot for a native watch. */\n\treadonly reserve?: () => (() => void) | null;\n}\n\nexport interface RegisterFileMonitorOptions {\n\treadonly description: string;\n\treadonly path: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly timeoutMs: number;\n\treadonly cwd: string;\n\treadonly approvedParent?: string;\n}\n\nexport interface RegisterMonitorOptions {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter?: RegExp;\n}\n\ninterface PendingFileRegistration {\n\trelease: (() => void) | undefined;\n\treadonly abort: AbortController;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n\tsettled: boolean;\n}\n\ninterface FileMonitorRecord {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly path: string;\n\treadonly canonicalPath: string;\n\treadonly canonicalParent: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly watcher: FSWatcher;\n\treadonly release: () => void;\n\treadonly poll: ReturnType<typeof setInterval>;\n\tpaused: boolean;\n\tsettled: boolean;\n\tpresent: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdigest: string;\n\tdevice: number;\n\tinode: number;\n\tpendingChange: boolean;\n\tdirty: boolean;\n\tdirtyPasses: number;\n\tdirtyWindowStartedAt: number;\n\tchecking: Promise<void> | undefined;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n}\n\ninterface MonitorRecord {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter: RegExp | undefined;\n\tlineBuffer: string;\n\tpaused: boolean;\n\tsettled: boolean;\n\tunsubscribeOutput: (() => void) | undefined;\n\tunsubscribeExit: (() => void) | undefined;\n}\n\n/**\n * Tracks active monitor sessions alongside the terminal manager's existing bash-id registry.\n * Output is deliberately retained only by TerminalRuntimeSession's bounded history; this\n * registry holds at most one unfinished line for each live monitor.\n */\nexport class MonitorRegistry {\n\treadonly #records = new Map<string, MonitorRecord>();\n\treadonly #emit: (event: MonitorEvent) => void;\n\treadonly #onChange: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #reserve: (() => (() => void) | null) | undefined;\n\treadonly #files = new Map<string, FileMonitorRecord>();\n\t#nextFileId = 1;\n\t#disposed = false;\n\t#pendingRegistrations = 0;\n\treadonly #pending = new Set<PendingFileRegistration>();\n\t#lifecycle = 0;\n\n\tconstructor(emit: (event: MonitorEvent) => void, options?: MonitorRegistryOptions) {\n\t\tthis.#emit = emit;\n\t\tthis.#onChange = options?.onChange;\n\t\tthis.#reserve = options?.reserve;\n\t}\n\n\tsnapshot(): readonly MonitorSnapshotEntry[] {\n\t\treturn [...this.#records.values(), ...this.#files.values()].map((record) => ({\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tpaused: record.paused,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t}));\n\t}\n\n\tasync registerFile(options: RegisterFileMonitorOptions): Promise<string> {\n\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\tthis.#pendingRegistrations += 1;\n\t\tconst lifecycle = this.#lifecycle;\n\t\tconst release = this.#reserve?.();\n\t\tif (this.#reserve && !release) {\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: terminal capacity is already in use.\");\n\t\t}\n\t\tconst pending: PendingFileRegistration = {\n\t\t\trelease: release ?? undefined,\n\t\t\tabort: new AbortController(),\n\t\t\tdeadline: setTimeout(() => pending.abort.abort(), options.timeoutMs),\n\t\t\tsettled: false,\n\t\t};\n\t\tthis.#pending.add(pending);\n\t\tconst path = resolve(options.cwd, options.path);\n\t\tconst parent = dirname(path);\n\t\tlet approvedParent: string;\n\t\ttry {\n\t\t\tawait this.#registrationAwait(pending, access(parent));\n\t\t\tapprovedParent = await this.#registrationAwait(pending, realpath(parent));\n\t\t\tconst approvedParentAtPermission = options.approvedParent;\n\t\t\tif (approvedParentAtPermission !== undefined && approvedParent !== approvedParentAtPermission) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during permission approval: ${parent}`);\n\t\t\t}\n\t\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tif (error instanceof Error && error.message.includes(\"disposed\")) throw error;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot access parent directory ${parent}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(`Cannot watch file: parent directory does not exist: ${parent}`);\n\t\t}\n\t\tlet initial: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet initialHandle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst target = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target is a symbolic link: ${path}`);\n\t\t\tinitialHandle = await this.#registrationAwait(pending, open(path, \"r\"), async (handle) => {\n\t\t\t\tawait handle.close();\n\t\t\t});\n\t\t\tinitial = await this.#registrationAwait(pending, initialHandle.stat());\n\t\t\tif (!initial.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${path}`);\n\t\t\tconst resolvedTarget = await this.#registrationAwait(pending, realpath(path));\n\t\t\tif (resolvedTarget !== join(approvedParent, basename(path)))\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst rebound = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst reboundStat = await this.#registrationAwait(pending, stat(path));\n\t\t\tif (!reboundStat.isFile() || reboundStat.dev !== initial.dev || reboundStat.ino !== initial.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t} catch (error) {\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#finishPending(pending);\n\t\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle || this.#pendingRegistrations < 1) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst id = `watch_${this.#nextFileId++}`;\n\t\tlet watcher: FSWatcher;\n\t\ttry {\n\t\t\tconst activationParent = await this.#registrationAwait(pending, realpath(parent));\n\t\t\tif (activationParent !== approvedParent) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during registration: ${parent}`);\n\t\t\t}\n\t\t\twatcher = watch(activationParent, (_kind, name) => {\n\t\t\t\tif (!name || basename(String(name)) === basename(path)) void this.#checkFile(id);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(`Cannot watch file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tlet registrationError: string | undefined;\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tregistrationError = `watcher error: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tconst record = this.#files.get(id);\n\t\t\tif (record) this.#settleFile(record, registrationError);\n\t\t});\n\t\tlet registrationCleaned = false;\n\t\tconst finishRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\tregistrationCleaned = true;\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t};\n\t\tconst cleanupRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\twatcher.close();\n\t\t\tfinishRegistration();\n\t\t\tthis.#finishPending(pending);\n\t\t};\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst canonicalPath = join(approvedParent, basename(path));\n\t\tlet digest: string;\n\t\ttry {\n\t\t\tdigest =\n\t\t\t\tinitial && initialHandle\n\t\t\t\t\t? await this.#registrationAwait(pending, this.#digestHandle(initialHandle, pending.abort.signal))\n\t\t\t\t\t: \"\";\n\t\t} catch (error) {\n\t\t\tcleanupRegistration();\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif (registrationError) {\n\t\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\t\tthrow new Error(registrationError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait initialHandle?.close();\n\t\tinitialHandle = undefined;\n\t\tif (registrationError) {\n\t\t\tcleanupRegistration();\n\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\tthrow new Error(registrationError);\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst record: FileMonitorRecord = {\n\t\t\tid,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tpath,\n\t\t\tcanonicalPath,\n\t\t\tcanonicalParent: approvedParent,\n\t\t\tevent: options.event,\n\t\t\twatcher,\n\t\t\trelease: release ?? (() => {}),\n\t\t\tpoll: setInterval(() => void this.#checkFile(id), 250),\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tpresent: initial !== null,\n\t\t\tmtimeMs: initial?.mtimeMs ?? 0,\n\t\t\tsize: initial?.size ?? 0,\n\t\t\tdigest,\n\t\t\tdevice: initial?.dev ?? 0,\n\t\t\tinode: initial?.ino ?? 0,\n\t\t\tpendingChange: false,\n\t\t\tdirty: false,\n\t\t\tdirtyPasses: 0,\n\t\t\tdirtyWindowStartedAt: 0,\n\t\t\tchecking: undefined,\n\t\t\tdeadline: setTimeout(() => {\n\t\t\t\tconst current = this.#files.get(id);\n\t\t\t\tif (current) this.#settleFile(current, \"watcher timed_out\");\n\t\t\t}, options.timeoutMs),\n\t\t};\n\t\tthis.#files.set(id, record);\n\t\tfinishRegistration();\n\t\tthis.#finishPending(pending, true);\n\t\tif (registrationError || this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tthis.#settleFile(record, registrationError ?? \"watcher killed\");\n\t\t\tthrow new Error(registrationError ?? \"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tthis.#notifyChange();\n\t\treturn id;\n\t}\n\n\tasync stopFile(id: string): Promise<boolean> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record) return false;\n\t\tthis.#settleFile(record, \"watcher killed\");\n\t\treturn true;\n\t}\n\n\tasync stopAllFiles(): Promise<number> {\n\t\tthis.#lifecycle += 1;\n\t\tconst records = [...this.#files.values()];\n\t\tfor (const record of records) this.#settleFile(record, \"watcher killed\");\n\t\tfor (const pending of [...this.#pending]) this.#finishPending(pending);\n\t\treturn records.length;\n\t}\n\n\t#settleFile(record: FileMonitorRecord, summary: string): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\tclearInterval(record.poll);\n\t\tclearTimeout(record.deadline);\n\t\trecord.watcher.close();\n\t\trecord.release();\n\t\tthis.#files.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tthis.#emit({ type: \"summary\", id: record.id, description: record.description, summary });\n\t}\n\n\tasync #checkFile(id: string): Promise<void> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled) return;\n\t\tif (record.checking) {\n\t\t\trecord.dirty = true;\n\t\t\treturn;\n\t\t}\n\t\trecord.checking = this.#checkFileImpl(record)\n\t\t\t.catch((error) => {\n\t\t\t\tif (!record.settled)\n\t\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\trecord.checking = undefined;\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.dirtyWindowStartedAt >= 1_000) {\n\t\t\t\t\trecord.dirtyWindowStartedAt = now;\n\t\t\t\t\trecord.dirtyPasses = 0;\n\t\t\t\t}\n\t\t\t\tif (record.dirty && !record.settled && record.dirtyPasses < 1) {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t\trecord.dirtyPasses += 1;\n\t\t\t\t\tvoid this.#checkFile(id);\n\t\t\t\t} else {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t}\n\t\t\t});\n\t\treturn record.checking;\n\t}\n\n\tasync #checkFileImpl(record: FileMonitorRecord): Promise<void> {\n\t\tif (record.settled) return;\n\t\tlet current: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet handle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst currentParent = await realpath(dirname(record.path));\n\t\t\tif (currentParent !== record.canonicalParent) {\n\t\t\t\tthis.#settleFile(record, `watcher error: monitored parent changed: ${dirname(record.path)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst target = await lstat(record.canonicalPath);\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst resolvedTarget = await realpath(record.canonicalPath);\n\t\t\tif (resolvedTarget !== record.canonicalPath)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\thandle = await open(record.canonicalPath, \"r\");\n\t\t\tconst opened = await handle.stat();\n\t\t\tif (!opened.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${record.path}`);\n\t\t\tif ((opened.dev !== record.device || opened.ino !== record.inode) && opened.nlink > 1)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tcurrent = opened;\n\t\t\tconst rebound = await lstat(record.canonicalPath);\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst reboundPath = await stat(record.canonicalPath);\n\t\t\tif (!reboundPath.isFile() || reboundPath.dev !== opened.dev || reboundPath.ino !== opened.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t} catch (error) {\n\t\t\tawait handle?.close();\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tconst present = current !== null;\n\t\tlet digest = \"\";\n\t\ttry {\n\t\t\tdigest = present && handle ? await this.#digestHandle(handle) : \"\";\n\t\t\tif (present && handle) {\n\t\t\t\tconst afterDigest = await stat(record.canonicalPath);\n\t\t\t\tconst opened = await handle.stat();\n\t\t\t\tif (afterDigest.dev !== opened.dev || afterDigest.ino !== opened.ino)\n\t\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\t}\n\t\t} finally {\n\t\t\tawait handle?.close();\n\t\t}\n\t\tconst changed =\n\t\t\trecord.event === \"create\"\n\t\t\t\t? !record.present && present\n\t\t\t\t: record.present &&\n\t\t\t\t\tpresent &&\n\t\t\t\t\t(current!.mtimeMs !== record.mtimeMs || current!.size !== record.size || digest !== record.digest);\n\t\trecord.pendingChange ||= changed;\n\t\tif (!record.present && current) {\n\t\t\trecord.device = current.dev;\n\t\t\trecord.inode = current.ino;\n\t\t}\n\t\trecord.present = present;\n\t\trecord.mtimeMs = current?.mtimeMs ?? 0;\n\t\trecord.size = current?.size ?? 0;\n\t\trecord.digest = digest;\n\t\tif (!record.pendingChange || record.paused || record.settled) return;\n\t\trecord.pendingChange = false;\n\t\tif (record.settled) return;\n\t\tthis.#emit({\n\t\t\ttype: \"line\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tline: `${record.event} ${record.path}`,\n\t\t});\n\t\tthis.#settleFile(record, \"watcher completed\");\n\t}\n\n\tregister(options: RegisterMonitorOptions): void {\n\t\tconst record: MonitorRecord = {\n\t\t\tid: options.id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\truntime: options.runtime,\n\t\t\tfilter: options.filter,\n\t\t\tlineBuffer: \"\",\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tunsubscribeOutput: undefined,\n\t\t\tunsubscribeExit: undefined,\n\t\t};\n\t\tthis.#records.set(record.id, record);\n\t\tthis.#notifyChange();\n\n\t\t// Runtime output is already bounded. Read what was produced before monitor registration,\n\t\t// then subscribe synchronously so a fast watcher cannot lose its first line.\n\t\tthis.#consume(record, record.runtime.fullOutput());\n\t\trecord.unsubscribeOutput = record.runtime.onOutput((chunk) => this.#consume(record, chunk));\n\t\trecord.unsubscribeExit = record.runtime.session.onExit(() => this.#settle(record));\n\t\tif (record.runtime.exited) this.#settle(record);\n\t}\n\n\tpauseAll(): string[] {\n\t\tconst paused: string[] = [];\n\t\tfor (const record of [...this.#records.values(), ...this.#files.values()]) {\n\t\t\tif (record.paused) continue;\n\t\t\trecord.paused = true;\n\t\t\tpaused.push(record.id);\n\t\t}\n\t\tif (paused.length > 0) this.#notifyChange();\n\t\treturn paused;\n\t}\n\n\trearm(id: string): MonitorRearmResult {\n\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\tif (!record) return \"not_found\";\n\t\tif (!record.paused) return \"not_paused\";\n\t\trecord.paused = false;\n\t\tthis.#notifyChange();\n\t\tif (\"pendingChange\" in record && record.pendingChange) void this.#checkFile(record.id);\n\t\treturn \"rearmed\";\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\t\tthis.#lifecycle += 1;\n\t\tfor (const record of this.#records.values()) this.#disposeRecord(record);\n\t\tfor (const record of this.#files.values()) this.#settleFile(record, \"watcher disposed\");\n\t\tfor (const pending of this.#pending) this.#finishPending(pending);\n\t\tthis.#records.clear();\n\t\tthis.#notifyChange();\n\t}\n\n\t#finishPending(pending: PendingFileRegistration, transfer = false): void {\n\t\tif (pending.settled) return;\n\t\tpending.settled = true;\n\t\tclearTimeout(pending.deadline);\n\t\tthis.#pending.delete(pending);\n\t\tif (transfer) pending.release = undefined;\n\t\telse {\n\t\t\tpending.abort.abort();\n\t\t\tpending.release?.();\n\t\t}\n\t}\n\n\tasync #registrationAwait<T>(\n\t\tpending: PendingFileRegistration,\n\t\toperation: Promise<T>,\n\t\tlateCleanup?: (value: T) => Promise<void>,\n\t): Promise<T> {\n\t\tif (pending.abort.signal.aborted) {\n\t\t\tvoid operation.then(\n\t\t\t\t(value) => lateCleanup?.(value),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthrow new Error(\"Cannot create file monitor: registration timed out or was disposed.\");\n\t\t}\n\t\tlet aborted = false;\n\t\tconst abort = new Promise<never>((_, reject) =>\n\t\t\tpending.abort.signal.addEventListener(\n\t\t\t\t\"abort\",\n\t\t\t\t() => {\n\t\t\t\t\taborted = true;\n\t\t\t\t\treject(new Error(\"Cannot create file monitor: registration timed out or was disposed.\"));\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t),\n\t\t);\n\t\tconst guarded = operation.then(\n\t\t\t(value) => {\n\t\t\t\tif (aborted) void lateCleanup?.(value);\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(error) => {\n\t\t\t\tif (aborted) return undefined as T;\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn Promise.race([guarded, abort]);\n\t}\n\n\tasync #digestHandle(handle: FileHandle, signal?: AbortSignal): Promise<string> {\n\t\tconst SAMPLE_SIZE = 64 * 1024;\n\t\tif (signal?.aborted) throw new Error(\"file monitor registration cancelled\");\n\t\tconst metadata = await handle.stat();\n\t\tconst hash = createHash(\"sha256\");\n\t\tconst first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));\n\t\tif (first.length > 0) {\n\t\t\tawait handle.read(first, 0, first.length, 0);\n\t\t\thash.update(first);\n\t\t}\n\t\tif (metadata.size > SAMPLE_SIZE) {\n\t\t\tconst middle = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));\n\t\t\thash.update(middle);\n\t\t\tconst last = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(last, 0, last.length, metadata.size - last.length);\n\t\t\thash.update(last);\n\t\t}\n\t\treturn `${metadata.size}:${hash.digest(\"hex\")}`;\n\t}\n\n\t#notifyChange(): void {\n\t\tthis.#onChange?.(this.snapshot());\n\t}\n\n\t#consume(record: MonitorRecord, chunk: string): void {\n\t\tif (record.settled || chunk.length === 0) return;\n\t\tlet remaining = record.lineBuffer + chunk;\n\t\tfor (;;) {\n\t\t\tconst newline = remaining.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst rawLine = remaining.slice(0, newline);\n\t\t\tremaining = remaining.slice(newline + 1);\n\t\t\tconst line = rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine;\n\t\t\tif (record.paused || (record.filter && !record.filter.test(line))) continue;\n\t\t\tthis.#emit({ type: \"line\", id: record.id, description: record.description, line });\n\t\t}\n\t\trecord.lineBuffer = remaining;\n\t}\n\n\t#settle(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tconst status = describeExit(record.runtime) ?? \"exited\";\n\t\tconst code = record.runtime.exitResult?.exitCode;\n\t\tconst codeText = code === null || code === undefined ? \"\" : ` (exit code ${code})`;\n\t\tthis.#emit({\n\t\t\ttype: \"summary\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tsummary: `watcher ${status}${codeText}`,\n\t\t});\n\t}\n\n\t#disposeRecord(record: MonitorRecord): void {\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t}\n}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AAC;QACtB,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC7B,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC;QACxD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC;QACjD,MAAM,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,IAAI,GAAG,CAAC;QACnF,IAAI,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,SAAS;YACf,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,OAAO,EAAE,WAAW,MAAM,GAAG,QAAQ,EAAE;SACvC,CAAC,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,MAAqB;QACnC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC7B,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;IAC5B,CAAC;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { type FSWatcher, watch } from \"node:fs\";\nimport { access, type FileHandle, lstat, open, realpath, stat } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { describeExit } from \"./tools/spawn.ts\";\n\nexport interface MonitorLineEvent {\n\treadonly type: \"line\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly line: string;\n}\n\nexport interface MonitorSummaryEvent {\n\treadonly type: \"summary\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly summary: string;\n}\n\nexport type MonitorEvent = MonitorLineEvent | MonitorSummaryEvent;\n\nexport type MonitorRearmResult = \"rearmed\" | \"not_paused\" | \"not_found\";\n\nexport interface MonitorResumeResult {\n\treadonly id: string;\n\treadonly mutedDropped: number;\n}\n\nexport interface MonitorSnapshotEntry {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly paused: boolean;\n\t/** Epoch milliseconds when the watch registered; feeds the footer's live elapsed label. */\n\treadonly startedAtMs: number;\n}\n\nexport interface MonitorRegistryOptions {\n\t/** Observes every registry transition (register/pause/rearm/settle/dispose) with the live snapshot. */\n\treadonly onChange?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Reserves one shared terminal capacity slot for a native watch. */\n\treadonly reserve?: () => (() => void) | null;\n}\n\nexport interface RegisterFileMonitorOptions {\n\treadonly description: string;\n\treadonly path: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly timeoutMs: number;\n\treadonly cwd: string;\n\treadonly approvedParent?: string;\n}\n\nexport interface RegisterMonitorOptions {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter?: RegExp;\n}\n\ninterface PendingFileRegistration {\n\trelease: (() => void) | undefined;\n\treadonly abort: AbortController;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n\tsettled: boolean;\n}\n\ninterface FileMonitorRecord {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly path: string;\n\treadonly canonicalPath: string;\n\treadonly canonicalParent: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly watcher: FSWatcher;\n\treadonly release: () => void;\n\treadonly poll: ReturnType<typeof setInterval>;\n\tpaused: boolean;\n\tsettled: boolean;\n\tpresent: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdigest: string;\n\tdevice: number;\n\tinode: number;\n\tpendingChange: boolean;\n\tdirty: boolean;\n\tdirtyPasses: number;\n\tdirtyWindowStartedAt: number;\n\tchecking: Promise<void> | undefined;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n}\n\ninterface MonitorRecord {\n\treadonly id: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter: RegExp | undefined;\n\tlineBuffer: string;\n\tmutedDropped: number;\n\tpaused: boolean;\n\tsettled: boolean;\n\tunsubscribeOutput: (() => void) | undefined;\n\tunsubscribeExit: (() => void) | undefined;\n}\n\n/**\n * Tracks active monitor sessions alongside the terminal manager's existing bash-id registry.\n * Output is deliberately retained only by TerminalRuntimeSession's bounded history; this\n * registry holds at most one unfinished line for each live monitor.\n */\nexport class MonitorRegistry {\n\treadonly #records = new Map<string, MonitorRecord>();\n\treadonly #emit: (event: MonitorEvent) => void;\n\treadonly #onChange: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #reserve: (() => (() => void) | null) | undefined;\n\treadonly #files = new Map<string, FileMonitorRecord>();\n\t#nextFileId = 1;\n\t#disposed = false;\n\t#pendingRegistrations = 0;\n\treadonly #pending = new Set<PendingFileRegistration>();\n\t#lifecycle = 0;\n\n\tconstructor(emit: (event: MonitorEvent) => void, options?: MonitorRegistryOptions) {\n\t\tthis.#emit = emit;\n\t\tthis.#onChange = options?.onChange;\n\t\tthis.#reserve = options?.reserve;\n\t}\n\n\tsnapshot(): readonly MonitorSnapshotEntry[] {\n\t\treturn [...this.#records.values(), ...this.#files.values()].map((record) => ({\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tpaused: record.paused,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t}));\n\t}\n\n\tasync registerFile(options: RegisterFileMonitorOptions): Promise<string> {\n\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\tthis.#pendingRegistrations += 1;\n\t\tconst lifecycle = this.#lifecycle;\n\t\tconst release = this.#reserve?.();\n\t\tif (this.#reserve && !release) {\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: terminal capacity is already in use.\");\n\t\t}\n\t\tconst pending: PendingFileRegistration = {\n\t\t\trelease: release ?? undefined,\n\t\t\tabort: new AbortController(),\n\t\t\tdeadline: setTimeout(() => pending.abort.abort(), options.timeoutMs),\n\t\t\tsettled: false,\n\t\t};\n\t\tthis.#pending.add(pending);\n\t\tconst path = resolve(options.cwd, options.path);\n\t\tconst parent = dirname(path);\n\t\tlet approvedParent: string;\n\t\ttry {\n\t\t\tawait this.#registrationAwait(pending, access(parent));\n\t\t\tapprovedParent = await this.#registrationAwait(pending, realpath(parent));\n\t\t\tconst approvedParentAtPermission = options.approvedParent;\n\t\t\tif (approvedParentAtPermission !== undefined && approvedParent !== approvedParentAtPermission) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during permission approval: ${parent}`);\n\t\t\t}\n\t\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tif (error instanceof Error && error.message.includes(\"disposed\")) throw error;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot access parent directory ${parent}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(`Cannot watch file: parent directory does not exist: ${parent}`);\n\t\t}\n\t\tlet initial: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet initialHandle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst target = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target is a symbolic link: ${path}`);\n\t\t\tinitialHandle = await this.#registrationAwait(pending, open(path, \"r\"), async (handle) => {\n\t\t\t\tawait handle.close();\n\t\t\t});\n\t\t\tinitial = await this.#registrationAwait(pending, initialHandle.stat());\n\t\t\tif (!initial.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${path}`);\n\t\t\tconst resolvedTarget = await this.#registrationAwait(pending, realpath(path));\n\t\t\tif (resolvedTarget !== join(approvedParent, basename(path)))\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst rebound = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst reboundStat = await this.#registrationAwait(pending, stat(path));\n\t\t\tif (!reboundStat.isFile() || reboundStat.dev !== initial.dev || reboundStat.ino !== initial.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t} catch (error) {\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#finishPending(pending);\n\t\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle || this.#pendingRegistrations < 1) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst id = `watch_${this.#nextFileId++}`;\n\t\tlet watcher: FSWatcher;\n\t\ttry {\n\t\t\tconst activationParent = await this.#registrationAwait(pending, realpath(parent));\n\t\t\tif (activationParent !== approvedParent) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during registration: ${parent}`);\n\t\t\t}\n\t\t\twatcher = watch(activationParent, (_kind, name) => {\n\t\t\t\tif (!name || basename(String(name)) === basename(path)) void this.#checkFile(id);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(`Cannot watch file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tlet registrationError: string | undefined;\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tregistrationError = `watcher error: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tconst record = this.#files.get(id);\n\t\t\tif (record) this.#settleFile(record, registrationError);\n\t\t});\n\t\tlet registrationCleaned = false;\n\t\tconst finishRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\tregistrationCleaned = true;\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t};\n\t\tconst cleanupRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\twatcher.close();\n\t\t\tfinishRegistration();\n\t\t\tthis.#finishPending(pending);\n\t\t};\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst canonicalPath = join(approvedParent, basename(path));\n\t\tlet digest: string;\n\t\ttry {\n\t\t\tdigest =\n\t\t\t\tinitial && initialHandle\n\t\t\t\t\t? await this.#registrationAwait(pending, this.#digestHandle(initialHandle, pending.abort.signal))\n\t\t\t\t\t: \"\";\n\t\t} catch (error) {\n\t\t\tcleanupRegistration();\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif (registrationError) {\n\t\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\t\tthrow new Error(registrationError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait initialHandle?.close();\n\t\tinitialHandle = undefined;\n\t\tif (registrationError) {\n\t\t\tcleanupRegistration();\n\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\tthrow new Error(registrationError);\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst record: FileMonitorRecord = {\n\t\t\tid,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tpath,\n\t\t\tcanonicalPath,\n\t\t\tcanonicalParent: approvedParent,\n\t\t\tevent: options.event,\n\t\t\twatcher,\n\t\t\trelease: release ?? (() => {}),\n\t\t\tpoll: setInterval(() => void this.#checkFile(id), 250),\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tpresent: initial !== null,\n\t\t\tmtimeMs: initial?.mtimeMs ?? 0,\n\t\t\tsize: initial?.size ?? 0,\n\t\t\tdigest,\n\t\t\tdevice: initial?.dev ?? 0,\n\t\t\tinode: initial?.ino ?? 0,\n\t\t\tpendingChange: false,\n\t\t\tdirty: false,\n\t\t\tdirtyPasses: 0,\n\t\t\tdirtyWindowStartedAt: 0,\n\t\t\tchecking: undefined,\n\t\t\tdeadline: setTimeout(() => {\n\t\t\t\tconst current = this.#files.get(id);\n\t\t\t\tif (current) this.#settleFile(current, \"watcher timed_out\");\n\t\t\t}, options.timeoutMs),\n\t\t};\n\t\tthis.#files.set(id, record);\n\t\tfinishRegistration();\n\t\tthis.#finishPending(pending, true);\n\t\tif (registrationError || this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tthis.#settleFile(record, registrationError ?? \"watcher killed\");\n\t\t\tthrow new Error(registrationError ?? \"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tthis.#notifyChange();\n\t\treturn id;\n\t}\n\n\tasync stopFile(id: string): Promise<boolean> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record) return false;\n\t\tthis.#settleFile(record, \"watcher killed\");\n\t\treturn true;\n\t}\n\n\tasync stopAllFiles(): Promise<number> {\n\t\tthis.#lifecycle += 1;\n\t\tconst records = [...this.#files.values()];\n\t\tfor (const record of records) this.#settleFile(record, \"watcher killed\");\n\t\tfor (const pending of [...this.#pending]) this.#finishPending(pending);\n\t\treturn records.length;\n\t}\n\n\t#settleFile(record: FileMonitorRecord, summary: string): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\tclearInterval(record.poll);\n\t\tclearTimeout(record.deadline);\n\t\trecord.watcher.close();\n\t\trecord.release();\n\t\tthis.#files.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tthis.#emit({ type: \"summary\", id: record.id, description: record.description, summary });\n\t}\n\n\tasync #checkFile(id: string): Promise<void> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled) return;\n\t\tif (record.checking) {\n\t\t\trecord.dirty = true;\n\t\t\treturn;\n\t\t}\n\t\trecord.checking = this.#checkFileImpl(record)\n\t\t\t.catch((error) => {\n\t\t\t\tif (!record.settled)\n\t\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\trecord.checking = undefined;\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.dirtyWindowStartedAt >= 1_000) {\n\t\t\t\t\trecord.dirtyWindowStartedAt = now;\n\t\t\t\t\trecord.dirtyPasses = 0;\n\t\t\t\t}\n\t\t\t\tif (record.dirty && !record.settled && record.dirtyPasses < 1) {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t\trecord.dirtyPasses += 1;\n\t\t\t\t\tvoid this.#checkFile(id);\n\t\t\t\t} else {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t}\n\t\t\t});\n\t\treturn record.checking;\n\t}\n\n\tasync #checkFileImpl(record: FileMonitorRecord): Promise<void> {\n\t\tif (record.settled) return;\n\t\tlet current: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet handle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst currentParent = await realpath(dirname(record.path));\n\t\t\tif (currentParent !== record.canonicalParent) {\n\t\t\t\tthis.#settleFile(record, `watcher error: monitored parent changed: ${dirname(record.path)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst target = await lstat(record.canonicalPath);\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst resolvedTarget = await realpath(record.canonicalPath);\n\t\t\tif (resolvedTarget !== record.canonicalPath)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\thandle = await open(record.canonicalPath, \"r\");\n\t\t\tconst opened = await handle.stat();\n\t\t\tif (!opened.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${record.path}`);\n\t\t\tif ((opened.dev !== record.device || opened.ino !== record.inode) && opened.nlink > 1)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tcurrent = opened;\n\t\t\tconst rebound = await lstat(record.canonicalPath);\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst reboundPath = await stat(record.canonicalPath);\n\t\t\tif (!reboundPath.isFile() || reboundPath.dev !== opened.dev || reboundPath.ino !== opened.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t} catch (error) {\n\t\t\tawait handle?.close();\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tconst present = current !== null;\n\t\tlet digest = \"\";\n\t\ttry {\n\t\t\tdigest = present && handle ? await this.#digestHandle(handle) : \"\";\n\t\t\tif (present && handle) {\n\t\t\t\tconst afterDigest = await stat(record.canonicalPath);\n\t\t\t\tconst opened = await handle.stat();\n\t\t\t\tif (afterDigest.dev !== opened.dev || afterDigest.ino !== opened.ino)\n\t\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\t}\n\t\t} finally {\n\t\t\tawait handle?.close();\n\t\t}\n\t\tconst changed =\n\t\t\trecord.event === \"create\"\n\t\t\t\t? !record.present && present\n\t\t\t\t: record.present &&\n\t\t\t\t\tpresent &&\n\t\t\t\t\t(current!.mtimeMs !== record.mtimeMs || current!.size !== record.size || digest !== record.digest);\n\t\trecord.pendingChange ||= changed;\n\t\tif (!record.present && current) {\n\t\t\trecord.device = current.dev;\n\t\t\trecord.inode = current.ino;\n\t\t}\n\t\trecord.present = present;\n\t\trecord.mtimeMs = current?.mtimeMs ?? 0;\n\t\trecord.size = current?.size ?? 0;\n\t\trecord.digest = digest;\n\t\tif (!record.pendingChange || record.paused || record.settled) return;\n\t\trecord.pendingChange = false;\n\t\tif (record.settled) return;\n\t\tthis.#emit({\n\t\t\ttype: \"line\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tline: `${record.event} ${record.path}`,\n\t\t});\n\t\tthis.#settleFile(record, \"watcher completed\");\n\t}\n\n\tregister(options: RegisterMonitorOptions): void {\n\t\tconst record: MonitorRecord = {\n\t\t\tid: options.id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\truntime: options.runtime,\n\t\t\tfilter: options.filter,\n\t\t\tlineBuffer: \"\",\n\t\t\tmutedDropped: 0,\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tunsubscribeOutput: undefined,\n\t\t\tunsubscribeExit: undefined,\n\t\t};\n\t\tthis.#records.set(record.id, record);\n\t\tthis.#notifyChange();\n\n\t\t// Runtime output is already bounded. Read what was produced before monitor registration,\n\t\t// then subscribe synchronously so a fast watcher cannot lose its first line.\n\t\tthis.#consume(record, record.runtime.fullOutput());\n\t\trecord.unsubscribeOutput = record.runtime.onOutput((chunk) => this.#consume(record, chunk));\n\t\trecord.unsubscribeExit = record.runtime.session.onExit(() => this.#settle(record));\n\t\tif (record.runtime.exited) this.#settle(record);\n\t}\n\n\tpause(ids: readonly string[]): string[] {\n\t\tconst paused: string[] = [];\n\t\tfor (const id of ids) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record || record.paused) continue;\n\t\t\trecord.paused = true;\n\t\t\tpaused.push(record.id);\n\t\t}\n\t\tif (paused.length > 0) this.#notifyChange();\n\t\treturn paused;\n\t}\n\n\tpauseAll(): string[] {\n\t\treturn this.pause([...this.#records.keys(), ...this.#files.keys()]);\n\t}\n\n\tresume(ids?: readonly string[]): MonitorResumeResult[] {\n\t\tconst candidates = ids ?? [...this.#records.keys(), ...this.#files.keys()];\n\t\tconst resumed: MonitorResumeResult[] = [];\n\t\tfor (const id of candidates) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record?.paused) continue;\n\t\t\trecord.paused = false;\n\t\t\tconst mutedDropped = \"mutedDropped\" in record ? record.mutedDropped : 0;\n\t\t\tif (\"mutedDropped\" in record) record.mutedDropped = 0;\n\t\t\tresumed.push({ id: record.id, mutedDropped });\n\t\t\tif (\"pendingChange\" in record && record.pendingChange) void this.#checkFile(record.id);\n\t\t}\n\t\tif (resumed.length > 0) this.#notifyChange();\n\t\treturn resumed;\n\t}\n\n\tmutedDropped(id: string): number {\n\t\treturn this.#records.get(id)?.mutedDropped ?? 0;\n\t}\n\n\trearm(id: string): MonitorRearmResult {\n\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\tif (!record) return \"not_found\";\n\t\tif (!record.paused) return \"not_paused\";\n\t\tthis.resume([id]);\n\t\treturn \"rearmed\";\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\t\tthis.#lifecycle += 1;\n\t\tfor (const record of this.#records.values()) this.#disposeRecord(record);\n\t\tfor (const record of this.#files.values()) this.#settleFile(record, \"watcher disposed\");\n\t\tfor (const pending of this.#pending) this.#finishPending(pending);\n\t\tthis.#records.clear();\n\t\tthis.#notifyChange();\n\t}\n\n\t#finishPending(pending: PendingFileRegistration, transfer = false): void {\n\t\tif (pending.settled) return;\n\t\tpending.settled = true;\n\t\tclearTimeout(pending.deadline);\n\t\tthis.#pending.delete(pending);\n\t\tif (transfer) pending.release = undefined;\n\t\telse {\n\t\t\tpending.abort.abort();\n\t\t\tpending.release?.();\n\t\t}\n\t}\n\n\tasync #registrationAwait<T>(\n\t\tpending: PendingFileRegistration,\n\t\toperation: Promise<T>,\n\t\tlateCleanup?: (value: T) => Promise<void>,\n\t): Promise<T> {\n\t\tif (pending.abort.signal.aborted) {\n\t\t\tvoid operation.then(\n\t\t\t\t(value) => lateCleanup?.(value),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthrow new Error(\"Cannot create file monitor: registration timed out or was disposed.\");\n\t\t}\n\t\tlet aborted = false;\n\t\tconst abort = new Promise<never>((_, reject) =>\n\t\t\tpending.abort.signal.addEventListener(\n\t\t\t\t\"abort\",\n\t\t\t\t() => {\n\t\t\t\t\taborted = true;\n\t\t\t\t\treject(new Error(\"Cannot create file monitor: registration timed out or was disposed.\"));\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t),\n\t\t);\n\t\tconst guarded = operation.then(\n\t\t\t(value) => {\n\t\t\t\tif (aborted) void lateCleanup?.(value);\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(error) => {\n\t\t\t\tif (aborted) return undefined as T;\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn Promise.race([guarded, abort]);\n\t}\n\n\tasync #digestHandle(handle: FileHandle, signal?: AbortSignal): Promise<string> {\n\t\tconst SAMPLE_SIZE = 64 * 1024;\n\t\tif (signal?.aborted) throw new Error(\"file monitor registration cancelled\");\n\t\tconst metadata = await handle.stat();\n\t\tconst hash = createHash(\"sha256\");\n\t\tconst first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));\n\t\tif (first.length > 0) {\n\t\t\tawait handle.read(first, 0, first.length, 0);\n\t\t\thash.update(first);\n\t\t}\n\t\tif (metadata.size > SAMPLE_SIZE) {\n\t\t\tconst middle = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));\n\t\t\thash.update(middle);\n\t\t\tconst last = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(last, 0, last.length, metadata.size - last.length);\n\t\t\thash.update(last);\n\t\t}\n\t\treturn `${metadata.size}:${hash.digest(\"hex\")}`;\n\t}\n\n\t#notifyChange(): void {\n\t\tthis.#onChange?.(this.snapshot());\n\t}\n\n\t#consume(record: MonitorRecord, chunk: string): void {\n\t\tif (record.settled || chunk.length === 0) return;\n\t\tlet remaining = record.lineBuffer + chunk;\n\t\tfor (;;) {\n\t\t\tconst newline = remaining.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst rawLine = remaining.slice(0, newline);\n\t\t\tremaining = remaining.slice(newline + 1);\n\t\t\tconst line = rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine;\n\t\t\tconst matchesFilter = !record.filter || record.filter.test(line);\n\t\t\tif (!matchesFilter) continue;\n\t\t\tif (record.paused) {\n\t\t\t\trecord.mutedDropped += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#emit({ type: \"line\", id: record.id, description: record.description, line });\n\t\t}\n\t\trecord.lineBuffer = remaining;\n\t}\n\n\t#settle(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tconst status = describeExit(record.runtime) ?? \"exited\";\n\t\tconst code = record.runtime.exitResult?.exitCode;\n\t\tconst codeText = code === null || code === undefined ? \"\" : ` (exit code ${code})`;\n\t\tthis.#emit({\n\t\t\ttype: \"summary\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tsummary: `watcher ${status}${codeText}`,\n\t\t});\n\t}\n\n\t#disposeRecord(record: MonitorRecord): void {\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t}\n}\n"]}
|
|
@@ -60,7 +60,7 @@ export function formatMonitorStatus(snapshot, nowMs) {
|
|
|
60
60
|
if (snapshot.length === 0)
|
|
61
61
|
return undefined;
|
|
62
62
|
const pausedCount = snapshot.filter((entry) => entry.paused).length;
|
|
63
|
-
const pausedPart = pausedCount === 0 ? "" : pausedCount === snapshot.length ? ",
|
|
63
|
+
const pausedPart = pausedCount === 0 ? "" : pausedCount === snapshot.length ? ", muted" : `, ${pausedCount} muted`;
|
|
64
64
|
const suffix = ` (${formatElapsedSeconds(monitorElapsedSeconds(snapshot, nowMs))}${pausedPart})`;
|
|
65
65
|
if (snapshot.length === 1) {
|
|
66
66
|
const head = `${WATCH_GLYPH} watching `;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-status.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-status.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAE7C,gFAAgF;AAChF,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,gGAAgG;AAChG,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,SAAS,WAAW,CAAC,IAAY,EAAE,GAAW;IAC7C,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAAwB,EAAE,MAAc;IACjE,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;QACjD,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;QACxC,MAAM,IAAI,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,WAAW,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,MAA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,MAAM,CAAC;AACjG,CAAC","sourcesContent":["import type { MonitorSnapshotEntry } from \"./monitor-registry.ts\";\n\nexport const MONITOR_STATUS_KEY = \"monitors\";\n\n/** The footer shares one status line with other extensions; keep this brief. */\nconst MAX_STATUS_LENGTH = 48;\n/** Marks the status as a live watch at a glance (same glyph family as the session selector). */\nconst WATCH_GLYPH = \"◉\";\n\nfunction truncateEnd(text: string, max: number): string {\n\tif (text.length <= max) return text;\n\treturn `${text.slice(0, Math.max(0, max - 1))}…`;\n}\n\n/**\n * Fits as many whole descriptions as possible into the budget, folding the rest\n * into a `+N more` counter so the monitor count is never truncated away.\n */\nfunction packDescriptions(names: readonly string[], budget: number): string {\n\tfor (let kept = names.length; kept >= 1; kept--) {\n\t\tconst hiddenCount = names.length - kept;\n\t\tconst tail = hiddenCount > 0 ? ` +${hiddenCount} more` : \"\";\n\t\tconst joined = names.slice(0, kept).join(\", \");\n\t\tif (joined.length + tail.length <= budget) return joined + tail;\n\t}\n\tconst tail = names.length > 1 ? ` +${names.length - 1} more` : \"\";\n\treturn truncateEnd(names[0] ?? \"\", Math.max(1, budget - tail.length)) + tail;\n}\n\n/**\n * Goal-style compact elapsed label (`5s`, `3m`, `2h 30m`, `1d 2h 3m`). Mirrors\n * `formatGoalElapsedSeconds` in the goal builtin; kept local so this builtin stays\n * self-contained, matching the existing monitor/eval status-file duplication.\n */\nexport function formatElapsedSeconds(value: number): string {\n\tconst seconds = Math.max(0, Math.trunc(value));\n\tif (seconds < 60) return `${seconds}s`;\n\tconst minutes = Math.trunc(seconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\tconst hours = Math.trunc(minutes / 60);\n\tconst remainingMinutes = minutes % 60;\n\tif (hours >= 24) {\n\t\tconst days = Math.trunc(hours / 24);\n\t\tconst remainingHours = hours % 24;\n\t\treturn `${days}d ${remainingHours}h ${remainingMinutes}m`;\n\t}\n\tif (remainingMinutes === 0) return `${hours}h`;\n\treturn `${hours}h ${remainingMinutes}m`;\n}\n\n/** Whole seconds since the oldest watch registered; never negative when the clock moves backwards. */\nexport function monitorElapsedSeconds(snapshot: readonly MonitorSnapshotEntry[], nowMs: number): number {\n\tlet oldest = Number.POSITIVE_INFINITY;\n\tfor (const entry of snapshot) oldest = Math.min(oldest, entry.startedAtMs);\n\tif (!Number.isFinite(oldest)) return 0;\n\treturn Math.max(0, Math.round((nowMs - oldest) / 1000));\n}\n\n/** Brief footer text for the active monitors; undefined clears the status. */\nexport function formatMonitorStatus(snapshot: readonly MonitorSnapshotEntry[], nowMs: number): string | undefined {\n\tif (snapshot.length === 0) return undefined;\n\tconst pausedCount = snapshot.filter((entry) => entry.paused).length;\n\tconst pausedPart = pausedCount === 0 ? \"\" : pausedCount === snapshot.length ? \", muted\" : `, ${pausedCount} muted`;\n\tconst suffix = ` (${formatElapsedSeconds(monitorElapsedSeconds(snapshot, nowMs))}${pausedPart})`;\n\tif (snapshot.length === 1) {\n\t\tconst head = `${WATCH_GLYPH} watching `;\n\t\tconst description = truncateEnd(snapshot[0]?.description ?? \"\", MAX_STATUS_LENGTH - head.length - suffix.length);\n\t\treturn head + description + suffix;\n\t}\n\tconst head = `${WATCH_GLYPH} watching ${snapshot.length}: `;\n\tconst names = snapshot.map((entry) => entry.description);\n\treturn head + packDescriptions(names, MAX_STATUS_LENGTH - head.length - suffix.length) + suffix;\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** System-prompt guidance for the persistent-terminal tool suite (CC-close, snake_case). */
|
|
2
|
-
export declare const TERMINAL_PROMPT_SECTION = "\n## Persistent terminal sessions\n\nThe `bash` tool is PTY-backed. For long-running or interactive work, do NOT use tmux or\nmanual `&` backgrounding \u2014 use the built-in session tools:\n\n- `bash({ command, run_in_background: true })` starts a persistent session and returns a\n `bash_id` immediately. Foreground calls still block and return output; their `timeout`\n (seconds) is a kill deadline. Background sessions ignore `timeout` and live until they\n exit or you call `kill_bash`.\n- `bash_output({ bash_id, filter, view })` peeks at a session without blocking: new output\n since the last read, the status line, or a rendered full-screen snapshot of TUIs via\n `view: \"screen\"`. Completion arrives as a notification carrying the exit code and output\n tail \u2014 peeking is for steering, never for waiting.\n- `monitor({ description, command, filter?, timeout_ms?, persistent? })`
|
|
2
|
+
export declare const TERMINAL_PROMPT_SECTION = "\n## Persistent terminal sessions\n\nThe `bash` tool is PTY-backed. For long-running or interactive work, do NOT use tmux or\nmanual `&` backgrounding \u2014 use the built-in session tools:\n\n- `bash({ command, run_in_background: true })` starts a persistent session and returns a\n `bash_id` immediately. Foreground calls still block and return output; their `timeout`\n (seconds) is a kill deadline. Background sessions ignore `timeout` and live until they\n exit or you call `kill_bash`.\n- `bash_output({ bash_id, filter, view })` peeks at a session without blocking: new output\n since the last read, the status line, or a rendered full-screen snapshot of TUIs via\n `view: \"screen\"`. Completion arrives as a notification carrying the exit code and output\n tail \u2014 peeking is for steering, never for waiting.\n- `monitor` subscribes you to a change. Pass `command` XOR `path` \u2014 one branch per call,\n never both:\n - `monitor({ description, command, filter?, timeout_ms?, persistent? })` watches a command:\n newline-terminated PTY output lines (stderr included) matching `filter` arrive as injected\n events while you keep working; command exit always delivers a summary. One-shot gate: wait\n inside the command and print one sentinel (`until <cond>; do sleep 1; done;\n printf 'READY\\n'`). Stream: `tail -n 0 -F | grep --line-buffered`. Filter noise at the\n source and stop with `kill_bash`.\n - `monitor({ description, path, event? })` natively watches one regular file and fires once \u2014\n prefer it over a shell poll loop. `\"create\"` (the default) fires only when the file appears\n after registration, so watch an already-existing file with `\"modify\"`; registration needs the\n parent directory to exist already, so poll with a `command` when the run creates that\n directory too. This branch takes no `filter` and no `persistent`.\n Identical updates are deduped; repeated monitor-only wakes pause the noisy monitor(s) that\n caused them, not all monitors. Completion still wakes the session, and\n `monitor({ action: \"rearm\", bash_id })` resumes one while `monitor({ action: \"rearm\" })`\n resumes all paused monitors; real user input also resumes paused monitors.\n- `bash_input({ bash_id, input, keys, submit })` sends stdin or named keys (e.g.\n `[\"ctrl+c\"]`, `[\"enter\"]`) to steer a REPL or interrupt a process.\n- `bash_resize({ bash_id, cols, rows })` resizes the PTY so full-screen programs reflow.\n- `kill_bash({ bash_id })` (or `{ all: true }`) tears the session tree down with no orphans.\n";
|
|
3
3
|
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/prompt.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/prompt.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,eAAO,MAAM,uBAAuB,8hFAmCnC,CAAC"}
|
|
@@ -13,22 +13,26 @@ manual \`&\` backgrounding — use the built-in session tools:
|
|
|
13
13
|
since the last read, the status line, or a rendered full-screen snapshot of TUIs via
|
|
14
14
|
\`view: "screen"\`. Completion arrives as a notification carrying the exit code and output
|
|
15
15
|
tail — peeking is for steering, never for waiting.
|
|
16
|
-
- \`monitor
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
- \`monitor\` subscribes you to a change. Pass \`command\` XOR \`path\` — one branch per call,
|
|
17
|
+
never both:
|
|
18
|
+
- \`monitor({ description, command, filter?, timeout_ms?, persistent? })\` watches a command:
|
|
19
|
+
newline-terminated PTY output lines (stderr included) matching \`filter\` arrive as injected
|
|
20
|
+
events while you keep working; command exit always delivers a summary. One-shot gate: wait
|
|
21
|
+
inside the command and print one sentinel (\`until <cond>; do sleep 1; done;
|
|
22
|
+
printf 'READY\\n'\`). Stream: \`tail -n 0 -F | grep --line-buffered\`. Filter noise at the
|
|
23
|
+
source and stop with \`kill_bash\`.
|
|
24
|
+
- \`monitor({ description, path, event? })\` natively watches one regular file and fires once —
|
|
25
|
+
prefer it over a shell poll loop. \`"create"\` (the default) fires only when the file appears
|
|
26
|
+
after registration, so watch an already-existing file with \`"modify"\`; registration needs the
|
|
27
|
+
parent directory to exist already, so poll with a \`command\` when the run creates that
|
|
28
|
+
directory too. This branch takes no \`filter\` and no \`persistent\`.
|
|
29
|
+
Identical updates are deduped; repeated monitor-only wakes pause the noisy monitor(s) that
|
|
30
|
+
caused them, not all monitors. Completion still wakes the session, and
|
|
31
|
+
\`monitor({ action: "rearm", bash_id })\` resumes one while \`monitor({ action: "rearm" })\`
|
|
32
|
+
resumes all paused monitors; real user input also resumes paused monitors.
|
|
24
33
|
- \`bash_input({ bash_id, input, keys, submit })\` sends stdin or named keys (e.g.
|
|
25
34
|
\`["ctrl+c"]\`, \`["enter"]\`) to steer a REPL or interrupt a process.
|
|
26
35
|
- \`bash_resize({ bash_id, cols, rows })\` resizes the PTY so full-screen programs reflow.
|
|
27
36
|
- \`kill_bash({ bash_id })\` (or \`{ all: true }\`) tears the session tree down with no orphans.
|
|
28
|
-
|
|
29
|
-
Typical flow: start with \`run_in_background: true\`, watch for patterns with
|
|
30
|
-
\`monitor({ command, filter })\`, peek with \`bash_output\`, steer with \`bash_input\`, then
|
|
31
|
-
\`kill_bash\` when done. Completion notifications carry the exit code and output tail, so a
|
|
32
|
-
follow-up read is only needed when the tail is not enough.
|
|
33
37
|
`;
|
|
34
38
|
//# sourceMappingURL=prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/prompt.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,uBAAuB,GAAG
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/prompt.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCtC,CAAC","sourcesContent":["/** System-prompt guidance for the persistent-terminal tool suite (CC-close, snake_case). */\nexport const TERMINAL_PROMPT_SECTION = `\n## Persistent terminal sessions\n\nThe \\`bash\\` tool is PTY-backed. For long-running or interactive work, do NOT use tmux or\nmanual \\`&\\` backgrounding — use the built-in session tools:\n\n- \\`bash({ command, run_in_background: true })\\` starts a persistent session and returns a\n \\`bash_id\\` immediately. Foreground calls still block and return output; their \\`timeout\\`\n (seconds) is a kill deadline. Background sessions ignore \\`timeout\\` and live until they\n exit or you call \\`kill_bash\\`.\n- \\`bash_output({ bash_id, filter, view })\\` peeks at a session without blocking: new output\n since the last read, the status line, or a rendered full-screen snapshot of TUIs via\n \\`view: \"screen\"\\`. Completion arrives as a notification carrying the exit code and output\n tail — peeking is for steering, never for waiting.\n- \\`monitor\\` subscribes you to a change. Pass \\`command\\` XOR \\`path\\` — one branch per call,\n never both:\n - \\`monitor({ description, command, filter?, timeout_ms?, persistent? })\\` watches a command:\n newline-terminated PTY output lines (stderr included) matching \\`filter\\` arrive as injected\n events while you keep working; command exit always delivers a summary. One-shot gate: wait\n inside the command and print one sentinel (\\`until <cond>; do sleep 1; done;\n printf 'READY\\\\n'\\`). Stream: \\`tail -n 0 -F | grep --line-buffered\\`. Filter noise at the\n source and stop with \\`kill_bash\\`.\n - \\`monitor({ description, path, event? })\\` natively watches one regular file and fires once —\n prefer it over a shell poll loop. \\`\"create\"\\` (the default) fires only when the file appears\n after registration, so watch an already-existing file with \\`\"modify\"\\`; registration needs the\n parent directory to exist already, so poll with a \\`command\\` when the run creates that\n directory too. This branch takes no \\`filter\\` and no \\`persistent\\`.\n Identical updates are deduped; repeated monitor-only wakes pause the noisy monitor(s) that\n caused them, not all monitors. Completion still wakes the session, and\n \\`monitor({ action: \"rearm\", bash_id })\\` resumes one while \\`monitor({ action: \"rearm\" })\\`\n resumes all paused monitors; real user input also resumes paused monitors.\n- \\`bash_input({ bash_id, input, keys, submit })\\` sends stdin or named keys (e.g.\n \\`[\"ctrl+c\"]\\`, \\`[\"enter\"]\\`) to steer a REPL or interrupt a process.\n- \\`bash_resize({ bash_id, cols, rows })\\` resizes the PTY so full-screen programs reflow.\n- \\`kill_bash({ bash_id })\\` (or \\`{ all: true }\\`) tears the session tree down with no orphans.\n`;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-output.d.ts","sourceRoot":"","sources":["../../../../../../src/core/extensions/builtin/terminal/tools/bash-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAe,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAC1G,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG3E,eAAO,MAAM,gBAAgB;;;;EAQ3B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAwB9D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB;;;;;;;;;;yBAShC,MAAM,SAAS,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;;;
|
|
1
|
+
{"version":3,"file":"bash-output.d.ts","sourceRoot":"","sources":["../../../../../../src/core/extensions/builtin/terminal/tools/bash-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAe,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAC1G,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG3E,eAAO,MAAM,gBAAgB;;;;EAQ3B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAwB9D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB;;;;;;;;;;yBAShC,MAAM,SAAS,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;;;EA6BxF"}
|