@andorra-labs/code 0.1.11 → 0.1.13
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/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/account-presentation.d.ts +1 -37
- package/dist/src/account-presentation.js +2 -42
- package/dist/src/activity.d.ts +0 -25
- package/dist/src/activity.js +1 -23
- package/dist/src/agent-definitions.d.ts +0 -26
- package/dist/src/agent-definitions.js +0 -43
- package/dist/src/agent-execution.d.ts +0 -2
- package/dist/src/agent-execution.js +59 -414
- package/dist/src/agent-mcp-catalog.d.ts +0 -8
- package/dist/src/agent-mcp-catalog.js +0 -2
- package/dist/src/agent-mcp.d.ts +0 -56
- package/dist/src/agent-mcp.js +14 -153
- package/dist/src/agent-modifiers.d.ts +0 -1
- package/dist/src/agent-modifiers.js +25 -68
- package/dist/src/analytics.d.ts +0 -66
- package/dist/src/analytics.js +0 -45
- package/dist/src/anthropic-console-auth.d.ts +0 -24
- package/dist/src/anthropic-console-auth.js +0 -37
- package/dist/src/anthropic-credentials.d.ts +0 -25
- package/dist/src/anthropic-credentials.js +0 -28
- package/dist/src/app-server/protocol.d.ts +19 -244
- package/dist/src/app-server/protocol.js +1 -132
- package/dist/src/app-server/reasoning.d.ts +0 -31
- package/dist/src/app-server/reasoning.js +0 -54
- package/dist/src/app-server/terminal.d.ts +0 -36
- package/dist/src/app-server/terminal.js +3 -39
- package/dist/src/app-server/workspace.d.ts +0 -167
- package/dist/src/app-server/workspace.js +4 -406
- package/dist/src/app-server.d.ts +33 -918
- package/dist/src/app-server.js +608 -2984
- package/dist/src/artifacts.d.ts +0 -10
- package/dist/src/artifacts.js +1 -11
- package/dist/src/attachments.d.ts +4 -98
- package/dist/src/attachments.js +10 -130
- package/dist/src/auth/AuthManager.d.ts +0 -93
- package/dist/src/auth/AuthManager.js +3 -165
- package/dist/src/auth/callback-page.d.ts +0 -1
- package/dist/src/auth/callback-page.js +0 -4
- package/dist/src/auth/callback.d.ts +0 -25
- package/dist/src/auth/callback.js +1 -29
- package/dist/src/auth/deployment.d.ts +0 -16
- package/dist/src/auth/deployment.js +0 -16
- package/dist/src/auth/index.d.ts +0 -11
- package/dist/src/auth/index.js +0 -11
- package/dist/src/auth/lock.d.ts +0 -1
- package/dist/src/auth/lock.js +0 -1
- package/dist/src/auth/store.d.ts +7 -108
- package/dist/src/auth/store.js +21 -129
- package/dist/src/auth/types.d.ts +0 -8
- package/dist/src/auth-commands.d.ts +0 -5
- package/dist/src/auth-commands.js +0 -1
- package/dist/src/automation-runner.d.ts +0 -9
- package/dist/src/automation-runner.js +0 -11
- package/dist/src/automation-service.d.ts +0 -10
- package/dist/src/automation-service.js +3 -17
- package/dist/src/automation-tool.js +0 -5
- package/dist/src/automation-worker-shutdown.d.ts +0 -1
- package/dist/src/automation-worker-shutdown.js +0 -3
- package/dist/src/automations.d.ts +23 -2
- package/dist/src/automations.js +91 -12
- package/dist/src/background-tasks.d.ts +0 -23
- package/dist/src/background-tasks.js +0 -11
- package/dist/src/boot-trace.d.ts +0 -13
- package/dist/src/boot-trace.js +1 -14
- package/dist/src/browser-activity.js +0 -2
- package/dist/src/browser-bridge.d.ts +0 -2
- package/dist/src/browser-bridge.js +0 -27
- package/dist/src/browser-captcha-tool.d.ts +0 -13
- package/dist/src/browser-captcha-tool.js +3 -35
- package/dist/src/browser-extensions-tool.d.ts +24 -0
- package/dist/src/browser-extensions-tool.js +137 -0
- package/dist/src/browser-extensions.d.ts +127 -0
- package/dist/src/browser-extensions.js +729 -0
- package/dist/src/browser-observation.d.ts +0 -15
- package/dist/src/browser-observation.js +1 -22
- package/dist/src/browser-panel-tool.d.ts +10 -25
- package/dist/src/browser-panel-tool.js +64 -60
- package/dist/src/browser-runner.d.ts +0 -1
- package/dist/src/browser-runner.js +7 -46
- package/dist/src/browser-server.d.ts +0 -6
- package/dist/src/browser-server.js +6 -229
- package/dist/src/browser-session.d.ts +0 -25
- package/dist/src/browser-session.js +1 -71
- package/dist/src/browser-stealth.d.ts +0 -12
- package/dist/src/browser-stealth.js +0 -36
- package/dist/src/browser-ui/app.js +7 -174
- package/dist/src/browser-ui/style.css +0 -68
- package/dist/src/browser-ui/tokens.css +11 -93
- package/dist/src/browser-view.d.ts +52 -290
- package/dist/src/browser-view.js +354 -567
- package/dist/src/capabilities.d.ts +0 -8
- package/dist/src/capabilities.js +0 -29
- package/dist/src/capsolver.d.ts +0 -13
- package/dist/src/capsolver.js +0 -15
- package/dist/src/clarification-ui.d.ts +0 -7
- package/dist/src/clarification-ui.js +0 -8
- package/dist/src/claude-executable.d.ts +0 -1
- package/dist/src/claude-executable.js +1 -2
- package/dist/src/claude-provider.d.ts +6 -19
- package/dist/src/claude-provider.js +166 -61
- package/dist/src/cli-executable.d.ts +0 -16
- package/dist/src/cli-executable.js +0 -7
- package/dist/src/cli-process.d.ts +0 -26
- package/dist/src/cli-process.js +0 -18
- package/dist/src/cli-sign-in.d.ts +0 -20
- package/dist/src/cli-sign-in.js +1 -17
- package/dist/src/cli.d.ts +3 -56
- package/dist/src/cli.js +193 -702
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +27 -100
- package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
- package/dist/src/code-intelligence/ContextLedger.js +0 -10
- package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
- package/dist/src/code-intelligence/ContextRouter.js +0 -8
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
- package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
- package/dist/src/code-intelligence/repository.d.ts +0 -9
- package/dist/src/code-intelligence/repository.js +1 -11
- package/dist/src/code-intelligence/types.d.ts +0 -8
- package/dist/src/codex-auth.d.ts +0 -44
- package/dist/src/codex-auth.js +0 -45
- package/dist/src/codex-browser-auth.d.ts +0 -13
- package/dist/src/codex-browser-auth.js +3 -20
- package/dist/src/codex-errors.js +0 -2
- package/dist/src/codex-executable.d.ts +0 -2
- package/dist/src/codex-executable.js +1 -7
- package/dist/src/codex-provider.d.ts +0 -13
- package/dist/src/codex-provider.js +1 -26
- package/dist/src/codex-rpc.d.ts +0 -10
- package/dist/src/codex-rpc.js +0 -12
- package/dist/src/coding-tools.d.ts +6 -27
- package/dist/src/coding-tools.js +193 -205
- package/dist/src/command-metrics.d.ts +0 -4
- package/dist/src/command-output-tap.d.ts +0 -11
- package/dist/src/command-output-tap.js +0 -3
- package/dist/src/command-screens.d.ts +24 -0
- package/dist/src/command-screens.js +132 -100
- package/dist/src/commands.d.ts +6 -63
- package/dist/src/commands.js +20 -100
- package/dist/src/completion-gates.d.ts +0 -47
- package/dist/src/completion-gates.js +0 -14
- package/dist/src/completion.d.ts +2 -58
- package/dist/src/completion.js +90 -186
- package/dist/src/config.d.ts +12 -116
- package/dist/src/config.js +41 -171
- package/dist/src/context-budget.d.ts +0 -22
- package/dist/src/context-budget.js +0 -44
- package/dist/src/context-compaction.d.ts +29 -6
- package/dist/src/context-compaction.js +94 -25
- package/dist/src/context-selection.d.ts +0 -24
- package/dist/src/context-selection.js +0 -34
- package/dist/src/dashboard-view.d.ts +0 -2
- package/dist/src/dashboard-view.js +0 -35
- package/dist/src/dashboard.d.ts +0 -2
- package/dist/src/dashboard.js +0 -9
- package/dist/src/deadline.d.ts +0 -45
- package/dist/src/deadline.js +0 -54
- package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
- package/dist/src/decision/ContinuationAdapter.js +0 -5
- package/dist/src/decision/DecisionEngine.d.ts +0 -4
- package/dist/src/decision/DecisionManager.d.ts +0 -1
- package/dist/src/decision/DecisionManager.js +2 -7
- package/dist/src/decision/DecisionPolicy.d.ts +0 -1
- package/dist/src/decision/DecisionPolicy.js +0 -1
- package/dist/src/decision/FactContinuations.d.ts +11 -43
- package/dist/src/decision/FactContinuations.js +126 -95
- package/dist/src/decision/FactServiceGate.d.ts +0 -1
- package/dist/src/decision/FactServiceGate.js +0 -4
- package/dist/src/decision/PreparedSteps.d.ts +0 -15
- package/dist/src/decision/PreparedSteps.js +1 -11
- package/dist/src/decision/applyToolMenu.d.ts +0 -1
- package/dist/src/decision/applyToolMenu.js +1 -5
- package/dist/src/decision/checks.d.ts +15 -28
- package/dist/src/decision/checks.js +118 -49
- package/dist/src/decision/facts.d.ts +0 -16
- package/dist/src/decision/facts.js +0 -30
- package/dist/src/decision/guidancePolicy.js +0 -1
- package/dist/src/decision/hostedPolicy.d.ts +0 -6
- package/dist/src/decision/hostedPolicy.js +0 -7
- package/dist/src/decision/hostedSkills.d.ts +0 -19
- package/dist/src/decision/hostedSkills.js +0 -19
- package/dist/src/decision/optimizationPolicy.d.ts +0 -3
- package/dist/src/decision/optimizationPolicy.js +1 -4
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
- package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
- package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
- package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
- package/dist/src/decision/routeTools.d.ts +0 -8
- package/dist/src/decision/routeTools.js +1 -8
- package/dist/src/decision/toolFamilies.d.ts +0 -1
- package/dist/src/decision/toolFamilies.js +0 -1
- package/dist/src/decision/toolMenu.d.ts +0 -3
- package/dist/src/decision/toolMenu.js +0 -4
- package/dist/src/decision/types.d.ts +0 -6
- package/dist/src/default-graph.d.ts +0 -9
- package/dist/src/default-graph.js +0 -9
- package/dist/src/delegation-changes.d.ts +0 -56
- package/dist/src/delegation-changes.js +15 -124
- package/dist/src/diff-preview.d.ts +1 -1
- package/dist/src/diff-preview.js +4 -12
- package/dist/src/duration.d.ts +0 -50
- package/dist/src/duration.js +0 -50
- package/dist/src/efficiency.d.ts +0 -39
- package/dist/src/efficiency.js +0 -16
- package/dist/src/engine/protocol.d.ts +0 -2
- package/dist/src/engine/protocol.js +0 -2
- package/dist/src/engine-streams.d.ts +13 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.d.ts +3 -2
- package/dist/src/extensions.js +76 -37
- package/dist/src/favicons.d.ts +0 -26
- package/dist/src/favicons.js +0 -34
- package/dist/src/file-diff.d.ts +2 -58
- package/dist/src/file-diff.js +0 -32
- package/dist/src/file-read-key.d.ts +1 -0
- package/dist/src/file-read-key.js +5 -0
- package/dist/src/file-read-state.d.ts +0 -1
- package/dist/src/file-read-state.js +0 -4
- package/dist/src/firefox-cookies.d.ts +0 -34
- package/dist/src/firefox-cookies.js +1 -55
- package/dist/src/git-identity-audit.d.ts +27 -0
- package/dist/src/git-identity-audit.js +286 -0
- package/dist/src/git-identity-guard.d.ts +4 -0
- package/dist/src/git-identity-guard.js +998 -0
- package/dist/src/git-identity-hold.d.ts +12 -0
- package/dist/src/git-identity-hold.js +81 -0
- package/dist/src/git-summary.d.ts +0 -58
- package/dist/src/git-summary.js +2 -212
- package/dist/src/goal-completion-verification.d.ts +2 -2
- package/dist/src/goal-completion-verification.js +3 -6
- package/dist/src/graph-account.d.ts +0 -21
- package/dist/src/graph-account.js +0 -17
- package/dist/src/graph-editor-session.d.ts +0 -1
- package/dist/src/graph-editor-session.js +1 -3
- package/dist/src/graph-health.d.ts +7 -49
- package/dist/src/graph-health.js +35 -46
- package/dist/src/graph-manager-chat.d.ts +27 -128
- package/dist/src/graph-manager-chat.js +36 -166
- package/dist/src/graph-provider-portability.d.ts +1 -21
- package/dist/src/graph-provider-portability.js +6 -45
- package/dist/src/graph-quota.d.ts +0 -33
- package/dist/src/graph-quota.js +1 -44
- package/dist/src/graph-runner.d.ts +0 -1
- package/dist/src/graph-runner.js +47 -387
- package/dist/src/graph-selection.d.ts +0 -14
- package/dist/src/graph-selection.js +0 -14
- package/dist/src/graph-server.d.ts +3 -11
- package/dist/src/graph-server.js +70 -111
- package/dist/src/graph-studio-features.d.ts +0 -5
- package/dist/src/graph-studio-features.js +2 -42
- package/dist/src/graph-sync.d.ts +0 -78
- package/dist/src/graph-sync.js +5 -201
- package/dist/src/graph-tool.d.ts +0 -18
- package/dist/src/graph-tool.js +0 -27
- package/dist/src/graph-ui/app.js +229 -498
- package/dist/src/graph-ui/compat.js +0 -7
- package/dist/src/graph-ui/controls.css +47 -43
- package/dist/src/graph-ui/controls.js +0 -88
- package/dist/src/graph-ui/drafts.js +0 -12
- package/dist/src/graph-ui/edge-router.js +0 -62
- package/dist/src/graph-ui/embed.js +0 -59
- package/dist/src/graph-ui/icons.js +2 -7
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/library.css +0 -5
- package/dist/src/graph-ui/manager-markdown.js +0 -11
- package/dist/src/graph-ui/manager-state.js +110 -49
- package/dist/src/graph-ui/manager.css +2 -20
- package/dist/src/graph-ui/manager.js +251 -166
- package/dist/src/graph-ui/model-picker.js +250 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graph-ui/sidebar.js +2 -3
- package/dist/src/graph-ui/skill-picker.js +373 -39
- package/dist/src/graph-ui/studio-canvas.js +3 -38
- package/dist/src/graph-ui/studio.css +0 -18
- package/dist/src/graph-ui/studio.js +3 -71
- package/dist/src/graph-ui/style.css +11 -134
- package/dist/src/graph-ui/theme.js +1 -26
- package/dist/src/graph-ui/tokens.css +15 -114
- package/dist/src/graphs.d.ts +7 -156
- package/dist/src/graphs.js +72 -273
- package/dist/src/grep-regex-worker.js +0 -2
- package/dist/src/grep-regex.d.ts +1 -5
- package/dist/src/grep-regex.js +6 -8
- package/dist/src/grok-provider.d.ts +0 -17
- package/dist/src/grok-provider.js +1 -26
- package/dist/src/handoffs.d.ts +0 -11
- package/dist/src/handoffs.js +0 -13
- package/dist/src/hardened-runtime.d.ts +0 -10
- package/dist/src/hardened-runtime.js +8 -46
- package/dist/src/harness-home.d.ts +21 -0
- package/dist/src/harness-home.js +87 -0
- package/dist/src/host-process-guard.d.ts +0 -50
- package/dist/src/host-process-guard.js +0 -641
- package/dist/src/limits.d.ts +0 -64
- package/dist/src/limits.js +0 -62
- package/dist/src/managed-sign-in.d.ts +0 -12
- package/dist/src/managed-sign-in.js +0 -16
- package/dist/src/markdown.d.ts +0 -28
- package/dist/src/markdown.js +1 -175
- package/dist/src/mcp.d.ts +21 -82
- package/dist/src/mcp.js +228 -237
- package/dist/src/membership-errors.d.ts +0 -14
- package/dist/src/membership-errors.js +0 -13
- package/dist/src/membership.d.ts +2 -60
- package/dist/src/membership.js +0 -85
- package/dist/src/memory/LocalToolMemory.d.ts +0 -1
- package/dist/src/memory/LocalToolMemory.js +2 -7
- package/dist/src/memory/MemoryDistiller.js +0 -15
- package/dist/src/memory/MemoryManager.d.ts +0 -3
- package/dist/src/memory/MemoryManager.js +6 -18
- package/dist/src/memory/MemoryPolicy.d.ts +0 -2
- package/dist/src/memory/MemoryPolicy.js +0 -2
- package/dist/src/memory/MemoryProvider.d.ts +0 -6
- package/dist/src/memory/MemoryRetriever.js +0 -7
- package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
- package/dist/src/memory/PermissionMemoryProvider.js +0 -1
- package/dist/src/memory/ProjectMemory.d.ts +42 -0
- package/dist/src/memory/ProjectMemory.js +285 -0
- package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
- package/dist/src/memory/ToolFailureLessons.js +0 -6
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
- package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
- package/dist/src/memory/redaction.d.ts +0 -5
- package/dist/src/memory/redaction.js +0 -11
- package/dist/src/memory/repository.d.ts +0 -6
- package/dist/src/memory/repository.js +2 -12
- package/dist/src/memory/types.d.ts +0 -1
- package/dist/src/model-health-cache.d.ts +0 -38
- package/dist/src/model-health-cache.js +1 -49
- package/dist/src/model-metadata.d.ts +0 -18
- package/dist/src/model-metadata.js +2 -42
- package/dist/src/model-override.d.ts +0 -36
- package/dist/src/model-override.js +0 -43
- package/dist/src/model-tiers.d.ts +0 -13
- package/dist/src/model-tiers.js +0 -23
- package/dist/src/opencode-catalog.d.ts +0 -2
- package/dist/src/opencode-catalog.js +0 -11
- package/dist/src/opencode-cli-provider.d.ts +0 -35
- package/dist/src/opencode-cli-provider.js +1 -44
- package/dist/src/opencode-provider.d.ts +0 -2
- package/dist/src/opencode-provider.js +6 -22
- package/dist/src/package-name.d.ts +1 -0
- package/dist/src/package-name.js +1 -0
- package/dist/src/paged-transcript.d.ts +0 -11
- package/dist/src/paged-transcript.js +2 -20
- package/dist/src/palette.d.ts +0 -63
- package/dist/src/palette.js +0 -63
- package/dist/src/permissions.d.ts +0 -15
- package/dist/src/permissions.js +0 -17
- package/dist/src/powershell-pool.d.ts +0 -9
- package/dist/src/powershell-pool.js +3 -26
- package/dist/src/process-warnings.d.ts +4 -0
- package/dist/src/process-warnings.js +103 -0
- package/dist/src/profile.d.ts +0 -43
- package/dist/src/profile.js +0 -43
- package/dist/src/project-reservation.d.ts +11 -0
- package/dist/src/project-reservation.js +143 -0
- package/dist/src/provider-connection.d.ts +0 -18
- package/dist/src/provider-connection.js +0 -39
- package/dist/src/provider-engine.d.ts +0 -21
- package/dist/src/provider-engine.js +3 -98
- package/dist/src/provider-import.d.ts +0 -49
- package/dist/src/provider-import.js +0 -60
- package/dist/src/provider-keys.d.ts +1 -36
- package/dist/src/provider-keys.js +5 -48
- package/dist/src/provider-settings.d.ts +0 -2
- package/dist/src/provider-settings.js +0 -32
- package/dist/src/providers.d.ts +0 -217
- package/dist/src/providers.js +0 -315
- package/dist/src/pull-requests.d.ts +0 -173
- package/dist/src/pull-requests.js +5 -195
- package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
- package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
- package/dist/src/qa/command-policy.d.ts +0 -23
- package/dist/src/qa/command-policy.js +0 -30
- package/dist/src/qa/guidance.d.ts +0 -21
- package/dist/src/qa/guidance.js +0 -20
- package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
- package/dist/src/qa/profile/ProjectInspector.js +0 -6
- package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
- package/dist/src/qa/profile/QaConfigLoader.js +0 -6
- package/dist/src/qa/profile/QaProfile.d.ts +0 -7
- package/dist/src/qa/profile/QaProfile.js +0 -7
- package/dist/src/qa/profile/yaml.d.ts +0 -9
- package/dist/src/qa/profile/yaml.js +0 -13
- package/dist/src/qa/qa-authorize.d.ts +0 -19
- package/dist/src/qa/qa-authorize.js +4 -11
- package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
- package/dist/src/qa/runtime/ProcessManager.js +4 -41
- package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
- package/dist/src/qa/runtime/PtyManager.js +2 -7
- package/dist/src/qa/runtime/changes.d.ts +0 -11
- package/dist/src/qa/runtime/changes.js +1 -3
- package/dist/src/qa/tools.d.ts +0 -10
- package/dist/src/qa/tools.js +0 -12
- package/dist/src/qa/types.d.ts +0 -13
- package/dist/src/react-runtime.d.ts +2 -21
- package/dist/src/react-runtime.js +106 -418
- package/dist/src/read-document-doc.d.ts +0 -6
- package/dist/src/read-document-doc.js +0 -55
- package/dist/src/read-document-docx.d.ts +0 -16
- package/dist/src/read-document-docx.js +2 -69
- package/dist/src/read-document-text.d.ts +0 -17
- package/dist/src/read-document-text.js +0 -22
- package/dist/src/read-document-tool.d.ts +0 -31
- package/dist/src/read-document-tool.js +0 -30
- package/dist/src/read-document.d.ts +0 -49
- package/dist/src/read-document.js +1 -67
- package/dist/src/read-image.d.ts +0 -32
- package/dist/src/read-image.js +0 -33
- package/dist/src/remote/cert.d.ts +1 -19
- package/dist/src/remote/cert.js +2 -51
- package/dist/src/remote/client.d.ts +0 -70
- package/dist/src/remote/client.js +2 -117
- package/dist/src/remote/command.js +0 -17
- package/dist/src/remote/engine-pool.d.ts +0 -152
- package/dist/src/remote/engine-pool.js +17 -335
- package/dist/src/remote/errors.d.ts +0 -15
- package/dist/src/remote/errors.js +0 -7
- package/dist/src/remote/network.d.ts +0 -26
- package/dist/src/remote/network.js +1 -34
- package/dist/src/remote/pairing.d.ts +16 -51
- package/dist/src/remote/pairing.js +50 -57
- package/dist/src/remote/pem.d.ts +2 -0
- package/dist/src/remote/pem.js +7 -0
- package/dist/src/remote/roots.d.ts +0 -20
- package/dist/src/remote/roots.js +0 -8
- package/dist/src/remote/serve.d.ts +0 -47
- package/dist/src/remote/serve.js +0 -30
- package/dist/src/remote/server.d.ts +0 -14
- package/dist/src/remote/server.js +1 -79
- package/dist/src/remote/types.d.ts +1 -32
- package/dist/src/remote/types.js +0 -10
- package/dist/src/run-control.d.ts +0 -7
- package/dist/src/run-control.js +0 -7
- package/dist/src/run-progress.d.ts +0 -170
- package/dist/src/run-progress.js +0 -285
- package/dist/src/run-records.d.ts +0 -443
- package/dist/src/run-records.js +44 -678
- package/dist/src/run-temp.d.ts +12 -0
- package/dist/src/run-temp.js +50 -0
- package/dist/src/runtime.d.ts +11 -227
- package/dist/src/runtime.js +0 -127
- package/dist/src/sandbox-child.js +0 -1
- package/dist/src/save-lock.d.ts +0 -12
- package/dist/src/save-lock.js +0 -28
- package/dist/src/screen-selection.d.ts +0 -23
- package/dist/src/screen-selection.js +0 -22
- package/dist/src/secret-redaction.d.ts +0 -12
- package/dist/src/secret-redaction.js +0 -45
- package/dist/src/session-changes.d.ts +4 -80
- package/dist/src/session-changes.js +25 -130
- package/dist/src/session-goal.d.ts +129 -0
- package/dist/src/session-goal.js +230 -0
- package/dist/src/session-monitor.d.ts +1 -10
- package/dist/src/session-monitor.js +2 -39
- package/dist/src/session-reaper.d.ts +0 -15
- package/dist/src/session-reaper.js +0 -14
- package/dist/src/session-skills.d.ts +15 -44
- package/dist/src/session-skills.js +75 -60
- package/dist/src/session-summary.d.ts +0 -26
- package/dist/src/session-summary.js +0 -32
- package/dist/src/session-title.d.ts +0 -1
- package/dist/src/session-title.js +0 -2
- package/dist/src/sessions.d.ts +2 -120
- package/dist/src/sessions.js +9 -178
- package/dist/src/shell.d.ts +3 -20
- package/dist/src/shell.js +8 -72
- package/dist/src/side-panel.d.ts +5 -99
- package/dist/src/side-panel.js +76 -133
- package/dist/src/sign-in-detection.d.ts +43 -0
- package/dist/src/sign-in-detection.js +154 -0
- package/dist/src/sign-in-offer.d.ts +17 -0
- package/dist/src/sign-in-offer.js +103 -0
- package/dist/src/skill-commands.d.ts +0 -1
- package/dist/src/skill-commands.js +1 -4
- package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/invocable-skills.d.ts +0 -18
- package/dist/src/skills/invocable-skills.js +0 -17
- package/dist/src/skills/project-skills.d.ts +0 -1
- package/dist/src/skills/project-skills.js +0 -3
- package/dist/src/skills/prompt-skills.js +0 -14
- package/dist/src/skills/runtime-skills.d.ts +1 -8
- package/dist/src/skills/runtime-skills.js +8 -32
- package/dist/src/stall-recovery.d.ts +0 -25
- package/dist/src/stall-recovery.js +0 -38
- package/dist/src/stray-files.d.ts +5 -0
- package/dist/src/stray-files.js +65 -0
- package/dist/src/structured-step.d.ts +0 -22
- package/dist/src/structured-step.js +0 -22
- package/dist/src/subagent-run.d.ts +0 -163
- package/dist/src/subagent-run.js +10 -374
- package/dist/src/subagent-tree.d.ts +32 -0
- package/dist/src/subagent-tree.js +128 -0
- package/dist/src/telemetry/aggregate.d.ts +0 -37
- package/dist/src/telemetry/aggregate.js +0 -40
- package/dist/src/telemetry/capture-core.d.ts +0 -87
- package/dist/src/telemetry/capture-core.js +0 -67
- package/dist/src/telemetry/capture.d.ts +0 -1
- package/dist/src/telemetry/capture.js +0 -3
- package/dist/src/telemetry/classify.d.ts +0 -58
- package/dist/src/telemetry/classify.js +0 -60
- package/dist/src/telemetry/decision-capture.d.ts +0 -1
- package/dist/src/telemetry/emitter.d.ts +0 -30
- package/dist/src/telemetry/emitter.js +1 -62
- package/dist/src/telemetry/gate.d.ts +0 -29
- package/dist/src/telemetry/gate.js +0 -22
- package/dist/src/telemetry/identity.d.ts +0 -13
- package/dist/src/telemetry/identity.js +0 -29
- package/dist/src/telemetry/outbox.d.ts +0 -64
- package/dist/src/telemetry/outbox.js +1 -108
- package/dist/src/telemetry/schema.d.ts +1 -49
- package/dist/src/telemetry/schema.js +1 -82
- package/dist/src/telemetry/state.d.ts +0 -53
- package/dist/src/telemetry/state.js +0 -64
- package/dist/src/telemetry/surface.d.ts +0 -31
- package/dist/src/telemetry/surface.js +1 -39
- package/dist/src/telemetry/uploader.d.ts +0 -11
- package/dist/src/telemetry/uploader.js +0 -46
- package/dist/src/telemetry/uploads.d.ts +0 -11
- package/dist/src/telemetry/uploads.js +0 -11
- package/dist/src/telemetry/version.d.ts +0 -4
- package/dist/src/telemetry/version.js +0 -14
- package/dist/src/telemetry/workspace.d.ts +0 -7
- package/dist/src/telemetry/workspace.js +1 -22
- package/dist/src/terminal-ui.d.ts +15 -524
- package/dist/src/terminal-ui.js +80 -876
- package/dist/src/test-edit-guard.d.ts +74 -0
- package/dist/src/test-edit-guard.js +269 -0
- package/dist/src/text.d.ts +0 -1
- package/dist/src/text.js +0 -1
- package/dist/src/time-limit.d.ts +0 -36
- package/dist/src/time-limit.js +0 -37
- package/dist/src/timers.d.ts +0 -161
- package/dist/src/timers.js +0 -126
- package/dist/src/todos.d.ts +0 -1
- package/dist/src/todos.js +0 -3
- package/dist/src/token-rate.d.ts +0 -94
- package/dist/src/token-rate.js +0 -154
- package/dist/src/tool-activity.d.ts +0 -6
- package/dist/src/tool-activity.js +1 -8
- package/dist/src/tool-availability.d.ts +0 -13
- package/dist/src/tool-availability.js +1 -14
- package/dist/src/tool-call-clock.d.ts +1 -4
- package/dist/src/tool-call-clock.js +0 -13
- package/dist/src/tool-catalog.d.ts +0 -11
- package/dist/src/tool-catalog.js +0 -23
- package/dist/src/tool-dependencies.d.ts +0 -5
- package/dist/src/tool-dependencies.js +0 -4
- package/dist/src/tool-diff-stats.d.ts +0 -23
- package/dist/src/tool-diff-stats.js +0 -49
- package/dist/src/tool-errors.d.ts +9 -7
- package/dist/src/tool-errors.js +13 -6
- package/dist/src/tool-failure-tracker.d.ts +3 -11
- package/dist/src/tool-failure-tracker.js +19 -27
- package/dist/src/tool-names.d.ts +0 -16
- package/dist/src/tool-names.js +0 -12
- package/dist/src/tool-profile.d.ts +6 -0
- package/dist/src/tool-profile.js +23 -0
- package/dist/src/tool-result-filter.d.ts +0 -19
- package/dist/src/tool-result-filter.js +1 -66
- package/dist/src/tool-schema-compatibility.d.ts +1 -2
- package/dist/src/tool-schema-compatibility.js +2 -7
- package/dist/src/tools.d.ts +0 -4
- package/dist/src/tools.js +11 -114
- package/dist/src/trajectory.d.ts +0 -13
- package/dist/src/trajectory.js +23 -79
- package/dist/src/transcript.d.ts +1 -37
- package/dist/src/transcript.js +11 -61
- package/dist/src/types.d.ts +2 -167
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +105 -0
- package/dist/src/update-check.d.ts +0 -14
- package/dist/src/update-check.js +2 -16
- package/dist/src/update.d.ts +4 -29
- package/dist/src/update.js +20 -98
- package/dist/src/usage-analytics.d.ts +17 -17
- package/dist/src/usage-analytics.js +168 -209
- package/dist/src/web-search.d.ts +0 -23
- package/dist/src/web-search.js +1 -27
- package/dist/src/widgets.d.ts +0 -25
- package/dist/src/widgets.js +0 -24
- package/dist/src/workspace-facts.d.ts +0 -12
- package/dist/src/workspace-facts.js +1 -18
- package/dist/src/workspace-git-metadata.d.ts +4 -5
- package/dist/src/workspace-git-metadata.js +37 -9
- package/dist/src/workspace-instructions.d.ts +3 -15
- package/dist/src/workspace-instructions.js +7 -20
- package/package.json +2 -2
|
@@ -3,16 +3,10 @@ interface CompoundEntry {
|
|
|
3
3
|
size: number;
|
|
4
4
|
}
|
|
5
5
|
export interface CompoundFile {
|
|
6
|
-
/** Streams directly under the root storage, by name. */
|
|
7
6
|
streams: Map<string, CompoundEntry>;
|
|
8
7
|
read(entry: CompoundEntry): Buffer;
|
|
9
8
|
}
|
|
10
|
-
/** Open a Compound File Binary container. Throws when its structure cannot be followed. */
|
|
11
9
|
export declare function openCompoundFile(bytes: Buffer): CompoundFile;
|
|
12
|
-
/**
|
|
13
|
-
* Text of a legacy Word document, or undefined when the compound file holds something else
|
|
14
|
-
* (an `.xls`, a `.ppt`, an `.msi`), so the caller can report it as the binary file it is.
|
|
15
|
-
*/
|
|
16
10
|
export declare function extractDoc(bytes: Buffer): {
|
|
17
11
|
text: string;
|
|
18
12
|
notes: string[];
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import { decodeWindows1252, headingBlock, joinBlocks, listBlock, rowBlock, tidyText } from './read-document-text.js';
|
|
2
|
-
/**
|
|
3
|
-
* Word 97-2003 `.doc` to plain text, without a dependency.
|
|
4
|
-
*
|
|
5
|
-
* A `.doc` is a Compound File (a small FAT file system in one file) holding a `WordDocument`
|
|
6
|
-
* stream and a table stream. The text is not stored as one run: a piece table in the table stream
|
|
7
|
-
* maps character positions to byte ranges of `WordDocument`, each either 8-bit Windows-1252 or
|
|
8
|
-
* UTF-16. Paragraph properties live in a second structure keyed by file offset, and they are the
|
|
9
|
-
* only way to tell a table row's end mark from an empty cell or a heading from body text, so this
|
|
10
|
-
* reads those too.
|
|
11
|
-
*
|
|
12
|
-
* Structure names and offsets follow Microsoft's [MS-CFB] and [MS-DOC] specifications. Every
|
|
13
|
-
* offset and length comes from the file and is bounds-checked: a wrong one must end in a clear
|
|
14
|
-
* error, never in an endless chain walk or a read past the buffer.
|
|
15
|
-
*/
|
|
16
2
|
const corrupt = (reason) => new Error(`This .doc is damaged (${reason}), so Read cannot open it. Ask for the document to be exported again as .docx or PDF.`);
|
|
17
|
-
/** Sector numbers at or above this are markers (free, end of chain, FAT, DIFAT), not sectors. */
|
|
18
3
|
const MAX_REGULAR_SECTOR = 0xfffffffa;
|
|
19
|
-
/** Open a Compound File Binary container. Throws when its structure cannot be followed. */
|
|
20
4
|
export function openCompoundFile(bytes) {
|
|
21
5
|
const broken = (reason) => new Error(`compound file: ${reason}`);
|
|
22
6
|
if (bytes.length < 512)
|
|
@@ -29,12 +13,10 @@ export function openCompoundFile(bytes) {
|
|
|
29
13
|
const perSector = sectorSize / 4;
|
|
30
14
|
const sector = (index) => {
|
|
31
15
|
const offset = (index + 1) * sectorSize;
|
|
32
|
-
// Writers that do not pad the last sector exist, so a short final sector is accepted.
|
|
33
16
|
if (index >= sectorCount || offset >= bytes.length)
|
|
34
17
|
throw broken('a sector lies outside the file');
|
|
35
18
|
return bytes.subarray(offset, offset + sectorSize);
|
|
36
19
|
};
|
|
37
|
-
// The first 109 FAT sector numbers are in the header; larger files chain more through DIFAT sectors.
|
|
38
20
|
const fatSectors = [];
|
|
39
21
|
for (let index = 0; index < 109; index++) {
|
|
40
22
|
const value = bytes.readUInt32LE(76 + index * 4);
|
|
@@ -68,7 +50,6 @@ export function openCompoundFile(bytes) {
|
|
|
68
50
|
const parts = [];
|
|
69
51
|
let length = 0;
|
|
70
52
|
for (let index = start; index < MAX_REGULAR_SECTOR && (size === undefined || length < size); index = following(index)) {
|
|
71
|
-
// A chain cannot be longer than the file has sectors, so a longer one is a loop.
|
|
72
53
|
if (parts.length > sectorCount)
|
|
73
54
|
throw broken('a sector chain loops');
|
|
74
55
|
const block = sector(index);
|
|
@@ -86,7 +67,6 @@ export function openCompoundFile(bytes) {
|
|
|
86
67
|
if (offset + 128 > directory.length)
|
|
87
68
|
return undefined;
|
|
88
69
|
const nameBytes = Math.min(Math.max(directory.readUInt16LE(offset + 64) - 2, 0), 62);
|
|
89
|
-
// Version 3 files may leave garbage in the high half of the size; no stream here can exceed 4 GiB anyway.
|
|
90
70
|
if (sectorShift === 12 && directory.readUInt32LE(offset + 124) !== 0)
|
|
91
71
|
throw broken('a stream is larger than 4 GiB');
|
|
92
72
|
return {
|
|
@@ -98,7 +78,6 @@ export function openCompoundFile(bytes) {
|
|
|
98
78
|
const root = entryAt(0);
|
|
99
79
|
if (!root || root.type !== 5)
|
|
100
80
|
throw broken('no root entry');
|
|
101
|
-
// A storage's children form a binary tree linked by sibling ids. Only the root level is needed.
|
|
102
81
|
const streams = new Map();
|
|
103
82
|
const seen = new Set();
|
|
104
83
|
const pending = [root.child];
|
|
@@ -114,7 +93,6 @@ export function openCompoundFile(bytes) {
|
|
|
114
93
|
streams.set(entry.name, { start: entry.start, size: entry.size });
|
|
115
94
|
pending.push(entry.left, entry.right);
|
|
116
95
|
}
|
|
117
|
-
// Streams under the cutoff live in 64-byte mini sectors inside the root entry's own stream.
|
|
118
96
|
const miniCutoff = bytes.readUInt32LE(56);
|
|
119
97
|
let mini;
|
|
120
98
|
const read = (entry) => {
|
|
@@ -133,14 +111,11 @@ export function openCompoundFile(bytes) {
|
|
|
133
111
|
return { streams, read };
|
|
134
112
|
}
|
|
135
113
|
const PLAIN = { style: 0, inTable: false, rowEnd: false, list: false, level: 0, innerCell: false, innerRowEnd: false };
|
|
136
|
-
/** Operand bytes by the three size bits of a property modifier; -1 means the operand carries its own length. */
|
|
137
114
|
const OPERAND_SIZE = [1, 1, 2, 4, 2, 2, -1, 3];
|
|
138
|
-
/** One paragraph's style index and the few property modifiers that change how its text should read. */
|
|
139
115
|
function readParagraphProperties(page, offset) {
|
|
140
116
|
const properties = { ...PLAIN };
|
|
141
117
|
if (offset + 1 >= page.length)
|
|
142
118
|
return properties;
|
|
143
|
-
// The size is counted in words; a zero first byte means the real count follows in the next byte.
|
|
144
119
|
let start = offset + 1;
|
|
145
120
|
let length = page[offset] * 2 - 1;
|
|
146
121
|
if (page[offset] === 0) {
|
|
@@ -158,8 +133,6 @@ function readParagraphProperties(page, offset) {
|
|
|
158
133
|
if (size < 0) {
|
|
159
134
|
if (position >= end)
|
|
160
135
|
break;
|
|
161
|
-
// Two modifiers break the one-byte length rule: the table definition counts in a 16-bit
|
|
162
|
-
// field, and a tab change of length 255 is sized by its two inner arrays.
|
|
163
136
|
if (code === 0xd608)
|
|
164
137
|
size = position + 2 <= end ? page.readUInt16LE(position) + 1 : end;
|
|
165
138
|
else if (code === 0xc615 && page[position] === 255) {
|
|
@@ -207,7 +180,6 @@ function readParagraphProperties(page, offset) {
|
|
|
207
180
|
}
|
|
208
181
|
return properties;
|
|
209
182
|
}
|
|
210
|
-
/** Paragraph properties for every paragraph, as ranges of `WordDocument` file offsets, sorted. */
|
|
211
183
|
function readPropertyRuns(document, table) {
|
|
212
184
|
const offset = document.readUInt32LE(0x102);
|
|
213
185
|
const length = document.readUInt32LE(0x106);
|
|
@@ -230,13 +202,11 @@ function readPropertyRuns(document, table) {
|
|
|
230
202
|
}
|
|
231
203
|
return runs.sort((a, b) => a.start - b.start);
|
|
232
204
|
}
|
|
233
|
-
/** The main document's text, one UTF-16 code unit per character position, and where each piece sits in the stream. */
|
|
234
205
|
function readPieces(document, table, characters) {
|
|
235
206
|
const start = document.readUInt32LE(0x1a2);
|
|
236
207
|
const end = start + document.readUInt32LE(0x1a6);
|
|
237
208
|
if (end > table.length || end <= start)
|
|
238
209
|
throw corrupt('the text index is missing');
|
|
239
|
-
// Property modifier blocks come first; the piece table is the block of type 2.
|
|
240
210
|
let position = start;
|
|
241
211
|
while (position < end && table[position] === 1)
|
|
242
212
|
position += 3 + (position + 3 <= end ? table.readUInt16LE(position + 1) : end);
|
|
@@ -258,7 +228,6 @@ function readPieces(document, table, characters) {
|
|
|
258
228
|
if (last <= first)
|
|
259
229
|
continue;
|
|
260
230
|
const descriptor = table.readUInt32LE(position + (count + 1) * 4 + index * 8 + 2);
|
|
261
|
-
// Bit 30 marks 8-bit text, whose stored offset is twice the real one.
|
|
262
231
|
const narrow = (descriptor & 0x40000000) !== 0;
|
|
263
232
|
const offset = narrow ? (descriptor & 0x3fffffff) >>> 1 : descriptor & 0x3fffffff;
|
|
264
233
|
const width = narrow ? 1 : 2;
|
|
@@ -272,16 +241,11 @@ function readPieces(document, table, characters) {
|
|
|
272
241
|
}
|
|
273
242
|
return { text: parts.join(''), pieces };
|
|
274
243
|
}
|
|
275
|
-
/**
|
|
276
|
-
* Text of a legacy Word document, or undefined when the compound file holds something else
|
|
277
|
-
* (an `.xls`, a `.ppt`, an `.msi`), so the caller can report it as the binary file it is.
|
|
278
|
-
*/
|
|
279
244
|
export function extractDoc(bytes) {
|
|
280
245
|
try {
|
|
281
246
|
return readDoc(bytes);
|
|
282
247
|
}
|
|
283
248
|
catch (error) {
|
|
284
|
-
// A read past the end of a stream means an offset in the file was wrong, not that Read is broken.
|
|
285
249
|
if (error instanceof RangeError)
|
|
286
250
|
throw corrupt('an offset points outside the file');
|
|
287
251
|
throw error;
|
|
@@ -293,15 +257,11 @@ function readDoc(bytes) {
|
|
|
293
257
|
container = openCompoundFile(bytes);
|
|
294
258
|
}
|
|
295
259
|
catch (error) {
|
|
296
|
-
// Even a broken container shows whether it was a Word document: stream names are plain UTF-16
|
|
297
|
-
// in the directory, and when the directory itself is gone (Word writes it last, so a cut-off
|
|
298
|
-
// file loses it) the document header is still the first thing after the container header.
|
|
299
260
|
const wordHeader = bytes.length >= 514 && bytes.readUInt16LE(512) === 0xa5ec;
|
|
300
261
|
if (wordHeader || bytes.includes(Buffer.from('WordDocument', 'utf16le')))
|
|
301
262
|
throw corrupt(error.message);
|
|
302
263
|
return undefined;
|
|
303
264
|
}
|
|
304
|
-
// Office saves a password-protected .docx/.xlsx/.pptx as a compound file wrapping the encrypted package.
|
|
305
265
|
if (container.streams.has('EncryptedPackage')) {
|
|
306
266
|
throw new Error('This Office document is password-protected (encrypted), so Read cannot open it. Ask the user for an unprotected copy.');
|
|
307
267
|
}
|
|
@@ -341,8 +301,6 @@ function readDoc(bytes) {
|
|
|
341
301
|
throw corrupt('the text length is implausible');
|
|
342
302
|
const { text, pieces } = readPieces(document, table, characters);
|
|
343
303
|
const runs = readPropertyRuns(document, table);
|
|
344
|
-
// Character position -> file offset -> the property run covering it. Paragraphs are visited in
|
|
345
|
-
// order, so the piece cursor only moves forward; property runs are found by binary search.
|
|
346
304
|
let pieceIndex = 0;
|
|
347
305
|
const propertiesAt = (position) => {
|
|
348
306
|
while (pieceIndex < pieces.length - 1 && position >= pieces[pieceIndex].last)
|
|
@@ -369,7 +327,6 @@ function readDoc(bytes) {
|
|
|
369
327
|
let cellParagraphs = [];
|
|
370
328
|
let afterCell = false;
|
|
371
329
|
let drawings = 0;
|
|
372
|
-
// A field is `0x13 instruction 0x14 result 0x15`; only the result is document text. Fields nest.
|
|
373
330
|
const fields = [];
|
|
374
331
|
let hidden = 0;
|
|
375
332
|
let paragraphNumber = 0;
|
|
@@ -381,9 +338,6 @@ function readDoc(bytes) {
|
|
|
381
338
|
paragraph = '';
|
|
382
339
|
paragraphNumber++;
|
|
383
340
|
if (mark === 0x07) {
|
|
384
|
-
// Each cell ends with 0x07 and so does the row, after its last cell. Only the paragraph
|
|
385
|
-
// properties tell the row mark from an empty cell; without them, a mark straight after
|
|
386
|
-
// another one is taken to end the row.
|
|
387
341
|
const rowEnd = properties ? properties.rowEnd : afterCell && !clean && !cellParagraphs.length;
|
|
388
342
|
if (rowEnd)
|
|
389
343
|
endRow();
|
|
@@ -396,8 +350,6 @@ function readDoc(bytes) {
|
|
|
396
350
|
}
|
|
397
351
|
afterCell = false;
|
|
398
352
|
if (properties?.inTable && !properties.rowEnd && mark === 0x0d) {
|
|
399
|
-
// A nested table is flattened into its cell, keeping the separator between its own cells.
|
|
400
|
-
// The inner row's end mark carries both flags, so it is tested first.
|
|
401
353
|
if (properties.innerRowEnd) {
|
|
402
354
|
const last = cellParagraphs.pop() ?? '';
|
|
403
355
|
cellParagraphs.push(last.endsWith('|') ? last.slice(0, -1).trimEnd() : last);
|
|
@@ -414,7 +366,6 @@ function readDoc(bytes) {
|
|
|
414
366
|
endRow();
|
|
415
367
|
}
|
|
416
368
|
if (clean) {
|
|
417
|
-
// Built-in heading styles keep style indexes 1-9 in every language; other styles can still carry an outline level.
|
|
418
369
|
const style = properties?.style ?? 0;
|
|
419
370
|
const heading = style >= 1 && style <= 9 ? style : properties?.outline !== undefined && properties.outline < 9 ? properties.outline + 1 : undefined;
|
|
420
371
|
if (heading !== undefined)
|
|
@@ -428,7 +379,6 @@ function readDoc(bytes) {
|
|
|
428
379
|
let runStart = 0;
|
|
429
380
|
for (let position = 0; position <= text.length; position++) {
|
|
430
381
|
const code = position < text.length ? text.charCodeAt(position) : -1;
|
|
431
|
-
// Ordinary characters are copied in runs; only control characters need a decision.
|
|
432
382
|
if (code >= 0x20)
|
|
433
383
|
continue;
|
|
434
384
|
const field = fields[fields.length - 1];
|
|
@@ -462,7 +412,6 @@ function readDoc(bytes) {
|
|
|
462
412
|
hidden--;
|
|
463
413
|
continue;
|
|
464
414
|
}
|
|
465
|
-
// A hyperlink keeps its target in the instruction; the result is only the label.
|
|
466
415
|
const url = /^\s*HYPERLINK\s+"([^"]+)"/i.exec(field.code)?.[1];
|
|
467
416
|
const label = paragraph.slice(field.start);
|
|
468
417
|
if (!hidden && url && field.paragraph === paragraphNumber && label.trim())
|
|
@@ -480,7 +429,6 @@ function readDoc(bytes) {
|
|
|
480
429
|
case 0x09:
|
|
481
430
|
paragraph += '\t';
|
|
482
431
|
break;
|
|
483
|
-
// Manual line break and column break.
|
|
484
432
|
case 0x0b:
|
|
485
433
|
case 0x0e:
|
|
486
434
|
paragraph += '\n';
|
|
@@ -488,15 +436,12 @@ function readDoc(bytes) {
|
|
|
488
436
|
case 0x1e:
|
|
489
437
|
paragraph += '-';
|
|
490
438
|
break;
|
|
491
|
-
// Anchors of inline pictures and floating shapes.
|
|
492
439
|
case 0x01:
|
|
493
440
|
case 0x08:
|
|
494
441
|
drawings++;
|
|
495
442
|
break;
|
|
496
|
-
// The rest (footnote and comment reference marks, optional hyphens) has no text form.
|
|
497
443
|
}
|
|
498
444
|
}
|
|
499
|
-
// A file cut off mid-paragraph or mid-table still gives up what it had.
|
|
500
445
|
if (tidyText(paragraph))
|
|
501
446
|
endParagraph(text.length - 1, 0x0d);
|
|
502
447
|
if (cellParagraphs.length)
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Word `.docx` to plain text, without a dependency.
|
|
3
|
-
*
|
|
4
|
-
* A `.docx` is a ZIP of XML parts. Read needs one of them, `word/document.xml`, turned into text a
|
|
5
|
-
* model can follow: paragraphs, headings, list items and table rows. That is a small enough job
|
|
6
|
-
* that a ZIP central-directory reader and a pull tokenizer cover it, where a general OOXML library
|
|
7
|
-
* would add megabytes to every install for layout features Read throws away.
|
|
8
|
-
*
|
|
9
|
-
* The file is untrusted input. Sizes come from the archive itself, so every part is inflated under
|
|
10
|
-
* a hard budget; nothing here trusts a declared length, an offset or a nesting depth.
|
|
11
|
-
*/
|
|
12
|
-
/** Total XML one document may inflate to, across all the parts read from it. */
|
|
13
1
|
export declare const DOCX_INFLATE_LIMIT: number;
|
|
14
|
-
/**
|
|
15
|
-
* Text of a `.docx`, or undefined when the ZIP is not a Word document (a `.xlsx`, a `.jar`, any
|
|
16
|
-
* other archive), so the caller can report it as the binary file it is.
|
|
17
|
-
*/
|
|
18
2
|
export declare function extractDocx(bytes: Buffer, signal?: AbortSignal): Promise<{
|
|
19
3
|
text: string;
|
|
20
4
|
notes: string[];
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { promisify } from 'node:util';
|
|
2
2
|
import { crc32, inflateRaw } from 'node:zlib';
|
|
3
3
|
import { headingBlock, joinBlocks, listBlock, rowBlock, tidyText } from './read-document-text.js';
|
|
4
|
-
/**
|
|
5
|
-
* Word `.docx` to plain text, without a dependency.
|
|
6
|
-
*
|
|
7
|
-
* A `.docx` is a ZIP of XML parts. Read needs one of them, `word/document.xml`, turned into text a
|
|
8
|
-
* model can follow: paragraphs, headings, list items and table rows. That is a small enough job
|
|
9
|
-
* that a ZIP central-directory reader and a pull tokenizer cover it, where a general OOXML library
|
|
10
|
-
* would add megabytes to every install for layout features Read throws away.
|
|
11
|
-
*
|
|
12
|
-
* The file is untrusted input. Sizes come from the archive itself, so every part is inflated under
|
|
13
|
-
* a hard budget; nothing here trusts a declared length, an offset or a nesting depth.
|
|
14
|
-
*/
|
|
15
|
-
/** Total XML one document may inflate to, across all the parts read from it. */
|
|
16
4
|
export const DOCX_INFLATE_LIMIT = 64 * 1024 * 1024;
|
|
17
|
-
/** Tables in cells in tables: beyond this depth the content is dropped rather than recursed into. */
|
|
18
5
|
const NESTING_LIMIT = 32;
|
|
19
6
|
const inflateRawAsync = promisify(inflateRaw);
|
|
20
7
|
const damaged = (reason) => new Error(`This .docx is damaged (${reason}), so Read cannot open it. Ask for the document to be exported again, or as PDF.`);
|
|
21
|
-
/**
|
|
22
|
-
* The archive's central directory, or undefined when the bytes are not a readable ZIP.
|
|
23
|
-
* ZIP64 is reported as `'zip64'`: a real `.docx` never needs it, and following 64-bit offsets is
|
|
24
|
-
* the kind of rarely exercised path a hostile archive is built to reach.
|
|
25
|
-
*/
|
|
26
8
|
function readZipDirectory(bytes) {
|
|
27
|
-
// The end record is the last thing in the file apart from an optional comment of at most 65535 bytes.
|
|
28
9
|
let end = -1;
|
|
29
10
|
for (let offset = bytes.length - 22, floor = Math.max(0, bytes.length - 22 - 0xffff); offset >= floor; offset--) {
|
|
30
11
|
if (bytes.readUInt32LE(offset) === 0x06054b50 && offset + 22 + bytes.readUInt16LE(offset + 20) <= bytes.length) {
|
|
@@ -45,8 +26,6 @@ function readZipDirectory(bytes) {
|
|
|
45
26
|
return undefined;
|
|
46
27
|
const nameLength = bytes.readUInt16LE(offset + 28);
|
|
47
28
|
const name = bytes.toString('utf8', offset + 46, offset + 46 + nameLength);
|
|
48
|
-
// The first entry for a name wins; a second one with the same name is how an archive shows
|
|
49
|
-
// one file to a scanner and another to the reader.
|
|
50
29
|
if (!entries.has(name)) {
|
|
51
30
|
entries.set(name, {
|
|
52
31
|
flags: bytes.readUInt16LE(offset + 8), method: bytes.readUInt16LE(offset + 10), crc: bytes.readUInt32LE(offset + 16),
|
|
@@ -57,7 +36,6 @@ function readZipDirectory(bytes) {
|
|
|
57
36
|
}
|
|
58
37
|
return entries;
|
|
59
38
|
}
|
|
60
|
-
/** Inflate one part, charging its size to the document's budget. */
|
|
61
39
|
async function readZipEntry(bytes, name, entry, budget) {
|
|
62
40
|
const tooLarge = () => new Error(`This .docx expands to more than ${DOCX_INFLATE_LIMIT / 1024 / 1024} MiB of XML, which Read will not load. Unzip it and extract the text you need with a script instead.`);
|
|
63
41
|
if (entry.flags & 1)
|
|
@@ -79,7 +57,6 @@ async function readZipEntry(bytes, name, entry, budget) {
|
|
|
79
57
|
data = packed;
|
|
80
58
|
else if (entry.method === 8) {
|
|
81
59
|
try {
|
|
82
|
-
// The declared size is a claim; the output limit is what actually stops a zip bomb.
|
|
83
60
|
data = await inflateRawAsync(packed, { maxOutputLength: Math.max(budget.remaining, 1) });
|
|
84
61
|
}
|
|
85
62
|
catch (error) {
|
|
@@ -98,7 +75,6 @@ async function readZipEntry(bytes, name, entry, budget) {
|
|
|
98
75
|
return data;
|
|
99
76
|
}
|
|
100
77
|
function decodeXmlBytes(data) {
|
|
101
|
-
// Parts are UTF-8 in practice; the package format also allows UTF-16 with a byte-order mark.
|
|
102
78
|
if (data[0] === 0xff && data[1] === 0xfe)
|
|
103
79
|
return data.toString('utf16le', 2);
|
|
104
80
|
if (data[0] === 0xfe && data[1] === 0xff)
|
|
@@ -109,8 +85,6 @@ const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
|
109
85
|
function decodeEntities(text) {
|
|
110
86
|
if (!text.includes('&'))
|
|
111
87
|
return text;
|
|
112
|
-
// Only the five predefined entities and character references: a document cannot define its own
|
|
113
|
-
// here, so there is nothing to expand recursively.
|
|
114
88
|
return text.replace(/&(#x[0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-z]+);/g, (whole, body) => {
|
|
115
89
|
if (body[0] !== '#')
|
|
116
90
|
return ENTITIES[body] ?? whole;
|
|
@@ -118,26 +92,15 @@ function decodeEntities(text) {
|
|
|
118
92
|
return code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff) ? String.fromCodePoint(code) : '';
|
|
119
93
|
});
|
|
120
94
|
}
|
|
121
|
-
/**
|
|
122
|
-
* A pull tokenizer rather than a tree: `document.xml` can be tens of megabytes, and a node per
|
|
123
|
-
* element would multiply that several times over in memory for a single pass that keeps only text.
|
|
124
|
-
*/
|
|
125
95
|
class XmlReader {
|
|
126
96
|
xml;
|
|
127
97
|
position = 0;
|
|
128
|
-
/**
|
|
129
|
-
* The prefix this part binds to the WordprocessingML namespace; element names are reported with
|
|
130
|
-
* `w:`. Empty when the part binds no prefix to it and uses it as the default namespace instead.
|
|
131
|
-
*/
|
|
132
98
|
prefix;
|
|
133
|
-
/** The part declares WordprocessingML as its default namespace, so unprefixed elements belong to it. */
|
|
134
99
|
defaulted;
|
|
135
100
|
constructor(xml) {
|
|
136
101
|
this.xml = xml;
|
|
137
102
|
const head = xml.slice(0, 16384);
|
|
138
103
|
const bound = /xmlns:([A-Za-z_][\w.-]*)\s*=\s*["'](?:http:\/\/schemas\.openxmlformats\.org\/wordprocessingml\/2006\/main|http:\/\/purl\.oclc\.org\/ooxml\/wordprocessingml\/main)["']/.exec(head);
|
|
139
|
-
// `<document xmlns="…/wordprocessingml/2006/main">` is as valid as `<w:document xmlns:w="…">`.
|
|
140
|
-
// Without this an unprefixed `body` was never recognized and a full document read as empty.
|
|
141
104
|
this.defaulted = /\sxmlns\s*=\s*["'](?:http:\/\/schemas\.openxmlformats\.org\/wordprocessingml\/2006\/main|http:\/\/purl\.oclc\.org\/ooxml\/wordprocessingml\/main)["']/.test(head);
|
|
142
105
|
this.prefix = bound?.[1] ?? (this.defaulted ? '' : 'w');
|
|
143
106
|
}
|
|
@@ -145,7 +108,7 @@ class XmlReader {
|
|
|
145
108
|
const xml = this.xml;
|
|
146
109
|
while (this.position < xml.length) {
|
|
147
110
|
const start = this.position;
|
|
148
|
-
if (xml.charCodeAt(start) !== 60
|
|
111
|
+
if (xml.charCodeAt(start) !== 60) {
|
|
149
112
|
const end = xml.indexOf('<', start);
|
|
150
113
|
this.position = end < 0 ? xml.length : end;
|
|
151
114
|
return { kind: 'text', name: '', attributes: '', selfClosing: false, text: decodeEntities(xml.slice(start, this.position)) };
|
|
@@ -167,7 +130,6 @@ class XmlReader {
|
|
|
167
130
|
this.skipPast('>', start + 2);
|
|
168
131
|
continue;
|
|
169
132
|
}
|
|
170
|
-
// A quoted attribute value may contain '>', so the tag ends at the first '>' outside quotes.
|
|
171
133
|
let end = start + 1;
|
|
172
134
|
let quote = 0;
|
|
173
135
|
for (; end < xml.length; end++) {
|
|
@@ -182,7 +144,7 @@ class XmlReader {
|
|
|
182
144
|
break;
|
|
183
145
|
}
|
|
184
146
|
this.position = Math.min(end + 1, xml.length);
|
|
185
|
-
const closing = xml.charCodeAt(start + 1) === 47
|
|
147
|
+
const closing = xml.charCodeAt(start + 1) === 47;
|
|
186
148
|
const selfClosing = !closing && xml.charCodeAt(end - 1) === 47;
|
|
187
149
|
const body = xml.slice(start + (closing ? 2 : 1), selfClosing ? end - 1 : end);
|
|
188
150
|
const space = body.search(/\s/);
|
|
@@ -191,7 +153,6 @@ class XmlReader {
|
|
|
191
153
|
}
|
|
192
154
|
return undefined;
|
|
193
155
|
}
|
|
194
|
-
/** Skip to the matching close of an element whose open tag was just returned. */
|
|
195
156
|
skip(name) {
|
|
196
157
|
let depth = 1;
|
|
197
158
|
for (let token = this.next(); token; token = this.next()) {
|
|
@@ -216,12 +177,10 @@ class XmlReader {
|
|
|
216
177
|
const prefix = name.slice(0, colon);
|
|
217
178
|
if (prefix === this.prefix)
|
|
218
179
|
return `w:${name.slice(colon + 1)}`;
|
|
219
|
-
// Whatever else this part calls `w` is not WordprocessingML and must not be mistaken for it.
|
|
220
180
|
return prefix === 'w' ? `other:${name.slice(colon + 1)}` : name;
|
|
221
181
|
}
|
|
222
182
|
}
|
|
223
183
|
const attributePatterns = new Map();
|
|
224
|
-
/** An attribute by local name, whatever prefix the part uses for it. */
|
|
225
184
|
function attribute(token, localName) {
|
|
226
185
|
if (!token.attributes)
|
|
227
186
|
return undefined;
|
|
@@ -233,7 +192,6 @@ function attribute(token, localName) {
|
|
|
233
192
|
const match = pattern.exec(token.attributes);
|
|
234
193
|
return match ? decodeEntities(match[1] ?? match[2] ?? '') : undefined;
|
|
235
194
|
}
|
|
236
|
-
/** `styles.xml` reduced to what decides whether a paragraph is a heading or a list item. */
|
|
237
195
|
function readStyles(xml) {
|
|
238
196
|
const styles = new Map();
|
|
239
197
|
const reader = new XmlReader(xml);
|
|
@@ -259,7 +217,6 @@ function readStyles(xml) {
|
|
|
259
217
|
}
|
|
260
218
|
return styles;
|
|
261
219
|
}
|
|
262
|
-
/** External hyperlink targets by relationship id. */
|
|
263
220
|
function readRelationships(xml) {
|
|
264
221
|
const links = new Map();
|
|
265
222
|
const reader = new XmlReader(xml);
|
|
@@ -273,13 +230,9 @@ function readRelationships(xml) {
|
|
|
273
230
|
}
|
|
274
231
|
return links;
|
|
275
232
|
}
|
|
276
|
-
/** Subtrees that hold no document text, or text that must not be read as part of the document. */
|
|
277
233
|
const SKIPPED = new Set([
|
|
278
|
-
// The legacy rendering of a drawing: its text is already present in the mc:Choice branch.
|
|
279
234
|
'mc:Fallback',
|
|
280
|
-
// Tracked changes: the text as it reads once every change is accepted.
|
|
281
235
|
'w:del', 'w:moveFrom', 'w:pPrChange', 'w:rPrChange', 'w:tblPrChange', 'w:sectPrChange',
|
|
282
|
-
// Field instructions, binary payloads and properties.
|
|
283
236
|
'w:instrText', 'w:delText', 'w:delInstrText', 'w:fldData', 'w:binData', 'w:rPr', 'w:sectPr',
|
|
284
237
|
'w:tblPr', 'w:tblGrid', 'w:tblPrEx', 'w:trPr', 'w:tcPr', 'w:sdtPr', 'w:sdtEndPr',
|
|
285
238
|
]);
|
|
@@ -303,10 +256,6 @@ class DocxConverter {
|
|
|
303
256
|
}
|
|
304
257
|
return blocks;
|
|
305
258
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Paragraphs and tables up to the close of `container`. Anything else at this level (content
|
|
308
|
-
* controls, custom XML, tracked insertions) is a wrapper, so the loop simply reads through it.
|
|
309
|
-
*/
|
|
310
259
|
readBlocks(container, out, depth, inCell) {
|
|
311
260
|
for (let token = this.reader.next(); token; token = this.reader.next()) {
|
|
312
261
|
if (token.kind === 'close') {
|
|
@@ -355,10 +304,8 @@ class DocxConverter {
|
|
|
355
304
|
let text = '';
|
|
356
305
|
let style;
|
|
357
306
|
let outline;
|
|
358
|
-
// Undefined until the paragraph says so itself; numbering id 0 is how a paragraph opts out of its style's list.
|
|
359
307
|
let numbered;
|
|
360
308
|
let level = 0;
|
|
361
|
-
// Text boxes are anchored inside a run; their paragraphs follow the one that anchors them.
|
|
362
309
|
const anchored = [];
|
|
363
310
|
const openLinks = [];
|
|
364
311
|
const reader = this.reader;
|
|
@@ -407,7 +354,6 @@ class DocxConverter {
|
|
|
407
354
|
case 'w:ptab':
|
|
408
355
|
text += '\t';
|
|
409
356
|
break;
|
|
410
|
-
// A form feed stands in for a forced page break until the paragraph is split below.
|
|
411
357
|
case 'w:br':
|
|
412
358
|
text += attribute(token, 'type') === 'page' ? '\f' : '\n';
|
|
413
359
|
break;
|
|
@@ -467,11 +413,6 @@ class DocxConverter {
|
|
|
467
413
|
});
|
|
468
414
|
out.push(...anchored);
|
|
469
415
|
}
|
|
470
|
-
/**
|
|
471
|
-
* Heading level from the paragraph's own outline level, else from its style. The style's *name*
|
|
472
|
-
* is the stable signal: ids are localised ("berschrift1", "Titre1", "1") while Word keeps the
|
|
473
|
-
* built-in names "heading 1".."heading 9" in every language.
|
|
474
|
-
*/
|
|
475
416
|
headingLevel(styleId, outline) {
|
|
476
417
|
if (outline !== undefined && outline >= 0 && outline < 9)
|
|
477
418
|
return outline + 1;
|
|
@@ -498,16 +439,10 @@ class DocxConverter {
|
|
|
498
439
|
return false;
|
|
499
440
|
}
|
|
500
441
|
}
|
|
501
|
-
/** Content types of a main document part: documents and templates, with or without macros. */
|
|
502
442
|
const MAIN_PART_TYPE = /^application\/vnd\.(?:openxmlformats-officedocument\.wordprocessingml\.(?:document|template)|ms-word\.(?:document|template)\.macroEnabled(?:Template)?)\.main\+xml$/;
|
|
503
443
|
const plural = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
504
|
-
/**
|
|
505
|
-
* Text of a `.docx`, or undefined when the ZIP is not a Word document (a `.xlsx`, a `.jar`, any
|
|
506
|
-
* other archive), so the caller can report it as the binary file it is.
|
|
507
|
-
*/
|
|
508
444
|
export async function extractDocx(bytes, signal) {
|
|
509
445
|
const directory = readZipDirectory(bytes);
|
|
510
|
-
// Entry names are stored uncompressed, so even an unreadable archive shows whether it was a Word document.
|
|
511
446
|
const namesDocument = () => bytes.includes('word/document.xml');
|
|
512
447
|
if (directory === 'zip64') {
|
|
513
448
|
if (namesDocument())
|
|
@@ -524,14 +459,12 @@ export async function extractDocx(bytes, signal) {
|
|
|
524
459
|
const entry = directory.get(name);
|
|
525
460
|
return entry ? decodeXmlBytes(await readZipEntry(bytes, name, entry, budget)) : undefined;
|
|
526
461
|
};
|
|
527
|
-
// Supporting parts only refine the output, so one that cannot be read is ignored, not fatal.
|
|
528
462
|
const optionalPart = async (name) => { try {
|
|
529
463
|
return await part(name);
|
|
530
464
|
}
|
|
531
465
|
catch {
|
|
532
466
|
return undefined;
|
|
533
467
|
} };
|
|
534
|
-
// The package's content types name the main part; Word writes word/document.xml, other producers need not.
|
|
535
468
|
let main = 'word/document.xml';
|
|
536
469
|
const types = await optionalPart('[Content_Types].xml');
|
|
537
470
|
if (types) {
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text plumbing shared by the document readers behind Read.
|
|
3
|
-
*
|
|
4
|
-
* The Word readers (`read-document-docx.ts`, `read-document-doc.ts`) both reduce a document to the
|
|
5
|
-
* same few block shapes, and both the legacy `.doc` reader and the non-UTF-8 text path need
|
|
6
|
-
* Windows-1252. Keeping those here stops the two Word formats drifting apart in how a paragraph,
|
|
7
|
-
* a list item or a table row reads to the model.
|
|
8
|
-
*/
|
|
9
|
-
/** One UTF-16 code unit per input byte, which the `.doc` reader relies on to index text by character position. */
|
|
10
1
|
export declare function decodeWindows1252(bytes: Uint8Array): string;
|
|
11
|
-
/** The marker both Word readers print where the author forced a new page. */
|
|
12
2
|
export declare const PAGE_BREAK_LINE = "--- page break ---";
|
|
13
|
-
/**
|
|
14
|
-
* `list` and `row` blocks sit on consecutive lines; everything else is separated by a blank line.
|
|
15
|
-
* `break` is an explicit page break and carries no text of its own.
|
|
16
|
-
*/
|
|
17
3
|
export interface DocumentBlock {
|
|
18
4
|
kind: 'paragraph' | 'list' | 'row' | 'break';
|
|
19
5
|
text: string;
|
|
20
6
|
}
|
|
21
7
|
export declare function headingBlock(level: number, text: string): DocumentBlock;
|
|
22
8
|
export declare function listBlock(level: number, text: string): DocumentBlock;
|
|
23
|
-
/** A table row on one line. Cell text is flattened because a line break inside a cell would split the row. */
|
|
24
9
|
export declare function rowBlock(cells: string[]): DocumentBlock | undefined;
|
|
25
|
-
/** Trailing whitespace per line and blank lines at either end carry nothing for a reader. */
|
|
26
10
|
export declare function tidyText(text: string): string;
|
|
27
11
|
export declare function joinBlocks(blocks: DocumentBlock[]): string;
|
|
28
|
-
/** "2, 5-7" for a sorted list of page numbers, so a note about many pages stays one short line. */
|
|
29
12
|
export declare function formatRanges(numbers: number[]): string;
|
|
@@ -1,41 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text plumbing shared by the document readers behind Read.
|
|
3
|
-
*
|
|
4
|
-
* The Word readers (`read-document-docx.ts`, `read-document-doc.ts`) both reduce a document to the
|
|
5
|
-
* same few block shapes, and both the legacy `.doc` reader and the non-UTF-8 text path need
|
|
6
|
-
* Windows-1252. Keeping those here stops the two Word formats drifting apart in how a paragraph,
|
|
7
|
-
* a list item or a table row reads to the model.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* 0x80-0x9F in Windows-1252. The five bytes the code page leaves undefined map to the C1 control
|
|
11
|
-
* with the same value, as browsers do, so decoding never fails and never shifts an offset.
|
|
12
|
-
*
|
|
13
|
-
* Node's `TextDecoder('windows-1252')` needs full ICU; a small-icu build only has UTF-8 and UTF-16,
|
|
14
|
-
* so the table is spelled out here rather than depending on how Node was compiled.
|
|
15
|
-
*/
|
|
16
1
|
const WINDOWS_1252_HIGH = '€\u0081‚ƒ„…†‡ˆ‰Š‹Œ\u008DŽ\u008F'
|
|
17
2
|
+ '\u0090‘’“”•–—˜™š›œ\u009DžŸ';
|
|
18
|
-
/** One UTF-16 code unit per input byte, which the `.doc` reader relies on to index text by character position. */
|
|
19
3
|
export function decodeWindows1252(bytes) {
|
|
20
4
|
const text = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('latin1');
|
|
21
5
|
return /[\x80-\x9f]/.test(text) ? text.replace(/[\x80-\x9f]/g, char => WINDOWS_1252_HIGH[char.charCodeAt(0) - 0x80]) : text;
|
|
22
6
|
}
|
|
23
|
-
/** The marker both Word readers print where the author forced a new page. */
|
|
24
7
|
export const PAGE_BREAK_LINE = '--- page break ---';
|
|
25
8
|
export function headingBlock(level, text) {
|
|
26
9
|
return { kind: 'paragraph', text: `${'#'.repeat(Math.min(Math.max(level, 1), 6))} ${text}` };
|
|
27
10
|
}
|
|
28
11
|
export function listBlock(level, text) {
|
|
29
|
-
// Continuation lines of an item (manual line breaks) are indented under the marker so the item stays one item.
|
|
30
12
|
const indent = ' '.repeat(Math.min(Math.max(level, 0), 8));
|
|
31
13
|
return { kind: 'list', text: `${indent}- ${text.replace(/\n/g, `\n${indent} `)}` };
|
|
32
14
|
}
|
|
33
|
-
/** A table row on one line. Cell text is flattened because a line break inside a cell would split the row. */
|
|
34
15
|
export function rowBlock(cells) {
|
|
35
16
|
const flat = cells.map(cell => cell.replace(/\s*\n\s*/g, ' ').trim());
|
|
36
17
|
return flat.some(Boolean) ? { kind: 'row', text: flat.join(' | ') } : undefined;
|
|
37
18
|
}
|
|
38
|
-
/** Trailing whitespace per line and blank lines at either end carry nothing for a reader. */
|
|
39
19
|
export function tidyText(text) {
|
|
40
20
|
return text.replace(/\r\n?/g, '\n').replace(/[ \t ]+$/gm, '').replace(/^\n+|\n+$/g, '');
|
|
41
21
|
}
|
|
@@ -43,7 +23,6 @@ export function joinBlocks(blocks) {
|
|
|
43
23
|
let text = '';
|
|
44
24
|
let previous;
|
|
45
25
|
for (const block of blocks) {
|
|
46
|
-
// A break at the very start, or two in a row, would only print noise.
|
|
47
26
|
if (block.kind === 'break' && (!previous || previous.kind === 'break'))
|
|
48
27
|
continue;
|
|
49
28
|
const line = block.kind === 'break' ? PAGE_BREAK_LINE : block.text;
|
|
@@ -54,7 +33,6 @@ export function joinBlocks(blocks) {
|
|
|
54
33
|
}
|
|
55
34
|
return tidyText(previous?.kind === 'break' ? text.slice(0, -PAGE_BREAK_LINE.length) : text);
|
|
56
35
|
}
|
|
57
|
-
/** "2, 5-7" for a sorted list of page numbers, so a note about many pages stays one short line. */
|
|
58
36
|
export function formatRanges(numbers) {
|
|
59
37
|
const parts = [];
|
|
60
38
|
for (let index = 0; index < numbers.length; index++) {
|
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
import type { ToolContext } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Documents through Read: PDF, Word and text in an older encoding.
|
|
4
|
-
*
|
|
5
|
-
* Read used to answer "Binary files are not supported" for anything that was not UTF-8 text or an
|
|
6
|
-
* image. An agent given a task whose input was a PDF then spent its run installing a PDF library
|
|
7
|
-
* (often impossible in the task's environment) or writing its own rasteriser, and read the result
|
|
8
|
-
* wrong. Read now returns what such a file says: the extracted text, paged with the same offset
|
|
9
|
-
* and limit as a text file, and for a PDF the pages themselves as images when asked, which is the
|
|
10
|
-
* only way to read a scan, a figure or a score.
|
|
11
|
-
*
|
|
12
|
-
* What comes back is a rendering of the file, not its bytes, so it is never recorded as a text
|
|
13
|
-
* read: Edit and Write keep refusing a file they have only seen this way.
|
|
14
|
-
*/
|
|
15
|
-
/** Largest document Read will open. The extracted text is paged, so this bounds memory, not output. */
|
|
16
2
|
export declare const READ_DOCUMENT_FILE_LIMIT: number;
|
|
17
|
-
/** PDF pages one Read call returns as images; the response's image budget still applies across calls. */
|
|
18
3
|
export declare const READ_PDF_RENDER_PAGES = 4;
|
|
19
4
|
export interface DocumentReadOptions {
|
|
20
|
-
/** 1-based first line of the extracted text; 0 and undefined mean the first line. */
|
|
21
5
|
offset?: number;
|
|
22
|
-
/** Lines to return at most. */
|
|
23
6
|
limit: number;
|
|
24
|
-
/** PDF pages to read, such as "3", "2-5" or "1,4,7-9". */
|
|
25
7
|
pages?: string;
|
|
26
|
-
/** Return the selected PDF pages as images instead of their text. */
|
|
27
8
|
render?: boolean;
|
|
28
|
-
/** The runtime's cap on one tool result; the page stops on the last whole line that fits. */
|
|
29
9
|
maxOutput: number;
|
|
30
|
-
/** A longer line is truncated, so one unbroken line cannot fill the window. */
|
|
31
10
|
maxLineChars: number;
|
|
32
11
|
}
|
|
33
|
-
/**
|
|
34
|
-
* The 1-based pages a `pages` argument names, in the order given and without repeats.
|
|
35
|
-
* Accepts single pages and ranges separated by commas: "3", "2-5", "1,4,7-9".
|
|
36
|
-
*/
|
|
37
12
|
export declare function parsePageSelection(spec: string, pageCount: number): number[];
|
|
38
|
-
/**
|
|
39
|
-
* The observation for a PDF or Word file, or undefined when the bytes are not a document Read
|
|
40
|
-
* understands (an ordinary zip, a spreadsheet's compound file), so the caller reports it as it
|
|
41
|
-
* always has.
|
|
42
|
-
*/
|
|
43
13
|
export declare function readDocumentObservation(context: ToolContext, shownPath: string, bytes: Buffer, options: DocumentReadOptions): Promise<string | undefined>;
|
|
44
|
-
/** The observation for a text file in an older encoding, decoded for reading only. */
|
|
45
14
|
export declare function legacyTextObservation(shownPath: string, decoded: {
|
|
46
15
|
text: string;
|
|
47
16
|
encoding: string;
|