@code-yeongyu/senpi 2026.9.15 → 2026.9.16
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 +46 -0
- package/dist/core/extensions/builtin/config-reload/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/index.js +25 -8
- package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts +4 -5
- package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-engine.js +14 -18
- package/dist/core/extensions/builtin/config-reload/watch-engine.js.map +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 +32 -9
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts +23 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js +48 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts +13 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js +24 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js +7 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts +2 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/index.js +11 -9
- package/dist/core/extensions/builtin/cursor-cli-oauth/index.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts +18 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js +61 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js.map +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts +4 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.js +1 -44
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts +22 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/transport.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js +2 -13
- package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts +3 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-digest.js +25 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-digest.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts +9 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-watch.js +33 -0
- package/dist/core/extensions/builtin/terminal/monitor-file-watch.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts +6 -0
- package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js +22 -0
- package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +14 -35
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/kernel-tools-context.d.ts +13 -0
- package/dist/core/extensions/kernel-tools-context.d.ts.map +1 -0
- package/dist/core/extensions/kernel-tools-context.js +3 -0
- package/dist/core/extensions/kernel-tools-context.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +19 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +103 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +21 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +9 -17
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +14 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +23 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +41 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +4 -3
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/read.d.ts +3 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +16 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +3 -3
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
- package/dist/modes/rpc/host-watchdog.js +5 -24
- package/dist/modes/rpc/host-watchdog.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +3 -8
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +3 -0
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-worker-client.d.ts +3 -0
- package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
- package/dist/modes/rpc/session-worker-client.js +17 -6
- package/dist/modes/rpc/session-worker-client.js.map +1 -1
- package/dist/modes/rpc/shutdown.d.ts +3 -0
- package/dist/modes/rpc/shutdown.d.ts.map +1 -0
- package/dist/modes/rpc/shutdown.js +17 -0
- package/dist/modes/rpc/shutdown.js.map +1 -0
- package/docs/extensions.md +3 -0
- package/docs/settings.md +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +36 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +24 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/http-server.ts +7 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/kernel-tools-protocol.ts +85 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +6 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +30 -11
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +11 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +10 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +46 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/runner.jl +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +58 -10
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.d.ts +13 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.js +7 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.d.ts +10 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.js +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.js +22 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.ts +26 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-host.ts +134 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-naming.js +28 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.d.ts +5 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.js +255 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-pump.js +105 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.d.ts +27 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.js +127 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-schema.js +69 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-types.ts +42 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +26 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +20 -8
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-slot.ts +6 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-startup.ts +9 -7
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/workpool.js +37 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/kernel-tools-unavailable.ts +5 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +13 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +57 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +13 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/workpool.rb +38 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +13 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +9 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +4 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-handler.ts +8 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +36 -71
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image-resize.ts +52 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +37 -72
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/managed-cell.ts +78 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +30 -5
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/run-eval-cell.ts +49 -30
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/terminal-snapshot-store.ts +35 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/tool-result-marshal.ts +23 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +51 -12
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +18 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts +4 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js +268 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts +18 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js +69 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts +27 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js +118 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts +21 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js +24 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts +12 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js +92 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts +47 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js +8 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts +52 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js +155 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.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/alibaba-token-plan.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.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/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.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/empty-response-errors.d.ts +15 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js +15 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +10 -0
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { cursorAgentEnvironment } from "./environment.js";
|
|
2
3
|
import { defaultCursorAgentExecutableDeps, resolveCursorAgentExecutable, } from "./executable.js";
|
|
3
4
|
import { buildCursorCliArgs } from "./spawn-args.js";
|
|
4
5
|
import { CursorCliStreamParser } from "./stream-parser.js";
|
|
@@ -68,18 +69,6 @@ class AsyncEventQueue {
|
|
|
68
69
|
waiter.reject(error);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
function explicitEnvironment(accountHome) {
|
|
72
|
-
const env = {
|
|
73
|
-
HOME: accountHome,
|
|
74
|
-
AGENT_CLI_CREDENTIAL_STORE: "file",
|
|
75
|
-
};
|
|
76
|
-
for (const name of ["PATH", "TERM", "LANG", "LC_ALL", "FORCE_COLOR"]) {
|
|
77
|
-
const value = process.env[name];
|
|
78
|
-
if (value !== undefined)
|
|
79
|
-
env[name] = value;
|
|
80
|
-
}
|
|
81
|
-
return env;
|
|
82
|
-
}
|
|
83
72
|
function killProcessGroup(child, signal) {
|
|
84
73
|
const pid = child.pid;
|
|
85
74
|
if (pid === undefined)
|
|
@@ -114,7 +103,7 @@ export function spawnCursorCli(input) {
|
|
|
114
103
|
const child = spawn(executable, buildCursorCliArgs(input), {
|
|
115
104
|
cwd: input.cwd,
|
|
116
105
|
detached: true,
|
|
117
|
-
env:
|
|
106
|
+
env: cursorAgentEnvironment(input.accountHome),
|
|
118
107
|
stdio: ["ignore", "pipe", "pipe"],
|
|
119
108
|
windowsHide: true,
|
|
120
109
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAEN,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAA2B,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAA6B,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEtF,8EAA8E;AAC9E,2EAA2E;AAC3E,gDAAgD;AAChD,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAC/C,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAKtD,YAAY,WAAmB,EAAE,UAAU,GAAG,2BA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,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import { type ChildProcessByStdio, spawn } from \"node:child_process\";\nimport type { Readable } from \"node:stream\";\nimport {\n\ttype CursorAgentExecutableDeps,\n\tdefaultCursorAgentExecutableDeps,\n\tresolveCursorAgentExecutable,\n} from \"./executable.ts\";\nimport { buildCursorCliArgs, type CursorCliArgsInput } from \"./spawn-args.ts\";\nimport { type CursorCliStreamEvent, CursorCliStreamParser } from \"./stream-parser.ts\";\n\n// The prompt rides as ONE argv element, so Linux MAX_ARG_STRLEN (131072 bytes\n// per single argv string) is the binding constraint on every platform; the\n// ~467 KB darwin probe ceiling is not portable.\nexport const MAX_CURSOR_CLI_PROMPT_BYTES = 130_000;\nexport const CURSOR_CLI_ABORT_GRACE_MS = 5_000;\nconst MAX_STDERR_BYTES = 64 * 1024;\n\nexport class CursorCliPromptTooLargeError extends Error {\n\treadonly kind = \"context_overflow\";\n\treadonly limitBytes: number;\n\treadonly actualBytes: number;\n\n\tconstructor(actualBytes: number, limitBytes = MAX_CURSOR_CLI_PROMPT_BYTES) {\n\t\tsuper(`Cursor CLI prompt is ${actualBytes} bytes; the limit is ${limitBytes} bytes`);\n\t\tthis.name = \"CursorCliPromptTooLargeError\";\n\t\tthis.actualBytes = actualBytes;\n\t\tthis.limitBytes = limitBytes;\n\t}\n}\n\nexport class CursorCliAbortError extends Error {\n\treadonly type = \"aborted\";\n\treadonly kind = \"aborted\";\n\n\tconstructor() {\n\t\tsuper(\"Cursor CLI invocation aborted\");\n\t\tthis.name = \"CursorCliAbortError\";\n\t}\n}\n\nexport type CursorCliTransportEvent = CursorCliStreamEvent | CursorCliAbortError;\n\nexport type CursorCliTransportCompletedOutcome = {\n\treadonly type: \"completed\";\n\treadonly exitCode: number | null;\n\treadonly signal: NodeJS.Signals | null;\n\treadonly stderr: string;\n};\n\nexport type CursorCliTransportAbortedOutcome = {\n\treadonly type: \"aborted\";\n\treadonly error: CursorCliAbortError;\n};\n\nexport type CursorCliTransportOutcome = CursorCliTransportCompletedOutcome | CursorCliTransportAbortedOutcome;\n\nexport type CursorCliTransportInput = CursorCliArgsInput & {\n\treadonly accountHome: string;\n\treadonly cwd: string;\n\treadonly signal?: AbortSignal;\n\treadonly executableDeps?: CursorAgentExecutableDeps;\n};\n\nexport type CursorCliTransportHandle = {\n\treadonly pid: number;\n\treadonly events: AsyncIterable<CursorCliTransportEvent>;\n\treadonly completed: Promise<CursorCliTransportOutcome>;\n\tabort(): void;\n};\n\ntype QueueWaiter<T> = {\n\tresolve(result: IteratorResult<T>): void;\n\treject(error: unknown): void;\n};\n\nclass AsyncEventQueue<T> implements AsyncIterableIterator<T> {\n\tprivate readonly values: T[] = [];\n\tprivate readonly waiters: QueueWaiter<T>[] = [];\n\tprivate ended = false;\n\tprivate failure: unknown;\n\n\t[Symbol.asyncIterator](): AsyncIterableIterator<T> {\n\t\treturn this;\n\t}\n\n\tnext(): Promise<IteratorResult<T>> {\n\t\tconst value = this.values.shift();\n\t\tif (value !== undefined) return Promise.resolve({ done: false, value });\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tif (this.ended) return Promise.resolve({ done: true, value: undefined });\n\t\treturn new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));\n\t}\n\n\tpush(value: T): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tconst waiter = this.waiters.shift();\n\t\tif (waiter) waiter.resolve({ done: false, value });\n\t\telse this.values.push(value);\n\t}\n\n\tclose(): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.ended = true;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter.resolve({ done: true, value: undefined });\n\t}\n\n\tfail(error: unknown): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.failure = error;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter.reject(error);\n\t}\n}\n\nfunction explicitEnvironment(accountHome: string): NodeJS.ProcessEnv {\n\tconst env: NodeJS.ProcessEnv = {\n\t\tHOME: accountHome,\n\t\tAGENT_CLI_CREDENTIAL_STORE: \"file\",\n\t};\n\tfor (const name of [\"PATH\", \"TERM\", \"LANG\", \"LC_ALL\", \"FORCE_COLOR\"] as const) {\n\t\tconst value = process.env[name];\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn env;\n}\n\nfunction killProcessGroup(child: ChildProcessByStdio<null, Readable, Readable>, signal: NodeJS.Signals): void {\n\tconst pid = child.pid;\n\tif (pid === undefined) return;\n\ttry {\n\t\tif (process.platform === \"win32\") child.kill(signal);\n\t\telse process.kill(-pid, signal);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n\t}\n}\n\nfunction appendBoundedStderr(current: Uint8Array, chunk: Uint8Array): Uint8Array {\n\tif (chunk.byteLength >= MAX_STDERR_BYTES) return chunk.subarray(chunk.byteLength - MAX_STDERR_BYTES);\n\tconst combined = Buffer.concat([current, chunk]);\n\treturn combined.byteLength <= MAX_STDERR_BYTES\n\t\t? combined\n\t\t: combined.subarray(combined.byteLength - MAX_STDERR_BYTES);\n}\n\n/** Spawn one cursor-agent print-mode invocation with strict environment and process-group ownership. */\nexport function spawnCursorCli(input: CursorCliTransportInput): CursorCliTransportHandle {\n\tconst promptBytes = Buffer.byteLength(input.prompt, \"utf8\");\n\tif (promptBytes > MAX_CURSOR_CLI_PROMPT_BYTES) throw new CursorCliPromptTooLargeError(promptBytes);\n\tif (input.signal?.aborted) throw new CursorCliAbortError();\n\n\tconst executable = resolveCursorAgentExecutable(input.executableDeps ?? defaultCursorAgentExecutableDeps());\n\tconst child = spawn(executable, buildCursorCliArgs(input), {\n\t\tcwd: input.cwd,\n\t\tdetached: true,\n\t\tenv: explicitEnvironment(input.accountHome),\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\twindowsHide: true,\n\t});\n\tif (child.pid === undefined) {\n\t\tchild.kill(\"SIGKILL\");\n\t\tthrow new Error(\"cursor-agent spawned without a process id\");\n\t}\n\n\tconst pid = child.pid;\n\tconst parser = new CursorCliStreamParser();\n\tconst events = new AsyncEventQueue<CursorCliTransportEvent>();\n\tlet stderr: Uint8Array = Buffer.alloc(0);\n\tlet abortRequested = false;\n\tlet abortTimer: NodeJS.Timeout | undefined;\n\tlet removeAbortListener = (): void => {};\n\tlet resolveCompleted: (outcome: CursorCliTransportOutcome) => void = () => {};\n\tlet rejectCompleted: (error: unknown) => void = () => {};\n\tconst completed = new Promise<CursorCliTransportOutcome>((resolve, reject) => {\n\t\tresolveCompleted = resolve;\n\t\trejectCompleted = reject;\n\t});\n\n\tconst abort = (): void => {\n\t\tif (abortRequested || child.exitCode !== null || child.signalCode !== null) return;\n\t\tabortRequested = true;\n\t\ttry {\n\t\t\tkillProcessGroup(child, \"SIGTERM\");\n\t\t} catch (error) {\n\t\t\tevents.fail(error);\n\t\t\trejectCompleted(error);\n\t\t\treturn;\n\t\t}\n\t\tabortTimer = setTimeout(() => {\n\t\t\ttry {\n\t\t\t\tkillProcessGroup(child, \"SIGKILL\");\n\t\t\t} catch (error) {\n\t\t\t\tevents.fail(error);\n\t\t\t\trejectCompleted(error);\n\t\t\t}\n\t\t}, CURSOR_CLI_ABORT_GRACE_MS);\n\t};\n\n\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\tfor (const event of parser.push(chunk)) events.push(event);\n\t});\n\tchild.stderr.on(\"data\", (chunk: Buffer) => {\n\t\tstderr = appendBoundedStderr(stderr, chunk);\n\t});\n\tchild.once(\"error\", (error) => {\n\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\tremoveAbortListener();\n\t\tevents.fail(error);\n\t\trejectCompleted(error);\n\t});\n\tchild.once(\"close\", (exitCode, signal) => {\n\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\tremoveAbortListener();\n\t\tif (abortRequested) {\n\t\t\tconst error = new CursorCliAbortError();\n\t\t\tevents.push(error);\n\t\t\tevents.close();\n\t\t\tresolveCompleted({ type: \"aborted\", error });\n\t\t\treturn;\n\t\t}\n\t\tfor (const event of parser.finish()) events.push(event);\n\t\tevents.close();\n\t\tresolveCompleted({ type: \"completed\", exitCode, signal, stderr: Buffer.from(stderr).toString(\"utf8\") });\n\t});\n\n\tif (input.signal) {\n\t\tinput.signal.addEventListener(\"abort\", abort, { once: true });\n\t\tremoveAbortListener = () => input.signal?.removeEventListener(\"abort\", abort);\n\t}\n\n\treturn { pid, events, completed, abort };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAEN,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAA2B,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAA6B,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEtF,8EAA8E;AAC9E,2EAA2E;AAC3E,gDAAgD;AAChD,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAC/C,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAKtD,YAAY,WAAmB,EAAE,UAAU,GAAG,2BAA2B;QACxE,KAAK,CAAC,wBAAwB,WAAW,wBAAwB,UAAU,QAAQ,CAAC,CAAC;QAL7E,SAAI,GAAG,kBAAkB,CAAC;QAMlC,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED,MAAM,O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CAAC,KAAK,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,gBAAgB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9D,mBAAmB,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import { type ChildProcessByStdio, spawn } from \"node:child_process\";\nimport type { Readable } from \"node:stream\";\nimport { cursorAgentEnvironment } from \"./environment.ts\";\nimport {\n\ttype CursorAgentExecutableDeps,\n\tdefaultCursorAgentExecutableDeps,\n\tresolveCursorAgentExecutable,\n} from \"./executable.ts\";\nimport { buildCursorCliArgs, type CursorCliArgsInput } from \"./spawn-args.ts\";\nimport { type CursorCliStreamEvent, CursorCliStreamParser } from \"./stream-parser.ts\";\n\n// The prompt rides as ONE argv element, so Linux MAX_ARG_STRLEN (131072 bytes\n// per single argv string) is the binding constraint on every platform; the\n// ~467 KB darwin probe ceiling is not portable.\nexport const MAX_CURSOR_CLI_PROMPT_BYTES = 130_000;\nexport const CURSOR_CLI_ABORT_GRACE_MS = 5_000;\nconst MAX_STDERR_BYTES = 64 * 1024;\n\nexport class CursorCliPromptTooLargeError extends Error {\n\treadonly kind = \"context_overflow\";\n\treadonly limitBytes: number;\n\treadonly actualBytes: number;\n\n\tconstructor(actualBytes: number, limitBytes = MAX_CURSOR_CLI_PROMPT_BYTES) {\n\t\tsuper(`Cursor CLI prompt is ${actualBytes} bytes; the limit is ${limitBytes} bytes`);\n\t\tthis.name = \"CursorCliPromptTooLargeError\";\n\t\tthis.actualBytes = actualBytes;\n\t\tthis.limitBytes = limitBytes;\n\t}\n}\n\nexport class CursorCliAbortError extends Error {\n\treadonly type = \"aborted\";\n\treadonly kind = \"aborted\";\n\n\tconstructor() {\n\t\tsuper(\"Cursor CLI invocation aborted\");\n\t\tthis.name = \"CursorCliAbortError\";\n\t}\n}\n\nexport type CursorCliTransportEvent = CursorCliStreamEvent | CursorCliAbortError;\n\nexport type CursorCliTransportCompletedOutcome = {\n\treadonly type: \"completed\";\n\treadonly exitCode: number | null;\n\treadonly signal: NodeJS.Signals | null;\n\treadonly stderr: string;\n};\n\nexport type CursorCliTransportAbortedOutcome = {\n\treadonly type: \"aborted\";\n\treadonly error: CursorCliAbortError;\n};\n\nexport type CursorCliTransportOutcome = CursorCliTransportCompletedOutcome | CursorCliTransportAbortedOutcome;\n\nexport type CursorCliTransportInput = CursorCliArgsInput & {\n\treadonly accountHome: string;\n\treadonly cwd: string;\n\treadonly signal?: AbortSignal;\n\treadonly executableDeps?: CursorAgentExecutableDeps;\n};\n\nexport type CursorCliTransportHandle = {\n\treadonly pid: number;\n\treadonly events: AsyncIterable<CursorCliTransportEvent>;\n\treadonly completed: Promise<CursorCliTransportOutcome>;\n\tabort(): void;\n};\n\ntype QueueWaiter<T> = {\n\tresolve(result: IteratorResult<T>): void;\n\treject(error: unknown): void;\n};\n\nclass AsyncEventQueue<T> implements AsyncIterableIterator<T> {\n\tprivate readonly values: T[] = [];\n\tprivate readonly waiters: QueueWaiter<T>[] = [];\n\tprivate ended = false;\n\tprivate failure: unknown;\n\n\t[Symbol.asyncIterator](): AsyncIterableIterator<T> {\n\t\treturn this;\n\t}\n\n\tnext(): Promise<IteratorResult<T>> {\n\t\tconst value = this.values.shift();\n\t\tif (value !== undefined) return Promise.resolve({ done: false, value });\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tif (this.ended) return Promise.resolve({ done: true, value: undefined });\n\t\treturn new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));\n\t}\n\n\tpush(value: T): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tconst waiter = this.waiters.shift();\n\t\tif (waiter) waiter.resolve({ done: false, value });\n\t\telse this.values.push(value);\n\t}\n\n\tclose(): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.ended = true;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter.resolve({ done: true, value: undefined });\n\t}\n\n\tfail(error: unknown): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.failure = error;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter.reject(error);\n\t}\n}\n\nfunction killProcessGroup(child: ChildProcessByStdio<null, Readable, Readable>, signal: NodeJS.Signals): void {\n\tconst pid = child.pid;\n\tif (pid === undefined) return;\n\ttry {\n\t\tif (process.platform === \"win32\") child.kill(signal);\n\t\telse process.kill(-pid, signal);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n\t}\n}\n\nfunction appendBoundedStderr(current: Uint8Array, chunk: Uint8Array): Uint8Array {\n\tif (chunk.byteLength >= MAX_STDERR_BYTES) return chunk.subarray(chunk.byteLength - MAX_STDERR_BYTES);\n\tconst combined = Buffer.concat([current, chunk]);\n\treturn combined.byteLength <= MAX_STDERR_BYTES\n\t\t? combined\n\t\t: combined.subarray(combined.byteLength - MAX_STDERR_BYTES);\n}\n\n/** Spawn one cursor-agent print-mode invocation with strict environment and process-group ownership. */\nexport function spawnCursorCli(input: CursorCliTransportInput): CursorCliTransportHandle {\n\tconst promptBytes = Buffer.byteLength(input.prompt, \"utf8\");\n\tif (promptBytes > MAX_CURSOR_CLI_PROMPT_BYTES) throw new CursorCliPromptTooLargeError(promptBytes);\n\tif (input.signal?.aborted) throw new CursorCliAbortError();\n\n\tconst executable = resolveCursorAgentExecutable(input.executableDeps ?? defaultCursorAgentExecutableDeps());\n\tconst child = spawn(executable, buildCursorCliArgs(input), {\n\t\tcwd: input.cwd,\n\t\tdetached: true,\n\t\tenv: cursorAgentEnvironment(input.accountHome),\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\twindowsHide: true,\n\t});\n\tif (child.pid === undefined) {\n\t\tchild.kill(\"SIGKILL\");\n\t\tthrow new Error(\"cursor-agent spawned without a process id\");\n\t}\n\n\tconst pid = child.pid;\n\tconst parser = new CursorCliStreamParser();\n\tconst events = new AsyncEventQueue<CursorCliTransportEvent>();\n\tlet stderr: Uint8Array = Buffer.alloc(0);\n\tlet abortRequested = false;\n\tlet abortTimer: NodeJS.Timeout | undefined;\n\tlet removeAbortListener = (): void => {};\n\tlet resolveCompleted: (outcome: CursorCliTransportOutcome) => void = () => {};\n\tlet rejectCompleted: (error: unknown) => void = () => {};\n\tconst completed = new Promise<CursorCliTransportOutcome>((resolve, reject) => {\n\t\tresolveCompleted = resolve;\n\t\trejectCompleted = reject;\n\t});\n\n\tconst abort = (): void => {\n\t\tif (abortRequested || child.exitCode !== null || child.signalCode !== null) return;\n\t\tabortRequested = true;\n\t\ttry {\n\t\t\tkillProcessGroup(child, \"SIGTERM\");\n\t\t} catch (error) {\n\t\t\tevents.fail(error);\n\t\t\trejectCompleted(error);\n\t\t\treturn;\n\t\t}\n\t\tabortTimer = setTimeout(() => {\n\t\t\ttry {\n\t\t\t\tkillProcessGroup(child, \"SIGKILL\");\n\t\t\t} catch (error) {\n\t\t\t\tevents.fail(error);\n\t\t\t\trejectCompleted(error);\n\t\t\t}\n\t\t}, CURSOR_CLI_ABORT_GRACE_MS);\n\t};\n\n\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\tfor (const event of parser.push(chunk)) events.push(event);\n\t});\n\tchild.stderr.on(\"data\", (chunk: Buffer) => {\n\t\tstderr = appendBoundedStderr(stderr, chunk);\n\t});\n\tchild.once(\"error\", (error) => {\n\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\tremoveAbortListener();\n\t\tevents.fail(error);\n\t\trejectCompleted(error);\n\t});\n\tchild.once(\"close\", (exitCode, signal) => {\n\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\tremoveAbortListener();\n\t\tif (abortRequested) {\n\t\t\tconst error = new CursorCliAbortError();\n\t\t\tevents.push(error);\n\t\t\tevents.close();\n\t\t\tresolveCompleted({ type: \"aborted\", error });\n\t\t\treturn;\n\t\t}\n\t\tfor (const event of parser.finish()) events.push(event);\n\t\tevents.close();\n\t\tresolveCompleted({ type: \"completed\", exitCode, signal, stderr: Buffer.from(stderr).toString(\"utf8\") });\n\t});\n\n\tif (input.signal) {\n\t\tinput.signal.addEventListener(\"abort\", abort, { once: true });\n\t\tremoveAbortListener = () => input.signal?.removeEventListener(\"abort\", abort);\n\t}\n\n\treturn { pid, events, completed, abort };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-file-digest.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-file-digest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBhG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
// Identity digest over first/middle/last 64 KiB samples plus size: cheap enough to run per
|
|
3
|
+
// poll tick on large files while still catching content replacements that preserve mtime.
|
|
4
|
+
export async function digestFileHandle(handle, signal) {
|
|
5
|
+
const SAMPLE_SIZE = 64 * 1024;
|
|
6
|
+
if (signal?.aborted)
|
|
7
|
+
throw new Error("file monitor registration cancelled");
|
|
8
|
+
const metadata = await handle.stat();
|
|
9
|
+
const hash = createHash("sha256");
|
|
10
|
+
const first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));
|
|
11
|
+
if (first.length > 0) {
|
|
12
|
+
await handle.read(first, 0, first.length, 0);
|
|
13
|
+
hash.update(first);
|
|
14
|
+
}
|
|
15
|
+
if (metadata.size > SAMPLE_SIZE) {
|
|
16
|
+
const middle = Buffer.alloc(SAMPLE_SIZE);
|
|
17
|
+
await handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));
|
|
18
|
+
hash.update(middle);
|
|
19
|
+
const last = Buffer.alloc(SAMPLE_SIZE);
|
|
20
|
+
await handle.read(last, 0, last.length, metadata.size - last.length);
|
|
21
|
+
hash.update(last);
|
|
22
|
+
}
|
|
23
|
+
return `${metadata.size}:${hash.digest("hex")}`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=monitor-file-digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-file-digest.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-file-digest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,2FAA2F;AAC3F,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAkB,EAAE,MAAoB;IAC9E,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC;IAC9B,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,GAAG,WAAW,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACzC,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { FileHandle } from \"node:fs/promises\";\n\n// Identity digest over first/middle/last 64 KiB samples plus size: cheap enough to run per\n// poll tick on large files while still catching content replacements that preserve mtime.\nexport async function digestFileHandle(handle: FileHandle, signal?: AbortSignal): Promise<string> {\n\tconst SAMPLE_SIZE = 64 * 1024;\n\tif (signal?.aborted) throw new Error(\"file monitor registration cancelled\");\n\tconst metadata = await handle.stat();\n\tconst hash = createHash(\"sha256\");\n\tconst first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));\n\tif (first.length > 0) {\n\t\tawait handle.read(first, 0, first.length, 0);\n\t\thash.update(first);\n\t}\n\tif (metadata.size > SAMPLE_SIZE) {\n\t\tconst middle = Buffer.alloc(SAMPLE_SIZE);\n\t\tawait handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));\n\t\thash.update(middle);\n\t\tconst last = Buffer.alloc(SAMPLE_SIZE);\n\t\tawait handle.read(last, 0, last.length, metadata.size - last.length);\n\t\thash.update(last);\n\t}\n\treturn `${metadata.size}:${hash.digest(\"hex\")}`;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-file-watch.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-file-watch.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,qBAAa,aAAa;;IAKzB,YAAY,KAAK,EAAE,MAAM,IAAI,EAG5B;IAED,KAAK,IAAI,IAAI,CAIZ;IAED,MAAM,IAAI,IAAI,CAIb;IAED,IAAI,IAAI,IAAI,CAGX;CAKD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// fs.watch misses events under rename-heavy writers, so file monitors poll. A paused watch
|
|
2
|
+
// clears its timer entirely (zero wakeups, zero stat/digest work) and resume() runs one
|
|
3
|
+
// immediate check, so a change made during the pause is still detected and fired.
|
|
4
|
+
export const FILE_MONITOR_POLL_MS = 250;
|
|
5
|
+
export class FileWatchLoop {
|
|
6
|
+
#check;
|
|
7
|
+
#timer;
|
|
8
|
+
#stopped = false;
|
|
9
|
+
constructor(check) {
|
|
10
|
+
this.#check = check;
|
|
11
|
+
this.#start();
|
|
12
|
+
}
|
|
13
|
+
pause() {
|
|
14
|
+
if (this.#timer === undefined)
|
|
15
|
+
return;
|
|
16
|
+
clearInterval(this.#timer);
|
|
17
|
+
this.#timer = undefined;
|
|
18
|
+
}
|
|
19
|
+
resume() {
|
|
20
|
+
if (this.#stopped || this.#timer !== undefined)
|
|
21
|
+
return;
|
|
22
|
+
this.#start();
|
|
23
|
+
this.#check();
|
|
24
|
+
}
|
|
25
|
+
stop() {
|
|
26
|
+
this.#stopped = true;
|
|
27
|
+
this.pause();
|
|
28
|
+
}
|
|
29
|
+
#start() {
|
|
30
|
+
this.#timer = setInterval(this.#check, FILE_MONITOR_POLL_MS);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=monitor-file-watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-file-watch.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-file-watch.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,wFAAwF;AACxF,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,MAAM,OAAO,aAAa;IAChB,MAAM,CAAa;IAC5B,MAAM,CAA6C;IACnD,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAY,KAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACtC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACvD,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IAED,IAAI;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC;IAED,MAAM;QACL,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC9D,CAAC;CACD","sourcesContent":["// fs.watch misses events under rename-heavy writers, so file monitors poll. A paused watch\n// clears its timer entirely (zero wakeups, zero stat/digest work) and resume() runs one\n// immediate check, so a change made during the pause is still detected and fired.\nexport const FILE_MONITOR_POLL_MS = 250;\n\nexport class FileWatchLoop {\n\treadonly #check: () => void;\n\t#timer: ReturnType<typeof setInterval> | undefined;\n\t#stopped = false;\n\n\tconstructor(check: () => void) {\n\t\tthis.#check = check;\n\t\tthis.#start();\n\t}\n\n\tpause(): void {\n\t\tif (this.#timer === undefined) return;\n\t\tclearInterval(this.#timer);\n\t\tthis.#timer = undefined;\n\t}\n\n\tresume(): void {\n\t\tif (this.#stopped || this.#timer !== undefined) return;\n\t\tthis.#start();\n\t\tthis.#check();\n\t}\n\n\tstop(): void {\n\t\tthis.#stopped = true;\n\t\tthis.pause();\n\t}\n\n\t#start(): void {\n\t\tthis.#timer = setInterval(this.#check, FILE_MONITOR_POLL_MS);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-line-buffer.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-line-buffer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD,qBAAa,iBAAiB;;IAG7B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAa9B;CACD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// A newline-less stream must not grow the retained tail without bound; an over-cap line is
|
|
2
|
+
// truncated to its last MONITOR_LINE_BUFFER_MAX_CHARS characters.
|
|
3
|
+
export const MONITOR_LINE_BUFFER_MAX_CHARS = 65_536;
|
|
4
|
+
export class MonitorLineBuffer {
|
|
5
|
+
#tail = "";
|
|
6
|
+
append(chunk) {
|
|
7
|
+
let remaining = this.#tail + chunk;
|
|
8
|
+
const lines = [];
|
|
9
|
+
for (;;) {
|
|
10
|
+
const newline = remaining.indexOf("\n");
|
|
11
|
+
if (newline < 0)
|
|
12
|
+
break;
|
|
13
|
+
const rawLine = remaining.slice(0, newline);
|
|
14
|
+
remaining = remaining.slice(newline + 1);
|
|
15
|
+
lines.push(rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine);
|
|
16
|
+
}
|
|
17
|
+
this.#tail =
|
|
18
|
+
remaining.length > MONITOR_LINE_BUFFER_MAX_CHARS ? remaining.slice(-MONITOR_LINE_BUFFER_MAX_CHARS) : remaining;
|
|
19
|
+
return lines;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=monitor-line-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-line-buffer.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-line-buffer.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,kEAAkE;AAClE,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEpD,MAAM,OAAO,iBAAiB;IAC7B,KAAK,GAAG,EAAE,CAAC;IAEX,MAAM,CAAC,KAAa;QACnB,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,SAAS,CAAC;YACT,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,OAAO,GAAG,CAAC;gBAAE,MAAM;YACvB,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC5C,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,KAAK;YACT,SAAS,CAAC,MAAM,GAAG,6BAA6B,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChH,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["// A newline-less stream must not grow the retained tail without bound; an over-cap line is\n// truncated to its last MONITOR_LINE_BUFFER_MAX_CHARS characters.\nexport const MONITOR_LINE_BUFFER_MAX_CHARS = 65_536;\n\nexport class MonitorLineBuffer {\n\t#tail = \"\";\n\n\tappend(chunk: string): string[] {\n\t\tlet remaining = this.#tail + chunk;\n\t\tconst lines: string[] = [];\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\tlines.push(rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine);\n\t\t}\n\t\tthis.#tail =\n\t\t\tremaining.length > MONITOR_LINE_BUFFER_MAX_CHARS ? remaining.slice(-MONITOR_LINE_BUFFER_MAX_CHARS) : remaining;\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,yBAAyB,IAAI,iBAAiB,EAC9C,0BAA0B,IAAI,kBAAkB,EAChD,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,yBAAyB,IAAI,iBAAiB,E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AC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CA8LlG;IAED,6FAA6F;IAC7F,cAAc,CAAC,EAAE,EAAE,MAAM;;;;;;;kBAKxB;IAED,sGAAsG;IACtG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK9C;IAEK,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK3C;IAEK,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAMpC;IA8HD,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAkChD;IAED,KAAK,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAWtC;IAED,QAAQ,IAAI,MAAM,EAAE,CAEnB;IAED,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAgBrD;IAED,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/B;IAED,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAMpC;IAED,+GAA+G;IAC/G,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAOzE;IAED,OAAO,IAAI,IAAI,CAQd;CAsID"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { watch } from "node:fs";
|
|
3
3
|
import { access, lstat, open, stat } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { canonicalWatchPath, probeDirectoryOpenable } from "../../../../utils/fs-watch.js";
|
|
6
6
|
import { realpathWithoutOpen } from "../../../../utils/paths.js";
|
|
7
|
+
import { digestFileHandle } from "./monitor-file-digest.js";
|
|
8
|
+
import { FileWatchLoop } from "./monitor-file-watch.js";
|
|
9
|
+
import { MonitorLineBuffer } from "./monitor-line-buffer.js";
|
|
7
10
|
import { DEFAULT_DURABLE_MONITOR_FIRE_BUDGET, FIRE_BUDGET_AUTO_MUTE_SUMMARY, FIRE_BUDGET_WINDOW_MS } from "./shared.js";
|
|
8
11
|
import { describeExit } from "./tools/spawn.js";
|
|
9
12
|
const MONITOR_ID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -237,7 +240,7 @@ export class MonitorRegistry {
|
|
|
237
240
|
event: options.event,
|
|
238
241
|
watcher,
|
|
239
242
|
release: release ?? (() => { }),
|
|
240
|
-
|
|
243
|
+
watch: new FileWatchLoop(() => void this.#checkFile(id)),
|
|
241
244
|
paused: false,
|
|
242
245
|
settled: false,
|
|
243
246
|
present: initial !== null,
|
|
@@ -300,7 +303,7 @@ export class MonitorRegistry {
|
|
|
300
303
|
if (record.settled)
|
|
301
304
|
return;
|
|
302
305
|
record.settled = true;
|
|
303
|
-
|
|
306
|
+
record.watch.stop();
|
|
304
307
|
clearTimeout(record.deadline);
|
|
305
308
|
record.watcher.close();
|
|
306
309
|
record.release();
|
|
@@ -318,7 +321,7 @@ export class MonitorRegistry {
|
|
|
318
321
|
}
|
|
319
322
|
async #checkFile(id) {
|
|
320
323
|
const record = this.#files.get(id);
|
|
321
|
-
if (!record || record.settled)
|
|
324
|
+
if (!record || record.settled || record.paused)
|
|
322
325
|
return;
|
|
323
326
|
if (record.checking) {
|
|
324
327
|
record.dirty = true;
|
|
@@ -442,7 +445,7 @@ export class MonitorRegistry {
|
|
|
442
445
|
expiresAt: options.expiresAt,
|
|
443
446
|
runtime: options.runtime,
|
|
444
447
|
filter: options.filter,
|
|
445
|
-
lineBuffer:
|
|
448
|
+
lineBuffer: new MonitorLineBuffer(),
|
|
446
449
|
mutedDropped: 0,
|
|
447
450
|
paused: false,
|
|
448
451
|
settled: false,
|
|
@@ -468,6 +471,8 @@ export class MonitorRegistry {
|
|
|
468
471
|
if (!record || record.paused)
|
|
469
472
|
continue;
|
|
470
473
|
record.paused = true;
|
|
474
|
+
if ("watch" in record)
|
|
475
|
+
record.watch.pause();
|
|
471
476
|
paused.push(record.id);
|
|
472
477
|
}
|
|
473
478
|
if (paused.length > 0)
|
|
@@ -492,8 +497,8 @@ export class MonitorRegistry {
|
|
|
492
497
|
if ("fireWindow" in record && record.fireWindow !== undefined)
|
|
493
498
|
record.fireWindow.count = 0;
|
|
494
499
|
resumed.push({ id: record.id, mutedDropped });
|
|
495
|
-
if ("
|
|
496
|
-
|
|
500
|
+
if ("watch" in record)
|
|
501
|
+
record.watch.resume();
|
|
497
502
|
}
|
|
498
503
|
if (resumed.length > 0)
|
|
499
504
|
this.#notifyChange();
|
|
@@ -568,25 +573,7 @@ export class MonitorRegistry {
|
|
|
568
573
|
return Promise.race([guarded, abort]);
|
|
569
574
|
}
|
|
570
575
|
async #digestHandle(handle, signal) {
|
|
571
|
-
|
|
572
|
-
if (signal?.aborted)
|
|
573
|
-
throw new Error("file monitor registration cancelled");
|
|
574
|
-
const metadata = await handle.stat();
|
|
575
|
-
const hash = createHash("sha256");
|
|
576
|
-
const first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));
|
|
577
|
-
if (first.length > 0) {
|
|
578
|
-
await handle.read(first, 0, first.length, 0);
|
|
579
|
-
hash.update(first);
|
|
580
|
-
}
|
|
581
|
-
if (metadata.size > SAMPLE_SIZE) {
|
|
582
|
-
const middle = Buffer.alloc(SAMPLE_SIZE);
|
|
583
|
-
await handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));
|
|
584
|
-
hash.update(middle);
|
|
585
|
-
const last = Buffer.alloc(SAMPLE_SIZE);
|
|
586
|
-
await handle.read(last, 0, last.length, metadata.size - last.length);
|
|
587
|
-
hash.update(last);
|
|
588
|
-
}
|
|
589
|
-
return `${metadata.size}:${hash.digest("hex")}`;
|
|
576
|
+
return digestFileHandle(handle, signal);
|
|
590
577
|
}
|
|
591
578
|
#notifyChange() {
|
|
592
579
|
this.#onChange?.(this.snapshot());
|
|
@@ -594,14 +581,7 @@ export class MonitorRegistry {
|
|
|
594
581
|
#consume(record, chunk) {
|
|
595
582
|
if (record.settled || chunk.length === 0)
|
|
596
583
|
return;
|
|
597
|
-
|
|
598
|
-
for (;;) {
|
|
599
|
-
const newline = remaining.indexOf("\n");
|
|
600
|
-
if (newline < 0)
|
|
601
|
-
break;
|
|
602
|
-
const rawLine = remaining.slice(0, newline);
|
|
603
|
-
remaining = remaining.slice(newline + 1);
|
|
604
|
-
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
584
|
+
for (const line of record.lineBuffer.append(chunk)) {
|
|
605
585
|
const matchesFilter = !record.filter || record.filter.test(line);
|
|
606
586
|
if (!matchesFilter)
|
|
607
587
|
continue;
|
|
@@ -627,7 +607,6 @@ export class MonitorRegistry {
|
|
|
627
607
|
}
|
|
628
608
|
}
|
|
629
609
|
}
|
|
630
|
-
record.lineBuffer = remaining;
|
|
631
610
|
}
|
|
632
611
|
#settle(record) {
|
|
633
612
|
if (record.settled)
|