@sayknow-cli/coding-agent 0.3.1 → 0.3.2
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/bin/skc.js +4 -0
- package/dist/types/cli/mcp-cli.d.ts +25 -0
- package/dist/types/cli/plugin-cli.d.ts +2 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/commands/mcp.d.ts +70 -0
- package/dist/types/commands/plugin.d.ts +6 -0
- package/dist/types/commands/session.d.ts +6 -0
- package/dist/types/config/keybindings.d.ts +2 -2
- package/dist/types/config/model-profile-activation.d.ts +8 -1
- package/dist/types/config/settings-schema.d.ts +1 -59
- package/dist/types/deep-interview/plaintext-gate-guard.d.ts +11 -0
- package/dist/types/extensibility/skc-plugins/compiler.d.ts +19 -0
- package/dist/types/extensibility/skc-plugins/constrained-hooks.d.ts +29 -0
- package/dist/types/extensibility/skc-plugins/index.d.ts +9 -0
- package/dist/types/extensibility/skc-plugins/injection.d.ts +9 -0
- package/dist/types/extensibility/skc-plugins/installer.d.ts +13 -0
- package/dist/types/extensibility/skc-plugins/mcp-policy.d.ts +26 -0
- package/dist/types/extensibility/skc-plugins/observability.d.ts +27 -0
- package/dist/types/extensibility/skc-plugins/prompt-appendix.d.ts +16 -0
- package/dist/types/extensibility/skc-plugins/registry.d.ts +32 -0
- package/dist/types/extensibility/skc-plugins/runtime-adapters.d.ts +64 -0
- package/dist/types/extensibility/skc-plugins/session-validation.d.ts +42 -0
- package/dist/types/extensibility/skc-plugins/types.d.ts +158 -2
- package/dist/types/extensibility/skc-plugins/validation.d.ts +8 -1
- package/dist/types/i18n/messages/en.d.ts +0 -1
- package/dist/types/main.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +1 -1
- package/dist/types/modes/components/model-selector.d.ts +8 -0
- package/dist/types/modes/components/settings-defs.d.ts +0 -1
- package/dist/types/modes/components/status-line/git-utils.d.ts +6 -0
- package/dist/types/modes/theme/defaults/index.d.ts +99 -0
- package/dist/types/modes/theme/theme.d.ts +1 -1
- package/dist/types/notifications/html-format.d.ts +11 -0
- package/dist/types/notifications/index.d.ts +149 -1
- package/dist/types/notifications/lifecycle-commands.d.ts +60 -0
- package/dist/types/notifications/lifecycle-control-runtime.d.ts +98 -0
- package/dist/types/notifications/lifecycle-orchestrator.d.ts +144 -0
- package/dist/types/notifications/operator-runtime.d.ts +52 -0
- package/dist/types/notifications/rate-limit-pool.d.ts +2 -0
- package/dist/types/notifications/recent-activity.d.ts +35 -0
- package/dist/types/notifications/telegram-daemon.d.ts +114 -16
- package/dist/types/notifications/telegram-reference.d.ts +3 -1
- package/dist/types/notifications/topic-registry.d.ts +12 -9
- package/dist/types/runtime-mcp/types.d.ts +7 -0
- package/dist/types/sdk.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +14 -4
- package/dist/types/session/blob-store.d.ts +25 -0
- package/dist/types/session/session-manager.d.ts +57 -0
- package/dist/types/skc-runtime/launch-tmux.d.ts +1 -0
- package/dist/types/skc-runtime/psmux-detect.d.ts +78 -0
- package/dist/types/skc-runtime/team-runtime.d.ts +2 -0
- package/dist/types/skc-runtime/tmux-common.d.ts +30 -2
- package/dist/types/skc-runtime/tmux-sessions.d.ts +18 -0
- package/dist/types/slash-commands/helpers/fast-status-report.d.ts +6 -0
- package/dist/types/system-prompt.d.ts +2 -0
- package/dist/types/task/executor.d.ts +9 -1
- package/dist/types/tools/composer-bash-policy.d.ts +14 -0
- package/dist/types/tools/index.d.ts +3 -1
- package/dist/types/utils/changelog.d.ts +1 -0
- package/dist/types/web/insane/url-guard.d.ts +6 -3
- package/dist/types/web/scrapers/types.d.ts +5 -0
- package/dist/types/web/scrapers/utils.d.ts +7 -1
- package/package.json +11 -9
- package/scripts/g004-tmux-smoke.ts +100 -0
- package/scripts/g005-daemon-smoke.ts +180 -0
- package/scripts/g011-daemon-path-smoke.ts +153 -0
- package/src/cli/fast-help.ts +29 -1
- package/src/cli/mcp-cli.ts +272 -0
- package/src/cli/plugin-cli.ts +66 -3
- package/src/cli.ts +30 -12
- package/src/commands/mcp.ts +117 -0
- package/src/commands/plugin.ts +4 -0
- package/src/commands/session.ts +18 -0
- package/src/config/keybindings.ts +2 -2
- package/src/config/model-profile-activation.ts +55 -7
- package/src/config/settings-schema.ts +8 -93
- package/src/deep-interview/plaintext-gate-guard.ts +94 -0
- package/src/defaults/skc/extensions/grok-cli-vendor/biome.json +1 -1
- package/src/defaults/skc/skills/deep-interview/SKILL.md +7 -6
- package/src/defaults/skc/skills/team/SKILL.md +5 -3
- package/src/defaults/skc/skills/ultragoal/SKILL.md +41 -13
- package/src/export/html/index.ts +2 -2
- package/src/extensibility/extensions/runner.ts +1 -0
- package/src/extensibility/skc-plugins/compiler.ts +351 -0
- package/src/extensibility/skc-plugins/constrained-hooks.ts +170 -0
- package/src/extensibility/skc-plugins/index.ts +9 -0
- package/src/extensibility/skc-plugins/injection.ts +109 -0
- package/src/extensibility/skc-plugins/installer.ts +434 -0
- package/src/extensibility/skc-plugins/loader.ts +3 -1
- package/src/extensibility/skc-plugins/mcp-policy.ts +239 -0
- package/src/extensibility/skc-plugins/observability.ts +84 -0
- package/src/extensibility/skc-plugins/paths.ts +1 -1
- package/src/extensibility/skc-plugins/prompt-appendix.ts +109 -0
- package/src/extensibility/skc-plugins/registry.ts +180 -0
- package/src/extensibility/skc-plugins/runtime-adapters.ts +234 -0
- package/src/extensibility/skc-plugins/schema.ts +250 -20
- package/src/extensibility/skc-plugins/session-validation.ts +147 -0
- package/src/extensibility/skc-plugins/types.ts +199 -3
- package/src/extensibility/skc-plugins/validation.ts +80 -0
- package/src/extensibility/skills.ts +15 -0
- package/src/hooks/skill-state.ts +57 -0
- package/src/i18n/messages/de.ts +0 -1
- package/src/i18n/messages/en.ts +0 -1
- package/src/i18n/messages/es.ts +0 -1
- package/src/i18n/messages/fr.ts +0 -1
- package/src/i18n/messages/ja.ts +0 -1
- package/src/i18n/messages/ko.ts +0 -1
- package/src/i18n/messages/zh.ts +0 -1
- package/src/internal-urls/docs-index.generated.ts +12 -8
- package/src/main.ts +14 -3
- package/src/modes/bridge/bridge-mode.ts +11 -0
- package/src/modes/components/assistant-message.ts +49 -1
- package/src/modes/components/custom-editor.ts +2 -0
- package/src/modes/components/footer.ts +2 -3
- package/src/modes/components/hook-editor.ts +1 -1
- package/src/modes/components/hook-selector.ts +67 -43
- package/src/modes/components/model-selector.ts +56 -11
- package/src/modes/components/settings-defs.ts +1 -2
- package/src/modes/components/settings-selector.ts +2 -7
- package/src/modes/components/status-line/git-utils.ts +25 -0
- package/src/modes/components/status-line.ts +10 -11
- package/src/modes/components/welcome.ts +2 -3
- package/src/modes/controllers/extension-ui-controller.ts +0 -27
- package/src/modes/controllers/selector-controller.ts +53 -11
- package/src/modes/interactive-mode.ts +4 -1
- package/src/modes/shared/agent-wire/scopes.ts +1 -1
- package/src/modes/theme/defaults/gruvbox-dark.json +99 -0
- package/src/modes/theme/defaults/index.ts +2 -0
- package/src/modes/theme/theme.ts +0 -4
- package/src/modes/utils/hotkeys-markdown.ts +1 -1
- package/src/notifications/html-format.ts +38 -0
- package/src/notifications/index.ts +242 -12
- package/src/notifications/lifecycle-commands.ts +238 -0
- package/src/notifications/lifecycle-control-runtime.ts +405 -0
- package/src/notifications/lifecycle-orchestrator.ts +358 -0
- package/src/notifications/operator-runtime.ts +171 -0
- package/src/notifications/rate-limit-pool.ts +19 -0
- package/src/notifications/recent-activity.ts +132 -0
- package/src/notifications/telegram-daemon.ts +778 -257
- package/src/notifications/telegram-reference.ts +25 -7
- package/src/notifications/topic-registry.ts +23 -9
- package/src/prompts/agents/executor.md +2 -2
- package/src/runtime-mcp/transports/stdio.ts +38 -4
- package/src/runtime-mcp/types.ts +7 -0
- package/src/sdk.ts +157 -10
- package/src/session/agent-session.ts +166 -74
- package/src/session/blob-store.ts +196 -8
- package/src/session/session-manager.ts +762 -12
- package/src/skc-runtime/launch-tmux.ts +68 -19
- package/src/skc-runtime/psmux-detect.ts +239 -0
- package/src/skc-runtime/team-runtime.ts +56 -23
- package/src/skc-runtime/tmux-common.ts +88 -4
- package/src/skc-runtime/tmux-sessions.ts +111 -9
- package/src/skc-runtime/ultragoal-guard.ts +25 -8
- package/src/skc-runtime/ultragoal-runtime.ts +75 -15
- package/src/slash-commands/builtin-registry.ts +23 -3
- package/src/slash-commands/helpers/fast-status-report.ts +13 -3
- package/src/slash-commands/helpers/parse.ts +2 -1
- package/src/system-prompt.ts +9 -0
- package/src/task/executor.ts +31 -7
- package/src/task/index.ts +2 -0
- package/src/tools/ask.ts +5 -1
- package/src/tools/bash.ts +9 -0
- package/src/tools/composer-bash-policy.ts +96 -0
- package/src/tools/fetch.ts +18 -2
- package/src/tools/index.ts +3 -1
- package/src/utils/changelog.ts +8 -0
- package/src/web/insane/url-guard.ts +18 -14
- package/src/web/scrapers/types.ts +143 -45
- package/src/web/scrapers/utils.ts +70 -19
package/src/system-prompt.ts
CHANGED
|
@@ -336,6 +336,8 @@ export interface BuildSystemPromptOptions {
|
|
|
336
336
|
toolNames?: string[];
|
|
337
337
|
/** Text to append to system prompt. */
|
|
338
338
|
appendSystemPrompt?: string;
|
|
339
|
+
/** Rendered SKC plugin system-appendix blocks (lower-authority, appended last). */
|
|
340
|
+
pluginAppendices?: string;
|
|
339
341
|
/** Repeat full tool descriptions in system prompt. Default: false */
|
|
340
342
|
repeatToolDescriptions?: boolean;
|
|
341
343
|
/** Skills settings for discovery. */
|
|
@@ -380,6 +382,7 @@ export async function buildSystemPrompt(options: BuildSystemPromptOptions = {}):
|
|
|
380
382
|
customPrompt,
|
|
381
383
|
tools,
|
|
382
384
|
appendSystemPrompt,
|
|
385
|
+
pluginAppendices,
|
|
383
386
|
repeatToolDescriptions = false,
|
|
384
387
|
skillsSettings,
|
|
385
388
|
toolNames: providedToolNames,
|
|
@@ -579,5 +582,11 @@ export async function buildSystemPrompt(options: BuildSystemPromptOptions = {}):
|
|
|
579
582
|
systemPrompt.push(projectPrompt);
|
|
580
583
|
}
|
|
581
584
|
|
|
585
|
+
// Plugin system appendices are appended last as a lower-authority block; they
|
|
586
|
+
// can never override base/project/developer instructions above them.
|
|
587
|
+
if (pluginAppendices?.trim()) {
|
|
588
|
+
systemPrompt.push(pluginAppendices.trim());
|
|
589
|
+
}
|
|
590
|
+
|
|
582
591
|
return { systemPrompt };
|
|
583
592
|
}
|
package/src/task/executor.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as fs from "node:fs/promises";
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import type { AgentEvent, AgentIdentity, AgentTelemetryConfig, ThinkingLevel } from "@sayknow-cli/agent-core";
|
|
11
11
|
import { recordHandoff, resolveTelemetry } from "@sayknow-cli/agent-core";
|
|
12
|
+
import type { ServiceTier } from "@sayknow-cli/ai";
|
|
12
13
|
import { type JsonSchemaValidationIssue, validateJsonSchemaValue } from "@sayknow-cli/ai/utils/schema";
|
|
13
14
|
import { logger, prompt, untilAborted } from "@sayknow-cli/utils";
|
|
14
15
|
import { AsyncJobManager } from "../async";
|
|
@@ -19,7 +20,7 @@ import { Settings } from "../config/settings";
|
|
|
19
20
|
import { SETTINGS_SCHEMA, type SettingPath } from "../config/settings-schema";
|
|
20
21
|
import { runExtensionCompact, runExtensionSetModel } from "../extensibility/extensions/compact-handler";
|
|
21
22
|
import { getSessionSlashCommands } from "../extensibility/extensions/get-commands-handler";
|
|
22
|
-
import { buildAgentSubskillInjection } from "../extensibility/skc-plugins";
|
|
23
|
+
import { buildAgentSubskillInjection, renderAgentPromptAdditions } from "../extensibility/skc-plugins";
|
|
23
24
|
import { buildSkillPromptMessage, type Skill } from "../extensibility/skills";
|
|
24
25
|
import type { HindsightSessionState } from "../hindsight/state";
|
|
25
26
|
import type { LocalProtocolOptions } from "../internal-urls";
|
|
@@ -146,6 +147,13 @@ export interface ExecutorOptions {
|
|
|
146
147
|
authStorage?: AuthStorage;
|
|
147
148
|
modelRegistry?: ModelRegistry;
|
|
148
149
|
settings?: Settings;
|
|
150
|
+
/**
|
|
151
|
+
* Live service-tier intent of the parent session (`AgentSession.serviceTier`),
|
|
152
|
+
* used as the inherited tier when `task.serviceTier === "inherit"`. Passing the
|
|
153
|
+
* live value (not the stale settings snapshot) lets a runtime `/fast on` reach
|
|
154
|
+
* subagents, and a main-model fast-mode auto-disable does not clobber it.
|
|
155
|
+
*/
|
|
156
|
+
inheritedServiceTier?: ServiceTier;
|
|
149
157
|
/** Override local:// protocol options so subagent shares parent's local:// root */
|
|
150
158
|
localProtocolOptions?: LocalProtocolOptions;
|
|
151
159
|
/**
|
|
@@ -482,15 +490,19 @@ function getUsageTokens(usage: unknown): number {
|
|
|
482
490
|
return firstNumberField(record, ["totalTokens", "total_tokens"]) ?? 0;
|
|
483
491
|
}
|
|
484
492
|
|
|
485
|
-
export function createSubagentSettings(baseSettings: Settings): Settings {
|
|
493
|
+
export function createSubagentSettings(baseSettings: Settings, inheritedServiceTier?: ServiceTier): Settings {
|
|
486
494
|
const snapshot: Partial<Record<SettingPath, unknown>> = {};
|
|
487
495
|
for (const key of Object.keys(SETTINGS_SCHEMA) as SettingPath[]) {
|
|
488
496
|
snapshot[key] = baseSettings.get(key);
|
|
489
497
|
}
|
|
490
|
-
// Subagent-scoped service-tier override: "inherit"
|
|
491
|
-
//
|
|
498
|
+
// Subagent-scoped service-tier override: "inherit" uses the parent session's
|
|
499
|
+
// LIVE intent (so a runtime `/fast on` reaches subagents and a main-model
|
|
500
|
+
// fast-mode auto-disable never clobbers it); any explicit value applies only
|
|
501
|
+
// to subagent sessions and wins over inherited intent.
|
|
492
502
|
const taskServiceTier = baseSettings.get("task.serviceTier");
|
|
493
|
-
if (taskServiceTier
|
|
503
|
+
if (taskServiceTier === "inherit") {
|
|
504
|
+
snapshot.serviceTier = inheritedServiceTier ?? "none";
|
|
505
|
+
} else {
|
|
494
506
|
snapshot.serviceTier = taskServiceTier;
|
|
495
507
|
}
|
|
496
508
|
return Settings.isolated({
|
|
@@ -571,7 +583,7 @@ export async function runSubprocess(options: ExecutorOptions): Promise<SingleRes
|
|
|
571
583
|
}
|
|
572
584
|
|
|
573
585
|
const settings = options.settings ?? Settings.isolated();
|
|
574
|
-
const subagentSettings = createSubagentSettings(settings);
|
|
586
|
+
const subagentSettings = createSubagentSettings(settings, options.inheritedServiceTier);
|
|
575
587
|
const maxRecursionDepth = settings.get("task.maxRecursionDepth") ?? 2;
|
|
576
588
|
const maxRuntimeMs = Math.max(0, Math.trunc(Number(settings.get("task.maxRuntimeMs") ?? 0) || 0));
|
|
577
589
|
const parentDepth = options.taskDepth ?? 0;
|
|
@@ -1229,6 +1241,13 @@ export async function runSubprocess(options: ExecutorOptions): Promise<SingleRes
|
|
|
1229
1241
|
agentName: agent.name,
|
|
1230
1242
|
});
|
|
1231
1243
|
|
|
1244
|
+
let agentPromptAdditions = { appendix: "", advertisement: "" };
|
|
1245
|
+
try {
|
|
1246
|
+
agentPromptAdditions = await renderAgentPromptAdditions({ cwd, agentName: agent.name });
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
logger.warn("Failed to render SKC plugin agent prompt additions", { error });
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1232
1251
|
const { session } = await awaitAbortable(
|
|
1233
1252
|
createAgentSession({
|
|
1234
1253
|
cwd: worktree ?? cwd,
|
|
@@ -1259,7 +1278,12 @@ export async function runSubprocess(options: ExecutorOptions): Promise<SingleRes
|
|
|
1259
1278
|
ircSelfId: ircEnabled ? id : "",
|
|
1260
1279
|
forkContext: forkContextNotice,
|
|
1261
1280
|
});
|
|
1262
|
-
|
|
1281
|
+
// Order: base agent prompt -> agent appendix -> Tier-1 advertisement -> Tier-2 body.
|
|
1282
|
+
const appendixPart = agentPromptAdditions.appendix ? `\n\n${agentPromptAdditions.appendix}` : "";
|
|
1283
|
+
const advertPart = agentPromptAdditions.advertisement
|
|
1284
|
+
? `\n\n${agentPromptAdditions.advertisement}`
|
|
1285
|
+
: "";
|
|
1286
|
+
const promptWithSubskills = `${subagentPrompt}${appendixPart}${advertPart}${agentSubskillBlock}`;
|
|
1263
1287
|
return defaultPrompt.length === 0
|
|
1264
1288
|
? [promptWithSubskills]
|
|
1265
1289
|
: [...defaultPrompt.slice(0, -1), promptWithSubskills, defaultPrompt[defaultPrompt.length - 1]];
|
package/src/task/index.ts
CHANGED
|
@@ -1311,6 +1311,7 @@ export class TaskTool implements AgentTool<TaskToolSchemaInstance, TaskToolDetai
|
|
|
1311
1311
|
authStorage: this.session.authStorage,
|
|
1312
1312
|
modelRegistry: this.session.modelRegistry,
|
|
1313
1313
|
settings: this.session.settings,
|
|
1314
|
+
inheritedServiceTier: this.session.serviceTier,
|
|
1314
1315
|
contextFiles,
|
|
1315
1316
|
skills: availableSkills,
|
|
1316
1317
|
autoloadSkills: resolvedAutoloadSkills,
|
|
@@ -1372,6 +1373,7 @@ export class TaskTool implements AgentTool<TaskToolSchemaInstance, TaskToolDetai
|
|
|
1372
1373
|
authStorage: this.session.authStorage,
|
|
1373
1374
|
modelRegistry: this.session.modelRegistry,
|
|
1374
1375
|
settings: this.session.settings,
|
|
1376
|
+
inheritedServiceTier: this.session.serviceTier,
|
|
1375
1377
|
contextFiles,
|
|
1376
1378
|
skills: availableSkills,
|
|
1377
1379
|
autoloadSkills: resolvedAutoloadSkills,
|
package/src/tools/ask.ts
CHANGED
|
@@ -260,7 +260,11 @@ async function askSingleQuestion(
|
|
|
260
260
|
? "up/down navigate enter select ←/→ question esc cancel"
|
|
261
261
|
: "up/down navigate enter select esc cancel";
|
|
262
262
|
const helpText =
|
|
263
|
-
scrollTitleRows === undefined
|
|
263
|
+
scrollTitleRows === undefined
|
|
264
|
+
? baseHelpText
|
|
265
|
+
: navigation
|
|
266
|
+
? "↑/↓ select enter ←/→ question esc PgUp/PgDn/Ctrl+u/d: question · Wheel: transcript"
|
|
267
|
+
: "↑/↓ select enter esc PgUp/PgDn/Ctrl+u/d: question · Wheel: transcript";
|
|
264
268
|
const dialogOptions = {
|
|
265
269
|
initialIndex,
|
|
266
270
|
timeout,
|
package/src/tools/bash.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { type BashInteractiveResult, runInteractiveBashPty } from "./bash-intera
|
|
|
25
25
|
import { checkBashInterception } from "./bash-interceptor";
|
|
26
26
|
import { canUseInteractiveBashPty } from "./bash-pty-selection";
|
|
27
27
|
import { expandInternalUrls, type InternalUrlExpansionOptions } from "./bash-skill-urls";
|
|
28
|
+
import { checkComposerBashPolicy } from "./composer-bash-policy";
|
|
28
29
|
import { formatStyledTruncationWarning, type OutputMeta, stripOutputNotice } from "./output-meta";
|
|
29
30
|
import { resolveToCwd } from "./path-utils";
|
|
30
31
|
import { formatToolWorkingDirectory, replaceTabs } from "./render-utils";
|
|
@@ -570,6 +571,14 @@ export class BashTool implements AgentTool<BashToolSchema, BashToolDetails> {
|
|
|
570
571
|
}
|
|
571
572
|
}
|
|
572
573
|
|
|
574
|
+
const composerPolicy = checkComposerBashPolicy({
|
|
575
|
+
modelId: this.session.getActiveModelString?.() ?? this.session.getModelString?.() ?? this.session.model?.id,
|
|
576
|
+
commands: rawCommand === command ? [command] : [rawCommand, command],
|
|
577
|
+
});
|
|
578
|
+
if (!composerPolicy.allowed) {
|
|
579
|
+
throw new ToolError(composerPolicy.message);
|
|
580
|
+
}
|
|
581
|
+
|
|
573
582
|
const internalUrlOptions: InternalUrlExpansionOptions = {
|
|
574
583
|
skills: this.session.skills ?? [],
|
|
575
584
|
internalRouter: InternalUrlRouter.instance(),
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isComposerHarnessModel } from "@sayknow-cli/ai/providers/composer-discipline";
|
|
2
|
+
|
|
3
|
+
export const COMPOSER_BASH_POLICY_ERROR =
|
|
4
|
+
"Composer bash policy blocked repository file I/O. Use find, search, read, and edit tools for file discovery, file inspection, and file mutation.";
|
|
5
|
+
|
|
6
|
+
type ComposerBashPolicyResult =
|
|
7
|
+
| { allowed: true }
|
|
8
|
+
| {
|
|
9
|
+
allowed: false;
|
|
10
|
+
reason: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const BLOCK_PATTERNS: Array<{ id: string; pattern: RegExp }> = [
|
|
15
|
+
{ id: "pipe", pattern: /\|/ },
|
|
16
|
+
{ id: "process-substitution", pattern: /<[>(]/ },
|
|
17
|
+
{ id: "heredoc", pattern: /<<[-~]?/ },
|
|
18
|
+
{ id: "command-substitution", pattern: /\$\(|`/ },
|
|
19
|
+
{ id: "redirection", pattern: /(^|[^<>])(?:>>?|<)(?!=)/ },
|
|
20
|
+
{ id: "tee", pattern: /(?:^|[;&|\s])tee(?:\s|$)/ },
|
|
21
|
+
{
|
|
22
|
+
id: "shell-file-read-discovery",
|
|
23
|
+
pattern: /(?:^|[;&|()\s])(?:\S*\/)?(?:cat|head|tail|less|more|grep|rg|find|fd|tree|ls)\b/,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "shell-file-mutation",
|
|
27
|
+
pattern: /(?:^|[;&|()\s])(?:\S*\/)?(?:cp|mv|rm|touch|mkdir|chmod|chown|ln)\b/,
|
|
28
|
+
},
|
|
29
|
+
{ id: "sed-print", pattern: /(?:^|[;&|()\s])sed\s+(?:-[^\s]*n\b|.*\bp\b)/ },
|
|
30
|
+
{ id: "awk-print", pattern: /(?:^|[;&|()\s])awk\b/ },
|
|
31
|
+
{ id: "git-ls-files", pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+ls-files\b/ },
|
|
32
|
+
{ id: "git-grep", pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+grep\b/ },
|
|
33
|
+
{ id: "git-show-path", pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+show\s+\S+:\S+/ },
|
|
34
|
+
{ id: "git-diff", pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+diff(?:\s|$)/ },
|
|
35
|
+
{ id: "git-cat-file", pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+cat-file\b/ },
|
|
36
|
+
{
|
|
37
|
+
id: "git-show-discovery",
|
|
38
|
+
pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+show\b.*(?:--name-only|--name-status|--stat)/,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "git-log-path-discovery",
|
|
42
|
+
pattern: /(?:^|[;&|()\s])git(?:\s+-C\s+\S+)?\s+log\b.*(?:--name-only|--name-status|--stat)/,
|
|
43
|
+
},
|
|
44
|
+
{ id: "sed-in-place", pattern: /(?:^|[;&|()\s])sed\s+-[^\s]*i\b/ },
|
|
45
|
+
{ id: "perl-in-place", pattern: /(?:^|[;&|()\s])perl\s+-[^\s]*p[^\s]*i\b/ },
|
|
46
|
+
{
|
|
47
|
+
id: "script-file-io",
|
|
48
|
+
pattern:
|
|
49
|
+
/(?:^|[;&|()\s])(?:python3?|node|bun)\s+(?:-\s*<<|-c\b|-e\b|--eval\b).*?(?:read_text|read_bytes|write_text|iterdir|listdir|glob\.glob|readFile|readFileSync|writeFile|writeFileSync|readdir|readdirSync|stat|statSync|cpSync|rmSync|mkdirSync|createReadStream|createWriteStream|Bun\.file|Bun\.write|fs\.readFile|fs\.writeFile|fs\.readdir|fs\.stat|fs\.cp|fs\.rm|fs\.mkdir|open\s*\()/s,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "contaminated-command",
|
|
53
|
+
pattern: /```|^\s*(?:I\s+(?:will|need|am going)|We\s+(?:need|will)|First[, ]|Now[, ]|Let's)\b/im,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const ALLOWED_TERMINAL_PATTERNS: RegExp[] = [
|
|
58
|
+
/^bun\s+test(?:\s+[\w./:@=-]+)*$/,
|
|
59
|
+
/^bun\s+run\s+(?:check(?::[\w-]+)?|test(?::[\w-]+)?|build(?::[\w-]+)?)(?:\s+[\w./:@=-]+)*$/,
|
|
60
|
+
/^bun\s+--version$/,
|
|
61
|
+
/^mise\s+x\s+bun@\d+\.\d+\.\d+\s+--\s+bun\s+test(?:\s+[\w./:@=-]+)*$/,
|
|
62
|
+
/^mise\s+x\s+bun@\d+\.\d+\.\d+\s+--\s+bun\s+run\s+(?:check(?::[\w-]+)?|test(?::[\w-]+)?|build(?::[\w-]+)?)(?:\s+[\w./:@=-]+)*$/,
|
|
63
|
+
/^cargo\s+(?:test|check|build)(?:\s+[\w./:@=-]+)*$/,
|
|
64
|
+
/^git\s+status(?:\s+--short)?(?:\s+--branch)?$/,
|
|
65
|
+
/^git\s+rev-parse\s+HEAD$/,
|
|
66
|
+
/^npm\s+--version$/,
|
|
67
|
+
/^pnpm\s+--version$/,
|
|
68
|
+
/^yarn\s+--version$/,
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
function isAllowedComposerTerminalCommand(command: string): boolean {
|
|
72
|
+
const normalized = command.trim().replace(/\s+/g, " ");
|
|
73
|
+
return ALLOWED_TERMINAL_PATTERNS.some(pattern => pattern.test(normalized));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function isComposerBashPolicyModel(modelId: string | undefined): boolean {
|
|
77
|
+
return Boolean(modelId && isComposerHarnessModel(modelId));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function checkComposerBashPolicy(input: {
|
|
81
|
+
modelId?: string;
|
|
82
|
+
commands: readonly string[];
|
|
83
|
+
}): ComposerBashPolicyResult {
|
|
84
|
+
if (!isComposerBashPolicyModel(input.modelId)) return { allowed: true };
|
|
85
|
+
for (const command of input.commands) {
|
|
86
|
+
for (const block of BLOCK_PATTERNS) {
|
|
87
|
+
if (block.pattern.test(command)) {
|
|
88
|
+
return { allowed: false, reason: block.id, message: COMPOSER_BASH_POLICY_ERROR };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!isAllowedComposerTerminalCommand(command)) {
|
|
92
|
+
return { allowed: false, reason: "not-allowlisted", message: COMPOSER_BASH_POLICY_ERROR };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { allowed: true };
|
|
96
|
+
}
|
package/src/tools/fetch.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { CachedOutputBlock } from "../tui/output-block";
|
|
|
17
17
|
import { formatDimensionNote, resizeImage } from "../utils/image-resize";
|
|
18
18
|
import { ensureTool } from "../utils/tools-manager";
|
|
19
19
|
import { INSANE_NOTES, tryInsaneFetch } from "../web/insane/bridge";
|
|
20
|
-
import { validatePublicHttpUrlForInsane } from "../web/insane/url-guard";
|
|
20
|
+
import { validatePublicHttpUrl, validatePublicHttpUrlForInsane } from "../web/insane/url-guard";
|
|
21
21
|
import { extractWithParallel, findParallelApiKey, getParallelExtractContent } from "../web/parallel";
|
|
22
22
|
import { specialHandlers } from "../web/scrapers";
|
|
23
23
|
import type { RenderResult } from "../web/scrapers/types";
|
|
@@ -789,6 +789,21 @@ async function renderUrl(
|
|
|
789
789
|
|
|
790
790
|
// Step 0: Normalize URL (ensure scheme for special handlers)
|
|
791
791
|
url = normalizeUrl(url);
|
|
792
|
+
const publicUrl = await validatePublicHttpUrl(url);
|
|
793
|
+
if (!publicUrl.ok) {
|
|
794
|
+
notes.push(`Blocked URL fetch: target URL is not public HTTP(S): ${publicUrl.reason}`);
|
|
795
|
+
return {
|
|
796
|
+
url,
|
|
797
|
+
finalUrl: url,
|
|
798
|
+
contentType: "unknown",
|
|
799
|
+
method: "failed",
|
|
800
|
+
content: "",
|
|
801
|
+
fetchedAt,
|
|
802
|
+
truncated: false,
|
|
803
|
+
notes,
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
url = publicUrl.url.toString();
|
|
792
807
|
|
|
793
808
|
// Step 1: Try special handlers for known sites (unless raw mode)
|
|
794
809
|
if (!raw) {
|
|
@@ -802,7 +817,8 @@ async function renderUrl(
|
|
|
802
817
|
throw new ToolAbortError();
|
|
803
818
|
}
|
|
804
819
|
if (!response.ok) {
|
|
805
|
-
const failureNote =
|
|
820
|
+
const failureNote =
|
|
821
|
+
response.error ?? (response.status ? `Failed to fetch URL (HTTP ${response.status})` : "Failed to fetch URL");
|
|
806
822
|
notes.push(failureNote);
|
|
807
823
|
const insane = await tryInsaneFallback({
|
|
808
824
|
url,
|
package/src/tools/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentTelemetryConfig, AgentTool } from "@sayknow-cli/agent-core";
|
|
2
|
-
import type { Model, ToolChoice } from "@sayknow-cli/ai";
|
|
2
|
+
import type { Model, ServiceTier, ToolChoice } from "@sayknow-cli/ai";
|
|
3
3
|
import { $env, $flag, logger } from "@sayknow-cli/utils";
|
|
4
4
|
import type { PromptTemplate } from "../config/prompt-templates";
|
|
5
5
|
import type { Settings } from "../config/settings";
|
|
@@ -222,6 +222,8 @@ export interface ToolSession {
|
|
|
222
222
|
agentOutputManager?: AgentOutputManager;
|
|
223
223
|
/** Settings instance for passing to subagents */
|
|
224
224
|
settings: Settings;
|
|
225
|
+
/** Live service-tier intent of the parent session, inherited by `inherit` subagents. */
|
|
226
|
+
serviceTier?: ServiceTier;
|
|
225
227
|
/** Plan mode state (if active) */
|
|
226
228
|
getPlanModeState?: () => PlanModeState | undefined;
|
|
227
229
|
/** Goal mode state (if active or paused) */
|
package/src/utils/changelog.ts
CHANGED
|
@@ -92,6 +92,14 @@ export function getDisplayChangelogEntries(): ChangelogEntry[] {
|
|
|
92
92
|
return parseChangelogContent(CHANGELOG_TEXT);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
export function getInstalledVersionChangelogEntry(
|
|
96
|
+
entries: readonly ChangelogEntry[],
|
|
97
|
+
installedVersion: string,
|
|
98
|
+
): ChangelogEntry | undefined {
|
|
99
|
+
const [major = 0, minor = 0, patch = 0] = installedVersion.split(".").map(Number);
|
|
100
|
+
return entries.find(entry => entry.major === major && entry.minor === minor && entry.patch === patch) ?? entries[0];
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
/**
|
|
96
104
|
* Compare versions. Returns: -1 if v1 < v2, 0 if v1 === v2, 1 if v1 > v2
|
|
97
105
|
*/
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public HTTP(S) URL guard for
|
|
2
|
+
* Public HTTP(S) URL guard for user-supplied web fetch targets.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* dependency probe or engine subprocess is spawned. It is fail-closed: anything
|
|
8
|
-
* it cannot prove is a public, non-credentialed http/https target is rejected.
|
|
4
|
+
* Network-capable URL readers MUST run this guard before the first request and
|
|
5
|
+
* before following any redirect target. It is fail-closed: anything it cannot
|
|
6
|
+
* prove is a public, non-credentialed http/https target is rejected.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* opt-in (default off).
|
|
8
|
+
* The vendored insane-search engine performs its own redirects outside the
|
|
9
|
+
* TypeScript fetch path, so its fallback remains opt-in and is guarded before
|
|
10
|
+
* any dependency probe or engine subprocess is spawned.
|
|
14
11
|
*/
|
|
15
12
|
import * as dns from "node:dns/promises";
|
|
16
13
|
import * as net from "node:net";
|
|
@@ -105,11 +102,11 @@ export function isPrivateOrSpecialAddress(address: string): boolean {
|
|
|
105
102
|
}
|
|
106
103
|
|
|
107
104
|
/**
|
|
108
|
-
* Validate that `rawUrl` is a public http/https target
|
|
109
|
-
*
|
|
110
|
-
*
|
|
105
|
+
* Validate that `rawUrl` is a public http/https target. Resolves DNS names and
|
|
106
|
+
* rejects any that map to a private/special address. Never throws; returns a
|
|
107
|
+
* discriminated result.
|
|
111
108
|
*/
|
|
112
|
-
export async function
|
|
109
|
+
export async function validatePublicHttpUrl(
|
|
113
110
|
rawUrl: string,
|
|
114
111
|
options: { resolver?: AddressResolver } = {},
|
|
115
112
|
): Promise<PublicUrlResult> {
|
|
@@ -153,3 +150,10 @@ export async function validatePublicHttpUrlForInsane(
|
|
|
153
150
|
}
|
|
154
151
|
return { ok: true, url, addresses };
|
|
155
152
|
}
|
|
153
|
+
|
|
154
|
+
export async function validatePublicHttpUrlForInsane(
|
|
155
|
+
rawUrl: string,
|
|
156
|
+
options: { resolver?: AddressResolver } = {},
|
|
157
|
+
): Promise<PublicUrlResult> {
|
|
158
|
+
return validatePublicHttpUrl(rawUrl, options);
|
|
159
|
+
}
|
|
@@ -6,6 +6,8 @@ import type TurndownService from "turndown";
|
|
|
6
6
|
|
|
7
7
|
import type { AgentStorage } from "../../session/agent-storage";
|
|
8
8
|
import { ToolAbortError } from "../../tools/tool-errors";
|
|
9
|
+
import type { AddressResolver } from "../insane/url-guard";
|
|
10
|
+
import { validatePublicHttpUrl } from "../insane/url-guard";
|
|
9
11
|
|
|
10
12
|
export { formatNumber } from "@sayknow-cli/utils";
|
|
11
13
|
|
|
@@ -35,6 +37,7 @@ const USER_AGENTS = [
|
|
|
35
37
|
"Mozilla/5.0 (compatible; TextBot/1.0)",
|
|
36
38
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
|
37
39
|
];
|
|
40
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
38
41
|
|
|
39
42
|
function isBotBlocked(status: number, content: string): boolean {
|
|
40
43
|
if (status === 403 || status === 503) {
|
|
@@ -70,6 +73,9 @@ export interface LoadPageOptions {
|
|
|
70
73
|
body?: string;
|
|
71
74
|
maxBytes?: number;
|
|
72
75
|
signal?: AbortSignal;
|
|
76
|
+
publicUrlGuard?: boolean;
|
|
77
|
+
resolver?: AddressResolver;
|
|
78
|
+
maxRedirects?: number;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
export interface LoadPageResult {
|
|
@@ -78,87 +84,179 @@ export interface LoadPageResult {
|
|
|
78
84
|
finalUrl: string;
|
|
79
85
|
ok: boolean;
|
|
80
86
|
status?: number;
|
|
87
|
+
error?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function guardPublicFetchUrl(
|
|
91
|
+
rawUrl: string,
|
|
92
|
+
resolver: AddressResolver | undefined,
|
|
93
|
+
context: string,
|
|
94
|
+
): Promise<{ ok: true; url: string } | { ok: false; error: string; finalUrl: string }> {
|
|
95
|
+
const guard = await validatePublicHttpUrl(rawUrl, { resolver });
|
|
96
|
+
if (guard.ok) return { ok: true, url: guard.url.toString() };
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
error: `${context}: target URL is not public HTTP(S): ${guard.reason}`,
|
|
100
|
+
finalUrl: rawUrl,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function shouldRewriteRedirectMethod(status: number, method: string): boolean {
|
|
105
|
+
const normalized = method.toUpperCase();
|
|
106
|
+
return status === 303 || ((status === 301 || status === 302) && normalized === "POST");
|
|
81
107
|
}
|
|
82
108
|
|
|
83
109
|
/**
|
|
84
110
|
* Fetch a page with timeout and size limit
|
|
85
111
|
*/
|
|
86
112
|
export async function loadPage(url: string, options: LoadPageOptions = {}): Promise<LoadPageResult> {
|
|
87
|
-
const {
|
|
113
|
+
const {
|
|
114
|
+
timeout = 20,
|
|
115
|
+
headers = {},
|
|
116
|
+
maxBytes = MAX_BYTES,
|
|
117
|
+
signal,
|
|
118
|
+
method = "GET",
|
|
119
|
+
body,
|
|
120
|
+
publicUrlGuard = true,
|
|
121
|
+
resolver,
|
|
122
|
+
maxRedirects = 10,
|
|
123
|
+
} = options;
|
|
124
|
+
|
|
125
|
+
let initialUrl = url;
|
|
126
|
+
if (publicUrlGuard) {
|
|
127
|
+
const guarded = await guardPublicFetchUrl(url, resolver, "Blocked URL fetch");
|
|
128
|
+
if (!guarded.ok) {
|
|
129
|
+
return {
|
|
130
|
+
content: "",
|
|
131
|
+
contentType: "",
|
|
132
|
+
finalUrl: guarded.finalUrl,
|
|
133
|
+
ok: false,
|
|
134
|
+
error: guarded.error,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
initialUrl = guarded.url;
|
|
138
|
+
}
|
|
88
139
|
|
|
89
|
-
for (let attempt = 0; attempt < USER_AGENTS.length; attempt++) {
|
|
140
|
+
attempts: for (let attempt = 0; attempt < USER_AGENTS.length; attempt++) {
|
|
90
141
|
if (signal?.aborted) {
|
|
91
142
|
throw new ToolAbortError();
|
|
92
143
|
}
|
|
93
144
|
|
|
94
145
|
const userAgent = USER_AGENTS[attempt];
|
|
95
146
|
const requestSignal = ptree.combineSignals(signal, timeout * 1000);
|
|
147
|
+
let currentUrl = initialUrl;
|
|
148
|
+
let currentMethod = method;
|
|
149
|
+
let currentBody = body;
|
|
96
150
|
|
|
97
151
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
152
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
153
|
+
const requestInit: RequestInit = {
|
|
154
|
+
signal: requestSignal,
|
|
155
|
+
method: currentMethod,
|
|
156
|
+
headers: {
|
|
157
|
+
"User-Agent": userAgent,
|
|
158
|
+
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
159
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
160
|
+
"Accept-Encoding": "identity", // Cloudflare Markdown-for-Agents returns corrupted bytes when compression is negotiated
|
|
161
|
+
...headers,
|
|
162
|
+
},
|
|
163
|
+
redirect: "manual",
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (currentBody !== undefined) {
|
|
167
|
+
requestInit.body = currentBody;
|
|
168
|
+
}
|
|
110
169
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
170
|
+
const response = await fetch(currentUrl, requestInit);
|
|
171
|
+
if (REDIRECT_STATUSES.has(response.status)) {
|
|
172
|
+
const location = response.headers.get("location");
|
|
173
|
+
if (!location) {
|
|
174
|
+
return {
|
|
175
|
+
content: "",
|
|
176
|
+
contentType: "",
|
|
177
|
+
finalUrl: currentUrl,
|
|
178
|
+
ok: false,
|
|
179
|
+
status: response.status,
|
|
180
|
+
error: "Redirect response missing Location header",
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const redirectUrl = new URL(location, currentUrl).toString();
|
|
184
|
+
if (publicUrlGuard) {
|
|
185
|
+
const guarded = await guardPublicFetchUrl(redirectUrl, resolver, "Blocked URL redirect");
|
|
186
|
+
if (!guarded.ok) {
|
|
187
|
+
return {
|
|
188
|
+
content: "",
|
|
189
|
+
contentType: "",
|
|
190
|
+
finalUrl: guarded.finalUrl,
|
|
191
|
+
ok: false,
|
|
192
|
+
status: response.status,
|
|
193
|
+
error: guarded.error,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
currentUrl = guarded.url;
|
|
197
|
+
} else {
|
|
198
|
+
currentUrl = redirectUrl;
|
|
199
|
+
}
|
|
200
|
+
if (shouldRewriteRedirectMethod(response.status, currentMethod)) {
|
|
201
|
+
currentMethod = "GET";
|
|
202
|
+
currentBody = undefined;
|
|
203
|
+
}
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
114
206
|
|
|
115
|
-
|
|
207
|
+
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
208
|
+
const finalUrl = response.url || currentUrl;
|
|
116
209
|
|
|
117
|
-
|
|
118
|
-
|
|
210
|
+
const reader = response.body?.getReader();
|
|
211
|
+
if (!reader) {
|
|
212
|
+
return { content: "", contentType, finalUrl, ok: false, status: response.status };
|
|
213
|
+
}
|
|
119
214
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return { content: "", contentType, finalUrl, ok: false, status: response.status };
|
|
123
|
-
}
|
|
215
|
+
const chunks: Uint8Array[] = [];
|
|
216
|
+
let totalSize = 0;
|
|
124
217
|
|
|
125
|
-
|
|
126
|
-
|
|
218
|
+
while (true) {
|
|
219
|
+
const { done, value } = await reader.read();
|
|
220
|
+
if (done) break;
|
|
127
221
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (done) break;
|
|
222
|
+
chunks.push(value);
|
|
223
|
+
totalSize += value.length;
|
|
131
224
|
|
|
132
|
-
|
|
133
|
-
|
|
225
|
+
if (totalSize > maxBytes) {
|
|
226
|
+
reader.cancel();
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
134
230
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
231
|
+
const content = Buffer.concat(chunks).toString("utf-8");
|
|
232
|
+
if (isBotBlocked(response.status, content) && attempt < USER_AGENTS.length - 1) {
|
|
233
|
+
continue attempts;
|
|
138
234
|
}
|
|
139
|
-
}
|
|
140
235
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
236
|
+
if (!response.ok) {
|
|
237
|
+
return { content, contentType, finalUrl, ok: false, status: response.status };
|
|
238
|
+
}
|
|
145
239
|
|
|
146
|
-
|
|
147
|
-
return { content, contentType, finalUrl, ok: false, status: response.status };
|
|
240
|
+
return { content, contentType, finalUrl, ok: true, status: response.status };
|
|
148
241
|
}
|
|
149
|
-
|
|
150
|
-
|
|
242
|
+
return {
|
|
243
|
+
content: "",
|
|
244
|
+
contentType: "",
|
|
245
|
+
finalUrl: currentUrl,
|
|
246
|
+
ok: false,
|
|
247
|
+
error: `Too many redirects (${maxRedirects})`,
|
|
248
|
+
};
|
|
151
249
|
} catch {
|
|
152
250
|
if (signal?.aborted) {
|
|
153
251
|
throw new ToolAbortError();
|
|
154
252
|
}
|
|
155
253
|
if (attempt === USER_AGENTS.length - 1) {
|
|
156
|
-
return { content: "", contentType: "", finalUrl:
|
|
254
|
+
return { content: "", contentType: "", finalUrl: currentUrl, ok: false };
|
|
157
255
|
}
|
|
158
256
|
}
|
|
159
257
|
}
|
|
160
258
|
|
|
161
|
-
return { content: "", contentType: "", finalUrl:
|
|
259
|
+
return { content: "", contentType: "", finalUrl: initialUrl, ok: false };
|
|
162
260
|
}
|
|
163
261
|
|
|
164
262
|
/** Module-level Turndown instance — built lazily on first use. */
|