innocode 1.0.0 → 1.0.229
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/LICENSE +21 -0
- package/package.json +17 -118
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -18
- package/README.md +0 -15
- package/bunfig.toml +0 -5
- package/parsers-config.ts +0 -253
- package/script/build.ts +0 -198
- package/script/publish.ts +0 -186
- package/script/schema.ts +0 -47
- package/script/seed-e2e.ts +0 -50
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -1676
- package/src/acp/session.ts +0 -117
- package/src/acp/types.ts +0 -23
- package/src/agent/agent.ts +0 -338
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -14
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -44
- package/src/auth/index.ts +0 -70
- package/src/bun/index.ts +0 -137
- package/src/bun/registry.ts +0 -48
- package/src/bus/bus-event.ts +0 -43
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -105
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -70
- package/src/cli/cmd/agent.ts +0 -257
- package/src/cli/cmd/auth.ts +0 -400
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/agent.ts +0 -167
- package/src/cli/cmd/debug/config.ts +0 -16
- package/src/cli/cmd/debug/file.ts +0 -97
- package/src/cli/cmd/debug/index.ts +0 -48
- package/src/cli/cmd/debug/lsp.ts +0 -52
- package/src/cli/cmd/debug/ripgrep.ts +0 -87
- package/src/cli/cmd/debug/scrap.ts +0 -16
- package/src/cli/cmd/debug/skill.ts +0 -16
- package/src/cli/cmd/debug/snapshot.ts +0 -52
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -1540
- package/src/cli/cmd/import.ts +0 -147
- package/src/cli/cmd/mcp.ts +0 -765
- package/src/cli/cmd/models.ts +0 -77
- package/src/cli/cmd/pr.ts +0 -113
- package/src/cli/cmd/run.ts +0 -598
- package/src/cli/cmd/serve.ts +0 -20
- package/src/cli/cmd/session.ts +0 -135
- package/src/cli/cmd/stats.ts +0 -426
- package/src/cli/cmd/tui/app.tsx +0 -812
- package/src/cli/cmd/tui/attach.ts +0 -60
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -165
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -243
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -108
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-skill.tsx +0 -36
- package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -167
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/logo.tsx +0 -85
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -666
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1153
- package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
- package/src/cli/cmd/tui/component/spinner.tsx +0 -24
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
- package/src/cli/cmd/tui/component/tips.tsx +0 -153
- package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
- package/src/cli/cmd/tui/context/args.tsx +0 -15
- package/src/cli/cmd/tui/context/directory.ts +0 -13
- package/src/cli/cmd/tui/context/exit.tsx +0 -54
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -100
- package/src/cli/cmd/tui/context/kv.tsx +0 -52
- package/src/cli/cmd/tui/context/local.tsx +0 -409
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -46
- package/src/cli/cmd/tui/context/sdk.tsx +0 -101
- package/src/cli/cmd/tui/context/sync.tsx +0 -470
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -242
- package/src/cli/cmd/tui/context/theme/innocode.json +0 -245
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -249
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1154
- package/src/cli/cmd/tui/event.ts +0 -48
- package/src/cli/cmd/tui/routes/home.tsx +0 -145
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -135
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -2139
- package/src/cli/cmd/tui/routes/session/permission.tsx +0 -508
- package/src/cli/cmd/tui/routes/session/question.tsx +0 -466
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -313
- package/src/cli/cmd/tui/thread.ts +0 -188
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -59
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -85
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -207
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -40
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -80
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -401
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
- package/src/cli/cmd/tui/ui/link.tsx +0 -28
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -159
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/signal.ts +0 -7
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/util/transcript.ts +0 -98
- package/src/cli/cmd/tui/win32.ts +0 -129
- package/src/cli/cmd/tui/worker.ts +0 -152
- package/src/cli/cmd/uninstall.ts +0 -363
- package/src/cli/cmd/upgrade.ts +0 -73
- package/src/cli/cmd/web.ts +0 -81
- package/src/cli/error.ts +0 -57
- package/src/cli/logo.ts +0 -6
- package/src/cli/network.ts +0 -60
- package/src/cli/ui.ts +0 -113
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -150
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -101
- package/src/config/config.ts +0 -1517
- package/src/config/markdown.ts +0 -98
- package/src/env/index.ts +0 -28
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -583
- package/src/file/ripgrep.ts +0 -375
- package/src/file/time.ts +0 -69
- package/src/file/watcher.ts +0 -127
- package/src/flag/flag.ts +0 -148
- package/src/format/formatter.ts +0 -366
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -80
- package/src/id/id.ts +0 -83
- package/src/ide/index.ts +0 -76
- package/src/index.ts +0 -160
- package/src/installation/index.ts +0 -268
- package/src/lsp/client.ts +0 -252
- package/src/lsp/index.ts +0 -485
- package/src/lsp/language.ts +0 -119
- package/src/lsp/server.ts +0 -2046
- package/src/mcp/auth.ts +0 -132
- package/src/mcp/index.ts +0 -937
- package/src/mcp/oauth-callback.ts +0 -200
- package/src/mcp/oauth-provider.ts +0 -154
- package/src/patch/index.ts +0 -680
- package/src/permission/arity.ts +0 -163
- package/src/permission/index.ts +0 -210
- package/src/permission/next.ts +0 -280
- package/src/plugin/codex.ts +0 -624
- package/src/plugin/copilot.ts +0 -327
- package/src/plugin/index.ts +0 -138
- package/src/project/bootstrap.ts +0 -35
- package/src/project/instance.ts +0 -114
- package/src/project/project.ts +0 -371
- package/src/project/state.ts +0 -70
- package/src/project/vcs.ts +0 -76
- package/src/provider/auth.ts +0 -147
- package/src/provider/error.ts +0 -189
- package/src/provider/models.ts +0 -133
- package/src/provider/provider.ts +0 -1370
- package/src/provider/sdk/copilot/README.md +0 -5
- package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -164
- package/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
- package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -17
- package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -780
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
- package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
- package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -87
- package/src/provider/sdk/copilot/copilot-provider.ts +0 -100
- package/src/provider/sdk/copilot/index.ts +0 -2
- package/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
- package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -303
- package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
- package/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
- package/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
- package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -207
- package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1732
- package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -177
- package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
- package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -88
- package/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -128
- package/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -115
- package/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -65
- package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -104
- package/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -103
- package/src/provider/transform.ts +0 -806
- package/src/pty/index.ts +0 -286
- package/src/question/index.ts +0 -171
- package/src/scheduler/index.ts +0 -61
- package/src/server/error.ts +0 -36
- package/src/server/event.ts +0 -7
- package/src/server/mdns.ts +0 -60
- package/src/server/routes/config.ts +0 -92
- package/src/server/routes/experimental.ts +0 -208
- package/src/server/routes/file.ts +0 -197
- package/src/server/routes/global.ts +0 -183
- package/src/server/routes/mcp.ts +0 -225
- package/src/server/routes/permission.ts +0 -68
- package/src/server/routes/project.ts +0 -82
- package/src/server/routes/provider.ts +0 -179
- package/src/server/routes/pty.ts +0 -176
- package/src/server/routes/question.ts +0 -98
- package/src/server/routes/session.ts +0 -939
- package/src/server/routes/tui.ts +0 -379
- package/src/server/server.ts +0 -621
- package/src/session/compaction.ts +0 -261
- package/src/session/index.ts +0 -543
- package/src/session/instruction.ts +0 -197
- package/src/session/llm.ts +0 -283
- package/src/session/message-v2.ts +0 -841
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -410
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex_header.txt +0 -79
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt/trinity.txt +0 -97
- package/src/session/prompt.ts +0 -1964
- package/src/session/retry.ts +0 -101
- package/src/session/revert.ts +0 -121
- package/src/session/status.ts +0 -76
- package/src/session/summary.ts +0 -203
- package/src/session/system.ts +0 -54
- package/src/session/todo.ts +0 -37
- package/src/share/share-next.ts +0 -200
- package/src/share/share.ts +0 -92
- package/src/shell/shell.ts +0 -67
- package/src/skill/discovery.ts +0 -97
- package/src/skill/index.ts +0 -1
- package/src/skill/skill.ts +0 -188
- package/src/snapshot/index.ts +0 -255
- package/src/storage/storage.ts +0 -227
- package/src/tool/apply_patch.ts +0 -281
- package/src/tool/apply_patch.txt +0 -33
- package/src/tool/bash.ts +0 -269
- package/src/tool/bash.txt +0 -115
- package/src/tool/batch.ts +0 -175
- package/src/tool/batch.txt +0 -24
- package/src/tool/codesearch.ts +0 -132
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -655
- package/src/tool/edit.txt +0 -10
- package/src/tool/external-directory.ts +0 -32
- package/src/tool/glob.ts +0 -80
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -150
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -121
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp.ts +0 -96
- package/src/tool/lsp.txt +0 -19
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/plan-enter.txt +0 -14
- package/src/tool/plan-exit.txt +0 -13
- package/src/tool/plan.ts +0 -130
- package/src/tool/question.ts +0 -33
- package/src/tool/question.txt +0 -10
- package/src/tool/read.ts +0 -261
- package/src/tool/read.txt +0 -14
- package/src/tool/registry.ts +0 -160
- package/src/tool/skill.ts +0 -123
- package/src/tool/task.ts +0 -165
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -53
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -89
- package/src/tool/truncation.ts +0 -106
- package/src/tool/webfetch.ts +0 -186
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -150
- package/src/tool/websearch.txt +0 -14
- package/src/tool/write.ts +0 -85
- package/src/tool/write.txt +0 -8
- package/src/util/abort.ts +0 -35
- package/src/util/archive.ts +0 -16
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -93
- package/src/util/fn.ts +0 -11
- package/src/util/format.ts +0 -20
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -103
- package/src/util/lazy.ts +0 -18
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -180
- package/src/util/proxied.ts +0 -3
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -66
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -56
- package/src/worktree/index.ts +0 -612
- package/sst-env.d.ts +0 -9
- package/test/acp/agent-interface.test.ts +0 -51
- package/test/acp/event-subscription.test.ts +0 -436
- package/test/agent/agent.test.ts +0 -675
- package/test/bun.test.ts +0 -53
- package/test/cli/github-action.test.ts +0 -161
- package/test/cli/github-remote.test.ts +0 -80
- package/test/cli/import.test.ts +0 -38
- package/test/cli/tui/transcript.test.ts +0 -322
- package/test/config/agent-color.test.ts +0 -71
- package/test/config/config.test.ts +0 -1802
- package/test/config/fixtures/empty-frontmatter.md +0 -4
- package/test/config/fixtures/frontmatter.md +0 -28
- package/test/config/fixtures/markdown-header.md +0 -11
- package/test/config/fixtures/no-frontmatter.md +0 -1
- package/test/config/fixtures/weird-model-id.md +0 -13
- package/test/config/markdown.test.ts +0 -228
- package/test/file/ignore.test.ts +0 -10
- package/test/file/path-traversal.test.ts +0 -198
- package/test/file/ripgrep.test.ts +0 -39
- package/test/fixture/fixture.ts +0 -45
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -421
- package/test/lsp/client.test.ts +0 -95
- package/test/mcp/headers.test.ts +0 -153
- package/test/mcp/oauth-browser.test.ts +0 -249
- package/test/memory/abort-leak.test.ts +0 -136
- package/test/patch/patch.test.ts +0 -348
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -690
- package/test/permission-task.test.ts +0 -319
- package/test/plugin/auth-override.test.ts +0 -44
- package/test/plugin/codex.test.ts +0 -123
- package/test/preload.ts +0 -63
- package/test/project/project.test.ts +0 -120
- package/test/provider/amazon-bedrock.test.ts +0 -445
- package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
- package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
- package/test/provider/gitlab-duo.test.ts +0 -262
- package/test/provider/provider.test.ts +0 -2129
- package/test/provider/transform.test.ts +0 -1928
- package/test/question/question.test.ts +0 -300
- package/test/scheduler.test.ts +0 -73
- package/test/server/session-list.test.ts +0 -39
- package/test/server/session-select.test.ts +0 -78
- package/test/session/compaction.test.ts +0 -423
- package/test/session/instruction.test.ts +0 -170
- package/test/session/llm.test.ts +0 -667
- package/test/session/message-v2.test.ts +0 -924
- package/test/session/prompt-missing-file.test.ts +0 -53
- package/test/session/prompt-special-chars.test.ts +0 -56
- package/test/session/prompt-variant.test.ts +0 -68
- package/test/session/retry.test.ts +0 -188
- package/test/session/revert-compact.test.ts +0 -285
- package/test/session/session.test.ts +0 -71
- package/test/session/structured-output-integration.test.ts +0 -233
- package/test/session/structured-output.test.ts +0 -385
- package/test/skill/discovery.test.ts +0 -60
- package/test/skill/skill.test.ts +0 -388
- package/test/snapshot/snapshot.test.ts +0 -1040
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/apply_patch.test.ts +0 -559
- package/test/tool/bash.test.ts +0 -399
- package/test/tool/external-directory.test.ts +0 -127
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +0 -38413
- package/test/tool/grep.test.ts +0 -110
- package/test/tool/question.test.ts +0 -107
- package/test/tool/read.test.ts +0 -421
- package/test/tool/registry.test.ts +0 -122
- package/test/tool/skill.test.ts +0 -112
- package/test/tool/truncation.test.ts +0 -159
- package/test/util/filesystem.test.ts +0 -39
- package/test/util/format.test.ts +0 -59
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/lock.test.ts +0 -72
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -75
- package/tsconfig.json +0 -16
- /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
package/src/file/ripgrep.ts
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
// Ripgrep utility functions
|
|
2
|
-
import path from "path"
|
|
3
|
-
import { Global } from "../global"
|
|
4
|
-
import fs from "fs/promises"
|
|
5
|
-
import z from "zod"
|
|
6
|
-
import { NamedError } from "@opencode-ai/util/error"
|
|
7
|
-
import { lazy } from "../util/lazy"
|
|
8
|
-
import { $ } from "bun"
|
|
9
|
-
|
|
10
|
-
import { ZipReader, BlobReader, BlobWriter } from "@zip.js/zip.js"
|
|
11
|
-
import { Log } from "@/util/log"
|
|
12
|
-
|
|
13
|
-
export namespace Ripgrep {
|
|
14
|
-
const log = Log.create({ service: "ripgrep" })
|
|
15
|
-
const Stats = z.object({
|
|
16
|
-
elapsed: z.object({
|
|
17
|
-
secs: z.number(),
|
|
18
|
-
nanos: z.number(),
|
|
19
|
-
human: z.string(),
|
|
20
|
-
}),
|
|
21
|
-
searches: z.number(),
|
|
22
|
-
searches_with_match: z.number(),
|
|
23
|
-
bytes_searched: z.number(),
|
|
24
|
-
bytes_printed: z.number(),
|
|
25
|
-
matched_lines: z.number(),
|
|
26
|
-
matches: z.number(),
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const Begin = z.object({
|
|
30
|
-
type: z.literal("begin"),
|
|
31
|
-
data: z.object({
|
|
32
|
-
path: z.object({
|
|
33
|
-
text: z.string(),
|
|
34
|
-
}),
|
|
35
|
-
}),
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
export const Match = z.object({
|
|
39
|
-
type: z.literal("match"),
|
|
40
|
-
data: z.object({
|
|
41
|
-
path: z.object({
|
|
42
|
-
text: z.string(),
|
|
43
|
-
}),
|
|
44
|
-
lines: z.object({
|
|
45
|
-
text: z.string(),
|
|
46
|
-
}),
|
|
47
|
-
line_number: z.number(),
|
|
48
|
-
absolute_offset: z.number(),
|
|
49
|
-
submatches: z.array(
|
|
50
|
-
z.object({
|
|
51
|
-
match: z.object({
|
|
52
|
-
text: z.string(),
|
|
53
|
-
}),
|
|
54
|
-
start: z.number(),
|
|
55
|
-
end: z.number(),
|
|
56
|
-
}),
|
|
57
|
-
),
|
|
58
|
-
}),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const End = z.object({
|
|
62
|
-
type: z.literal("end"),
|
|
63
|
-
data: z.object({
|
|
64
|
-
path: z.object({
|
|
65
|
-
text: z.string(),
|
|
66
|
-
}),
|
|
67
|
-
binary_offset: z.number().nullable(),
|
|
68
|
-
stats: Stats,
|
|
69
|
-
}),
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const Summary = z.object({
|
|
73
|
-
type: z.literal("summary"),
|
|
74
|
-
data: z.object({
|
|
75
|
-
elapsed_total: z.object({
|
|
76
|
-
human: z.string(),
|
|
77
|
-
nanos: z.number(),
|
|
78
|
-
secs: z.number(),
|
|
79
|
-
}),
|
|
80
|
-
stats: Stats,
|
|
81
|
-
}),
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const Result = z.union([Begin, Match, End, Summary])
|
|
85
|
-
|
|
86
|
-
export type Result = z.infer<typeof Result>
|
|
87
|
-
export type Match = z.infer<typeof Match>
|
|
88
|
-
export type Begin = z.infer<typeof Begin>
|
|
89
|
-
export type End = z.infer<typeof End>
|
|
90
|
-
export type Summary = z.infer<typeof Summary>
|
|
91
|
-
const PLATFORM = {
|
|
92
|
-
"arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
|
|
93
|
-
"arm64-linux": {
|
|
94
|
-
platform: "aarch64-unknown-linux-gnu",
|
|
95
|
-
extension: "tar.gz",
|
|
96
|
-
},
|
|
97
|
-
"x64-darwin": { platform: "x86_64-apple-darwin", extension: "tar.gz" },
|
|
98
|
-
"x64-linux": { platform: "x86_64-unknown-linux-musl", extension: "tar.gz" },
|
|
99
|
-
"x64-win32": { platform: "x86_64-pc-windows-msvc", extension: "zip" },
|
|
100
|
-
} as const
|
|
101
|
-
|
|
102
|
-
export const ExtractionFailedError = NamedError.create(
|
|
103
|
-
"RipgrepExtractionFailedError",
|
|
104
|
-
z.object({
|
|
105
|
-
filepath: z.string(),
|
|
106
|
-
stderr: z.string(),
|
|
107
|
-
}),
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
export const UnsupportedPlatformError = NamedError.create(
|
|
111
|
-
"RipgrepUnsupportedPlatformError",
|
|
112
|
-
z.object({
|
|
113
|
-
platform: z.string(),
|
|
114
|
-
}),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
export const DownloadFailedError = NamedError.create(
|
|
118
|
-
"RipgrepDownloadFailedError",
|
|
119
|
-
z.object({
|
|
120
|
-
url: z.string(),
|
|
121
|
-
status: z.number(),
|
|
122
|
-
}),
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
const state = lazy(async () => {
|
|
126
|
-
const system = Bun.which("rg")
|
|
127
|
-
if (system) {
|
|
128
|
-
const stat = await fs.stat(system).catch(() => undefined)
|
|
129
|
-
if (stat?.isFile()) return { filepath: system }
|
|
130
|
-
log.warn("bun.which returned invalid rg path", { filepath: system })
|
|
131
|
-
}
|
|
132
|
-
const filepath = path.join(Global.Path.bin, "rg" + (process.platform === "win32" ? ".exe" : ""))
|
|
133
|
-
|
|
134
|
-
const file = Bun.file(filepath)
|
|
135
|
-
if (!(await file.exists())) {
|
|
136
|
-
const platformKey = `${process.arch}-${process.platform}` as keyof typeof PLATFORM
|
|
137
|
-
const config = PLATFORM[platformKey]
|
|
138
|
-
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
|
|
139
|
-
|
|
140
|
-
const version = "14.1.1"
|
|
141
|
-
const filename = `ripgrep-${version}-${config.platform}.${config.extension}`
|
|
142
|
-
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
|
|
143
|
-
|
|
144
|
-
const response = await fetch(url)
|
|
145
|
-
if (!response.ok) throw new DownloadFailedError({ url, status: response.status })
|
|
146
|
-
|
|
147
|
-
const buffer = await response.arrayBuffer()
|
|
148
|
-
const archivePath = path.join(Global.Path.bin, filename)
|
|
149
|
-
await Bun.write(archivePath, buffer)
|
|
150
|
-
if (config.extension === "tar.gz") {
|
|
151
|
-
const args = ["tar", "-xzf", archivePath, "--strip-components=1"]
|
|
152
|
-
|
|
153
|
-
if (platformKey.endsWith("-darwin")) args.push("--include=*/rg")
|
|
154
|
-
if (platformKey.endsWith("-linux")) args.push("--wildcards", "*/rg")
|
|
155
|
-
|
|
156
|
-
const proc = Bun.spawn(args, {
|
|
157
|
-
cwd: Global.Path.bin,
|
|
158
|
-
stderr: "pipe",
|
|
159
|
-
stdout: "pipe",
|
|
160
|
-
})
|
|
161
|
-
await proc.exited
|
|
162
|
-
if (proc.exitCode !== 0)
|
|
163
|
-
throw new ExtractionFailedError({
|
|
164
|
-
filepath,
|
|
165
|
-
stderr: await Bun.readableStreamToText(proc.stderr),
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
if (config.extension === "zip") {
|
|
169
|
-
const zipFileReader = new ZipReader(new BlobReader(new Blob([await Bun.file(archivePath).arrayBuffer()])))
|
|
170
|
-
const entries = await zipFileReader.getEntries()
|
|
171
|
-
let rgEntry: any
|
|
172
|
-
for (const entry of entries) {
|
|
173
|
-
if (entry.filename.endsWith("rg.exe")) {
|
|
174
|
-
rgEntry = entry
|
|
175
|
-
break
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (!rgEntry) {
|
|
180
|
-
throw new ExtractionFailedError({
|
|
181
|
-
filepath: archivePath,
|
|
182
|
-
stderr: "rg.exe not found in zip archive",
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const rgBlob = await rgEntry.getData(new BlobWriter())
|
|
187
|
-
if (!rgBlob) {
|
|
188
|
-
throw new ExtractionFailedError({
|
|
189
|
-
filepath: archivePath,
|
|
190
|
-
stderr: "Failed to extract rg.exe from zip archive",
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
await Bun.write(filepath, await rgBlob.arrayBuffer())
|
|
194
|
-
await zipFileReader.close()
|
|
195
|
-
}
|
|
196
|
-
await fs.unlink(archivePath)
|
|
197
|
-
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
filepath,
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
export async function filepath() {
|
|
206
|
-
const { filepath } = await state()
|
|
207
|
-
return filepath
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export async function* files(input: {
|
|
211
|
-
cwd: string
|
|
212
|
-
glob?: string[]
|
|
213
|
-
hidden?: boolean
|
|
214
|
-
follow?: boolean
|
|
215
|
-
maxDepth?: number
|
|
216
|
-
signal?: AbortSignal
|
|
217
|
-
}) {
|
|
218
|
-
input.signal?.throwIfAborted()
|
|
219
|
-
|
|
220
|
-
const args = [await filepath(), "--files", "--glob=!.git/*"]
|
|
221
|
-
if (input.follow) args.push("--follow")
|
|
222
|
-
if (input.hidden !== false) args.push("--hidden")
|
|
223
|
-
if (input.maxDepth !== undefined) args.push(`--max-depth=${input.maxDepth}`)
|
|
224
|
-
if (input.glob) {
|
|
225
|
-
for (const g of input.glob) {
|
|
226
|
-
args.push(`--glob=${g}`)
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Bun.spawn should throw this, but it incorrectly reports that the executable does not exist.
|
|
231
|
-
// See https://github.com/oven-sh/bun/issues/24012
|
|
232
|
-
if (!(await fs.stat(input.cwd).catch(() => undefined))?.isDirectory()) {
|
|
233
|
-
throw Object.assign(new Error(`No such file or directory: '${input.cwd}'`), {
|
|
234
|
-
code: "ENOENT",
|
|
235
|
-
errno: -2,
|
|
236
|
-
path: input.cwd,
|
|
237
|
-
})
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const proc = Bun.spawn(args, {
|
|
241
|
-
cwd: input.cwd,
|
|
242
|
-
stdout: "pipe",
|
|
243
|
-
stderr: "ignore",
|
|
244
|
-
maxBuffer: 1024 * 1024 * 20,
|
|
245
|
-
signal: input.signal,
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
const reader = proc.stdout.getReader()
|
|
249
|
-
const decoder = new TextDecoder()
|
|
250
|
-
let buffer = ""
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
while (true) {
|
|
254
|
-
input.signal?.throwIfAborted()
|
|
255
|
-
|
|
256
|
-
const { done, value } = await reader.read()
|
|
257
|
-
if (done) break
|
|
258
|
-
|
|
259
|
-
buffer += decoder.decode(value, { stream: true })
|
|
260
|
-
// Handle both Unix (\n) and Windows (\r\n) line endings
|
|
261
|
-
const lines = buffer.split(/\r?\n/)
|
|
262
|
-
buffer = lines.pop() || ""
|
|
263
|
-
|
|
264
|
-
for (const line of lines) {
|
|
265
|
-
if (line) yield line
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (buffer) yield buffer
|
|
270
|
-
} finally {
|
|
271
|
-
reader.releaseLock()
|
|
272
|
-
await proc.exited
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
input.signal?.throwIfAborted()
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export async function tree(input: { cwd: string; limit?: number; signal?: AbortSignal }) {
|
|
279
|
-
log.info("tree", input)
|
|
280
|
-
const files = await Array.fromAsync(Ripgrep.files({ cwd: input.cwd, signal: input.signal }))
|
|
281
|
-
interface Node {
|
|
282
|
-
name: string
|
|
283
|
-
children: Map<string, Node>
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function dir(node: Node, name: string) {
|
|
287
|
-
const existing = node.children.get(name)
|
|
288
|
-
if (existing) return existing
|
|
289
|
-
const next = { name, children: new Map() }
|
|
290
|
-
node.children.set(name, next)
|
|
291
|
-
return next
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const root: Node = { name: "", children: new Map() }
|
|
295
|
-
for (const file of files) {
|
|
296
|
-
if (file.includes(".innocode") || file.includes(".opencode")) continue
|
|
297
|
-
const parts = file.split(path.sep)
|
|
298
|
-
if (parts.length < 2) continue
|
|
299
|
-
let node = root
|
|
300
|
-
for (const part of parts.slice(0, -1)) {
|
|
301
|
-
node = dir(node, part)
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function count(node: Node): number {
|
|
306
|
-
let total = 0
|
|
307
|
-
for (const child of node.children.values()) {
|
|
308
|
-
total += 1 + count(child)
|
|
309
|
-
}
|
|
310
|
-
return total
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const total = count(root)
|
|
314
|
-
const limit = input.limit ?? total
|
|
315
|
-
const lines: string[] = []
|
|
316
|
-
const queue: { node: Node; path: string }[] = []
|
|
317
|
-
for (const child of Array.from(root.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
318
|
-
queue.push({ node: child, path: child.name })
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
let used = 0
|
|
322
|
-
for (let i = 0; i < queue.length && used < limit; i++) {
|
|
323
|
-
const { node, path } = queue[i]
|
|
324
|
-
lines.push(path)
|
|
325
|
-
used++
|
|
326
|
-
for (const child of Array.from(node.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
327
|
-
queue.push({ node: child, path: `${path}/${child.name}` })
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (total > used) lines.push(`[${total - used} truncated]`)
|
|
332
|
-
|
|
333
|
-
return lines.join("\n")
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export async function search(input: {
|
|
337
|
-
cwd: string
|
|
338
|
-
pattern: string
|
|
339
|
-
glob?: string[]
|
|
340
|
-
limit?: number
|
|
341
|
-
follow?: boolean
|
|
342
|
-
}) {
|
|
343
|
-
const args = [`${await filepath()}`, "--json", "--hidden", "--glob='!.git/*'"]
|
|
344
|
-
if (input.follow) args.push("--follow")
|
|
345
|
-
|
|
346
|
-
if (input.glob) {
|
|
347
|
-
for (const g of input.glob) {
|
|
348
|
-
args.push(`--glob=${g}`)
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (input.limit) {
|
|
353
|
-
args.push(`--max-count=${input.limit}`)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
args.push("--")
|
|
357
|
-
args.push(input.pattern)
|
|
358
|
-
|
|
359
|
-
const command = args.join(" ")
|
|
360
|
-
const result = await $`${{ raw: command }}`.cwd(input.cwd).quiet().nothrow()
|
|
361
|
-
if (result.exitCode !== 0) {
|
|
362
|
-
return []
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Handle both Unix (\n) and Windows (\r\n) line endings
|
|
366
|
-
const lines = result.text().trim().split(/\r?\n/).filter(Boolean)
|
|
367
|
-
// Parse JSON lines from ripgrep output
|
|
368
|
-
|
|
369
|
-
return lines
|
|
370
|
-
.map((line) => JSON.parse(line))
|
|
371
|
-
.map((parsed) => Result.parse(parsed))
|
|
372
|
-
.filter((r) => r.type === "match")
|
|
373
|
-
.map((r) => r.data)
|
|
374
|
-
}
|
|
375
|
-
}
|
package/src/file/time.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Instance } from "../project/instance"
|
|
2
|
-
import { Log } from "../util/log"
|
|
3
|
-
import { Flag } from "../flag/flag"
|
|
4
|
-
|
|
5
|
-
export namespace FileTime {
|
|
6
|
-
const log = Log.create({ service: "file.time" })
|
|
7
|
-
// Per-session read times plus per-file write locks.
|
|
8
|
-
// All tools that overwrite existing files should run their
|
|
9
|
-
// assert/read/write/update sequence inside withLock(filepath, ...)
|
|
10
|
-
// so concurrent writes to the same file are serialized.
|
|
11
|
-
export const state = Instance.state(() => {
|
|
12
|
-
const read: {
|
|
13
|
-
[sessionID: string]: {
|
|
14
|
-
[path: string]: Date | undefined
|
|
15
|
-
}
|
|
16
|
-
} = {}
|
|
17
|
-
const locks = new Map<string, Promise<void>>()
|
|
18
|
-
return {
|
|
19
|
-
read,
|
|
20
|
-
locks,
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export function read(sessionID: string, file: string) {
|
|
25
|
-
log.info("read", { sessionID, file })
|
|
26
|
-
const { read } = state()
|
|
27
|
-
read[sessionID] = read[sessionID] || {}
|
|
28
|
-
read[sessionID][file] = new Date()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function get(sessionID: string, file: string) {
|
|
32
|
-
return state().read[sessionID]?.[file]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function withLock<T>(filepath: string, fn: () => Promise<T>): Promise<T> {
|
|
36
|
-
const current = state()
|
|
37
|
-
const currentLock = current.locks.get(filepath) ?? Promise.resolve()
|
|
38
|
-
let release: () => void = () => {}
|
|
39
|
-
const nextLock = new Promise<void>((resolve) => {
|
|
40
|
-
release = resolve
|
|
41
|
-
})
|
|
42
|
-
const chained = currentLock.then(() => nextLock)
|
|
43
|
-
current.locks.set(filepath, chained)
|
|
44
|
-
await currentLock
|
|
45
|
-
try {
|
|
46
|
-
return await fn()
|
|
47
|
-
} finally {
|
|
48
|
-
release()
|
|
49
|
-
if (current.locks.get(filepath) === chained) {
|
|
50
|
-
current.locks.delete(filepath)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function assert(sessionID: string, filepath: string) {
|
|
56
|
-
if (Flag.OPENCODE_DISABLE_FILETIME_CHECK === true) {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const time = get(sessionID, filepath)
|
|
61
|
-
if (!time) throw new Error(`You must read file ${filepath} before overwriting it. Use the Read tool first`)
|
|
62
|
-
const stats = await Bun.file(filepath).stat()
|
|
63
|
-
if (stats.mtime.getTime() > time.getTime()) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`File ${filepath} has been modified since it was last read.\nLast modification: ${stats.mtime.toISOString()}\nLast read: ${time.toISOString()}\n\nPlease read the file again before modifying it.`,
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/file/watcher.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { BusEvent } from "@/bus/bus-event"
|
|
2
|
-
import { Bus } from "@/bus"
|
|
3
|
-
import z from "zod"
|
|
4
|
-
import { Instance } from "../project/instance"
|
|
5
|
-
import { Log } from "../util/log"
|
|
6
|
-
import { FileIgnore } from "./ignore"
|
|
7
|
-
import { Config } from "../config/config"
|
|
8
|
-
import path from "path"
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import { createWrapper } from "@parcel/watcher/wrapper"
|
|
11
|
-
import { lazy } from "@/util/lazy"
|
|
12
|
-
import { withTimeout } from "@/util/timeout"
|
|
13
|
-
import type ParcelWatcher from "@parcel/watcher"
|
|
14
|
-
import { $ } from "bun"
|
|
15
|
-
import { Flag } from "@/flag/flag"
|
|
16
|
-
import { readdir } from "fs/promises"
|
|
17
|
-
|
|
18
|
-
const SUBSCRIBE_TIMEOUT_MS = 10_000
|
|
19
|
-
|
|
20
|
-
declare const OPENCODE_LIBC: string | undefined
|
|
21
|
-
|
|
22
|
-
export namespace FileWatcher {
|
|
23
|
-
const log = Log.create({ service: "file.watcher" })
|
|
24
|
-
|
|
25
|
-
export const Event = {
|
|
26
|
-
Updated: BusEvent.define(
|
|
27
|
-
"file.watcher.updated",
|
|
28
|
-
z.object({
|
|
29
|
-
file: z.string(),
|
|
30
|
-
event: z.union([z.literal("add"), z.literal("change"), z.literal("unlink")]),
|
|
31
|
-
}),
|
|
32
|
-
),
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const watcher = lazy((): typeof import("@parcel/watcher") | undefined => {
|
|
36
|
-
try {
|
|
37
|
-
const binding = require(
|
|
38
|
-
`@parcel/watcher-${process.platform}-${process.arch}${process.platform === "linux" ? `-${OPENCODE_LIBC || "glibc"}` : ""}`,
|
|
39
|
-
)
|
|
40
|
-
return createWrapper(binding) as typeof import("@parcel/watcher")
|
|
41
|
-
} catch (error) {
|
|
42
|
-
log.error("failed to load watcher binding", { error })
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const state = Instance.state(
|
|
48
|
-
async () => {
|
|
49
|
-
if (Instance.project.vcs !== "git") return {}
|
|
50
|
-
log.info("init")
|
|
51
|
-
const cfg = await Config.get()
|
|
52
|
-
const backend = (() => {
|
|
53
|
-
if (process.platform === "win32") return "windows"
|
|
54
|
-
if (process.platform === "darwin") return "fs-events"
|
|
55
|
-
if (process.platform === "linux") return "inotify"
|
|
56
|
-
})()
|
|
57
|
-
if (!backend) {
|
|
58
|
-
log.error("watcher backend not supported", { platform: process.platform })
|
|
59
|
-
return {}
|
|
60
|
-
}
|
|
61
|
-
log.info("watcher backend", { platform: process.platform, backend })
|
|
62
|
-
|
|
63
|
-
const w = watcher()
|
|
64
|
-
if (!w) return {}
|
|
65
|
-
|
|
66
|
-
const subscribe: ParcelWatcher.SubscribeCallback = (err, evts) => {
|
|
67
|
-
if (err) return
|
|
68
|
-
for (const evt of evts) {
|
|
69
|
-
if (evt.type === "create") Bus.publish(Event.Updated, { file: evt.path, event: "add" })
|
|
70
|
-
if (evt.type === "update") Bus.publish(Event.Updated, { file: evt.path, event: "change" })
|
|
71
|
-
if (evt.type === "delete") Bus.publish(Event.Updated, { file: evt.path, event: "unlink" })
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const subs: ParcelWatcher.AsyncSubscription[] = []
|
|
76
|
-
const cfgIgnores = cfg.watcher?.ignore ?? []
|
|
77
|
-
|
|
78
|
-
if (Flag.OPENCODE_EXPERIMENTAL_FILEWATCHER) {
|
|
79
|
-
const pending = w.subscribe(Instance.directory, subscribe, {
|
|
80
|
-
ignore: [...FileIgnore.PATTERNS, ...cfgIgnores],
|
|
81
|
-
backend,
|
|
82
|
-
})
|
|
83
|
-
const sub = await withTimeout(pending, SUBSCRIBE_TIMEOUT_MS).catch((err) => {
|
|
84
|
-
log.error("failed to subscribe to Instance.directory", { error: err })
|
|
85
|
-
pending.then((s) => s.unsubscribe()).catch(() => {})
|
|
86
|
-
return undefined
|
|
87
|
-
})
|
|
88
|
-
if (sub) subs.push(sub)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const vcsDir = await $`git rev-parse --git-dir`
|
|
92
|
-
.quiet()
|
|
93
|
-
.nothrow()
|
|
94
|
-
.cwd(Instance.worktree)
|
|
95
|
-
.text()
|
|
96
|
-
.then((x) => path.resolve(Instance.worktree, x.trim()))
|
|
97
|
-
.catch(() => undefined)
|
|
98
|
-
if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) {
|
|
99
|
-
const gitDirContents = await readdir(vcsDir).catch(() => [])
|
|
100
|
-
const ignoreList = gitDirContents.filter((entry) => entry !== "HEAD")
|
|
101
|
-
const pending = w.subscribe(vcsDir, subscribe, {
|
|
102
|
-
ignore: ignoreList,
|
|
103
|
-
backend,
|
|
104
|
-
})
|
|
105
|
-
const sub = await withTimeout(pending, SUBSCRIBE_TIMEOUT_MS).catch((err) => {
|
|
106
|
-
log.error("failed to subscribe to vcsDir", { error: err })
|
|
107
|
-
pending.then((s) => s.unsubscribe()).catch(() => {})
|
|
108
|
-
return undefined
|
|
109
|
-
})
|
|
110
|
-
if (sub) subs.push(sub)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return { subs }
|
|
114
|
-
},
|
|
115
|
-
async (state) => {
|
|
116
|
-
if (!state.subs) return
|
|
117
|
-
await Promise.all(state.subs.map((sub) => sub?.unsubscribe()))
|
|
118
|
-
},
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
export function init() {
|
|
122
|
-
if (Flag.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER) {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
state()
|
|
126
|
-
}
|
|
127
|
-
}
|