@tbox.cn/tboxcode-dsh-tools 0.0.0-stage → 0.1.0-rc.10
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/lib/auto-commit/index.d.ts +2 -0
- package/lib/auto-commit/index.js +1 -0
- package/lib/auto-commit-FhjBfiMx.js +1 -0
- package/lib/index-BNOJI4FD.d.ts +34 -0
- package/lib/index-Bb9goxWJ.d.ts +14 -0
- package/lib/index-CNU9S13j.d.ts +52 -0
- package/lib/index-C_e95eAG.d.ts +23 -0
- package/lib/index-D8NxTQT6.d.ts +13 -0
- package/lib/index-bkf64gGn.d.ts +34 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.js +1 -0
- package/lib/pre-execute/index.d.ts +2 -0
- package/lib/pre-execute/index.js +1 -0
- package/lib/pre-execute-AkMe7eQo.js +1 -0
- package/lib/restrict/index.d.ts +2 -0
- package/lib/restrict/index.js +1 -0
- package/lib/restrict-CldLToKG.js +1 -0
- package/lib/scratch/index.d.ts +2 -0
- package/lib/scratch/index.js +1 -0
- package/lib/scratch-ak4Wn8Xe.js +2 -0
- package/lib/skill-provider/index.d.ts +2 -0
- package/lib/skill-provider/index.js +1 -0
- package/lib/skill-provider-DenqO0Yu.js +7 -0
- package/lib/webfetch/index.d.ts +2 -0
- package/lib/webfetch/index.js +1 -0
- package/lib/webfetch-CXvjRbDU.js +4 -0
- package/package.json +62 -3
- package/README.md +0 -3
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as RunAutoCommitOptions, c as name, d as shouldSkip, i as GitRunner, l as pushOnly, n as Config, o as apply, r as GitResult, s as defaultGitRunner, t as AutoCommitOutcome, u as runAutoCommit } from "../index-CNU9S13j.js";
|
|
2
|
+
export { AutoCommitOutcome, Config, GitResult, GitRunner, RunAutoCommitOptions, apply, defaultGitRunner, name, pushOnly, runAutoCommit, shouldSkip };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"../auto-commit-FhjBfiMx.js";export{a as apply,n as defaultGitRunner,i as name,t as pushOnly,e as runAutoCommit,r as shouldSkip};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";import{join as t}from"node:path";import{existsSync as n}from"node:fs";import{execFile as r}from"node:child_process";import{promisify as i}from"node:util";const a=i(r),o=`tboxcode-auto-commit`,s=e.object({enabled:e.boolean().optional(),push:e.boolean().optional(),remote:e.string().optional(),branch:e.string().optional(),commitMessage:e.string().optional(),pendingRetryMs:e.number().int().positive().optional(),authorName:e.string().optional(),authorEmail:e.string().optional(),maxAttempts:e.number().int().min(1).max(10).optional()}),c=async(e,t,n)=>{let r=await a(`git`,[...e],{cwd:t,env:{...process.env,...n},maxBuffer:16*1024*1024});return{stdout:r.stdout,stderr:r.stderr}};function l(e){return{GIT_AUTHOR_NAME:e.authorName??process.env.TBOX_GIT_AUTHOR_NAME??`CodingBox`,GIT_AUTHOR_EMAIL:e.authorEmail??process.env.TBOX_GIT_AUTHOR_EMAIL??`codingbox@tbox.cn`,GIT_COMMITTER_NAME:e.authorName??process.env.TBOX_GIT_AUTHOR_NAME??`CodingBox`,GIT_COMMITTER_EMAIL:e.authorEmail??process.env.TBOX_GIT_AUTHOR_EMAIL??`codingbox@tbox.cn`}}function u(e,r){if(e===void 0||e.length===0)return{kind:`skipped`,reason:`no-cwd`};if(r.enabled!==!0)return{kind:`skipped`,reason:`disabled`};if(n(t(e,`.git`,`TBOX_INIT_IN_PROGRESS`)))return{kind:`skipped`,reason:`init-in-progress`}}async function d(e,t,n,r){let i=n.remote??`origin`,a=n.branch,o=n.push===!1?[]:a===void 0?[`push`]:[`push`,i,a];if(o.length!==0)try{await e(o,t,r);return}catch{await e([`push`,i,`HEAD`],t,r)}}async function f(e){let{cwd:t,config:n}=e;await d(e.git??c,t,n,l(n))}async function p(e){let{cwd:t,config:n}=e,r=u(t,n);if(r!==void 0)return r;let i=e.git??c,a=l(n);if((await i([`status`,`--porcelain`],t,a)).stdout.trim().length===0)return{kind:`noop`};await i([`add`,`-A`],t,a);let o=n.commitMessage??`chore: auto-commit at ${(e.now??(()=>new Date))().toISOString()}`;await i([`commit`,`--no-verify`,`-m`,o],t,a);try{return await d(i,t,n,a),{kind:`committed`,pushed:n.push!==!1,commit:o}}catch(e){return{kind:`push-failed`,commit:o,error:e instanceof Error?e.message:String(e)}}}function m(e,t={}){let n=s.parse(t),r=n.maxAttempts??3,i=n.pendingRetryMs??3e4,a=new Map,o=new Set,c=e.logger,l=async t=>{let a=!1,s;for(let l=1;l<=r;l++)try{if(a){await f({cwd:t,config:n}),o.delete(t),e.emit?.(`tboxcode/git_push`,{cwd:t,ok:!0,...s===void 0?{}:{commit:s},attempt:l});return}let u=await p({cwd:t,config:n});if(u.kind===`push-failed`){if(o.add(t),s=u.commit,a=!0,e.emit?.(`tboxcode/git_push`,{cwd:t,ok:!1,error:u.error,attempt:l}),c?.warn(`[tboxcode-auto-commit] push failed (${t}): ${u.error}`),l<r){await new Promise(e=>setTimeout(e,l*i));continue}return}o.delete(t),u.kind===`committed`&&e.emit?.(`tboxcode/git_push`,{cwd:t,ok:!0,commit:u.commit});return}catch(e){if(c?.warn(`[tboxcode-auto-commit] attempt ${l} failed: ${e instanceof Error?e.message:String(e)}`),l>=r)return;await new Promise(e=>setTimeout(e,l*i))}},d=e=>{if(a.has(e))return;let t=l(e).catch(e=>c?.warn(`[tboxcode-auto-commit] ${e instanceof Error?e.message:String(e)}`)).finally(()=>a.delete(e));a.set(e,t)};if(e.on(`session/event`,(e,t)=>{if(t.type!==`turn/end`)return;let r=e.header;if(r?.origin===`subagent`||r?.parentSession!==void 0)return;let i=r?.cwd;i!==void 0&&u(i,n)===void 0&&d(i)}),n.enabled===!0)for(let e of o)d(e);return()=>{a.clear(),o.clear()}}export{p as a,f as i,c as n,u as o,o as r,m as t};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/pre-execute/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare const name = "tboxcode-pre-execute";
|
|
6
|
+
declare const inject: string[];
|
|
7
|
+
interface Config {
|
|
8
|
+
/** permission 映射(config `permission` 翻译域)。 */
|
|
9
|
+
permission?: Record<string, 'allow' | 'ask' | 'deny'>;
|
|
10
|
+
/** plan 档 MCP 写类模式表(后缀或完整名;缺省内置写类动词表)。 */
|
|
11
|
+
mcpDenyPatterns?: string[];
|
|
12
|
+
/** 拒绝访问的绝对/相对路径前缀(pre-execute 最佳努力;非 per-path sandbox)。 */
|
|
13
|
+
denyPaths?: string[];
|
|
14
|
+
}
|
|
15
|
+
/** 内置 MCP 写类模式表(保守后缀匹配——误伤面最小化,Revisions 维护义务)。 */
|
|
16
|
+
declare const DEFAULT_MCP_DENY_PATTERNS: readonly string[];
|
|
17
|
+
/** permission 优先级链(源 permission-policy resolveToolPermission 移植,
|
|
18
|
+
* dsh 侧无 sideEffecting/defaultPermission 面——无匹配返回 undefined 透传):
|
|
19
|
+
* exact → 最长 `prefix_*` 通配 → 组精确/通配 → `*` 全局。 */
|
|
20
|
+
declare function resolveToolPermission(toolName: string, permission: Record<string, 'allow' | 'ask' | 'deny'> | undefined, permissionGroups?: readonly string[]): 'allow' | 'ask' | 'deny' | undefined;
|
|
21
|
+
/** MCP 写类命中:只认 dsh mcp-client 的 `mcp__<server>__<tool>` 命名空间;
|
|
22
|
+
* `_` 分段精确匹配(模式词剥前导 `_`;如 `mcp__github__create_issue` 的
|
|
23
|
+
* [mcp, github, create, issue] 含 'create')或完整名匹配。分段制覆盖写类
|
|
24
|
+
* 动词位于任意段位的 MCP sanitized 名形态。原生下划线工具(scratch_write /
|
|
25
|
+
* todo_write / str_replace_editor 等)不进入此判定——命名空间前缀是唯一
|
|
26
|
+
* 可靠区分面(ToolExecution 不携带工具来源元数据)。 */
|
|
27
|
+
declare function matchesMcpDenyPattern(toolName: string, patterns: readonly string[]): boolean;
|
|
28
|
+
/** 从 exec.arguments 收集路径(已知键 + bash command token)。 */
|
|
29
|
+
declare function collectExecutionPaths(name: string, args: unknown): string[];
|
|
30
|
+
/** 命中任一 denyPaths 前缀即返回命中的配置项。 */
|
|
31
|
+
declare function matchDenyPath(candidate: string, denyPaths: readonly string[], cwd: string): string | undefined;
|
|
32
|
+
declare function apply(ctx: Context, config?: Config): () => void;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { inject as a, name as c, collectExecutionPaths as i, resolveToolPermission as l, DEFAULT_MCP_DENY_PATTERNS as n, matchDenyPath as o, apply as r, matchesMcpDenyPattern as s, Config as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/webfetch/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare const name = "tboxcode-webfetch";
|
|
6
|
+
declare const inject: string[];
|
|
7
|
+
/** 插件行 config(翻译域值;内部防御校验)。 */
|
|
8
|
+
interface Config {
|
|
9
|
+
maxLines?: number;
|
|
10
|
+
maxBytes?: number;
|
|
11
|
+
}
|
|
12
|
+
declare function apply(ctx: Context, config?: Config): () => void;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { name as i, apply as n, inject as r, Config as t };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/auto-commit/index.d.ts
|
|
4
|
+
declare const name = "tboxcode-auto-commit";
|
|
5
|
+
interface Config {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
push?: boolean;
|
|
8
|
+
remote?: string;
|
|
9
|
+
branch?: string;
|
|
10
|
+
commitMessage?: string;
|
|
11
|
+
pendingRetryMs?: number;
|
|
12
|
+
authorName?: string;
|
|
13
|
+
authorEmail?: string;
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
}
|
|
16
|
+
interface GitResult {
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
}
|
|
20
|
+
type GitRunner = (args: readonly string[], cwd: string, env?: NodeJS.ProcessEnv) => Promise<GitResult>;
|
|
21
|
+
declare const defaultGitRunner: GitRunner;
|
|
22
|
+
type AutoCommitOutcome = {
|
|
23
|
+
kind: 'skipped';
|
|
24
|
+
reason: 'no-cwd' | 'subagent' | 'init-in-progress' | 'disabled';
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'noop';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'committed';
|
|
29
|
+
pushed: boolean;
|
|
30
|
+
commit: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'push-failed';
|
|
33
|
+
commit: string;
|
|
34
|
+
error: string;
|
|
35
|
+
};
|
|
36
|
+
interface RunAutoCommitOptions {
|
|
37
|
+
cwd: string;
|
|
38
|
+
config: Config;
|
|
39
|
+
git?: GitRunner;
|
|
40
|
+
now?: () => Date;
|
|
41
|
+
}
|
|
42
|
+
/** 初始化标记 / 非 git 目录 / 无 cwd 的跳过判定。 */
|
|
43
|
+
declare function shouldSkip(cwd: string | undefined, config: Config): AutoCommitOutcome | undefined;
|
|
44
|
+
/** 仅重试 push(commit 已落的 pending 补推;不伪造新 commit)。 */
|
|
45
|
+
declare function pushOnly(options: Omit<RunAutoCommitOptions, 'config'> & {
|
|
46
|
+
config: Config;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
/** 一次 turn/end 的自动提交(纯函数;测试注入 git runner)。 */
|
|
49
|
+
declare function runAutoCommit(options: RunAutoCommitOptions): Promise<AutoCommitOutcome>;
|
|
50
|
+
declare function apply(ctx: Context, config?: Config): () => void;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { RunAutoCommitOptions as a, name as c, shouldSkip as d, GitRunner as i, pushOnly as l, Config as n, apply as o, GitResult as r, defaultGitRunner as s, AutoCommitOutcome as t, runAutoCommit as u };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/skill-provider/index.d.ts
|
|
4
|
+
declare const name = "tboxcode-skill-provider";
|
|
5
|
+
declare const inject: string[];
|
|
6
|
+
/** 插件行 config(`skills.paths` 翻译域 + configDir 注入 + watcher 节奏)。 */
|
|
7
|
+
interface Config {
|
|
8
|
+
/** 额外扫描根(config `skills.paths` 翻译域,C8)。 */
|
|
9
|
+
paths?: string[];
|
|
10
|
+
/** tboxcode configDir(缺省 `~/.config/tboxcode-dsh`——翻译域不传时兜底)。 */
|
|
11
|
+
configDir?: string;
|
|
12
|
+
/** 轮询间隔 ms(缺省 2000;测试注入短间隔)。 */
|
|
13
|
+
pollIntervalMs?: number;
|
|
14
|
+
/** 变更稳定窗口 ms(缺省 500;测试注入短窗口)。 */
|
|
15
|
+
settleWindowMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/** 统一 rank(note 定案:< 原生项目根 100)。 */
|
|
18
|
+
declare const TBOXCODE_SKILL_RANK = 50;
|
|
19
|
+
/** cwd 向上每级两目录(近→远;源 collectCwdUpSkillRoots 移植)。 */
|
|
20
|
+
declare function collectCwdUpSkillRoots(cwd: string): string[];
|
|
21
|
+
declare function apply(ctx: Context, config?: Config): () => void;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { inject as a, collectCwdUpSkillRoots as i, TBOXCODE_SKILL_RANK as n, name as o, apply as r, Config as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/restrict/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare const name = "tboxcode-restrict";
|
|
6
|
+
declare const inject: string[];
|
|
7
|
+
interface Config {
|
|
8
|
+
/** `'slash-only'`:skill 工具对模型不可见(仅 user 手势可调)。 */
|
|
9
|
+
skills?: 'slash-only';
|
|
10
|
+
}
|
|
11
|
+
declare function apply(ctx: Context, config?: Config): () => void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { name as i, apply as n, inject as r, Config as t };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/scratch/index.d.ts
|
|
4
|
+
declare const name = "tboxcode-scratch";
|
|
5
|
+
declare const inject: string[];
|
|
6
|
+
/** 结构面(dsh 类型子集——零 peer 膨胀)。 */
|
|
7
|
+
interface SandboxExecutionPolicy {
|
|
8
|
+
mode: string;
|
|
9
|
+
workspaceRoot: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 会话私有 scratch 目录(布局单源约定:与 bundle/prompts.ts 的 scratchDirFor 保持一致)。 */
|
|
13
|
+
declare function scratchDirFor(sessionId: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* session cwd(历史导出保留——旧解析语义;scratch 内部自 2026-11-03 起不再
|
|
16
|
+
* 使用,路径根 = scratch 目录,决策 [plan-mode-sandbox-composition] Revisions)。
|
|
17
|
+
*/
|
|
18
|
+
declare function resolveWithSessionCwd(modelPath: string | undefined, cwd: string | undefined): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* scratch 根解析:相对 → scratch 目录(node:path.resolve 归一);绝对原样;
|
|
21
|
+
* undefined → scratch 目录。
|
|
22
|
+
*/
|
|
23
|
+
declare function resolveScratchPath(modelPath: string | undefined, scratchDir: string): string;
|
|
24
|
+
/** per-call 特赦 policy 构造(工作区 = scratch 目录——/tmp 系由 workspace-write
|
|
25
|
+
* 档 writableRoots 原生覆盖)。 */
|
|
26
|
+
declare function scratchPolicy(sessionId: string): SandboxExecutionPolicy;
|
|
27
|
+
/**
|
|
28
|
+
* 幂等 ensure:根与会话目录都必须是真实目录。
|
|
29
|
+
* 竞态(ENOTDIR / EEXIST / ENOENT)有限重试;最终失败带路径与底层 cause。
|
|
30
|
+
*/
|
|
31
|
+
declare function ensureScratchDir(dir: string): Promise<void>;
|
|
32
|
+
declare function apply(ctx: Context): () => void;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolveScratchPath as a, scratchPolicy as c, name as i, ensureScratchDir as n, resolveWithSessionCwd as o, inject as r, scratchDirFor as s, apply as t };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { c as name, d as shouldSkip, l as pushOnly, n as Config, o as apply, t as AutoCommitOutcome, u as runAutoCommit } from "./index-CNU9S13j.js";
|
|
2
|
+
import { i as name$5, n as apply$5 } from "./index-Bb9goxWJ.js";
|
|
3
|
+
import { i as collectCwdUpSkillRoots, n as TBOXCODE_SKILL_RANK, o as name$4, r as apply$4 } from "./index-C_e95eAG.js";
|
|
4
|
+
import { i as name$2, n as apply$2 } from "./index-D8NxTQT6.js";
|
|
5
|
+
import { c as name$1, i as collectExecutionPaths, l as resolveToolPermission, n as DEFAULT_MCP_DENY_PATTERNS, o as matchDenyPath, r as apply$1, s as matchesMcpDenyPattern } from "./index-BNOJI4FD.js";
|
|
6
|
+
import { a as resolveScratchPath, c as scratchPolicy, i as name$3, o as resolveWithSessionCwd, s as scratchDirFor, t as apply$3 } from "./index-bkf64gGn.js";
|
|
7
|
+
import { ToolRunContext } from "@deepseek-ai/dsh-tools";
|
|
8
|
+
|
|
9
|
+
//#region src/webfetch/webfetch-core.d.ts
|
|
10
|
+
|
|
11
|
+
/** 截断缺省(parity:openacpagent truncate.ts MAX_LINES/MAX_BYTES)。 */
|
|
12
|
+
declare const TRUNCATE_MAX_LINES = 2000;
|
|
13
|
+
declare const TRUNCATE_MAX_BYTES: number;
|
|
14
|
+
declare function extractTextFromHTML(html: string): Promise<string>;
|
|
15
|
+
interface Hop {
|
|
16
|
+
readonly url: string;
|
|
17
|
+
readonly kind: 'js' | 'meta';
|
|
18
|
+
}
|
|
19
|
+
declare function detectRedirect(html: string, baseUrl: string): Hop | null;
|
|
20
|
+
/** 流式读取响应体,字节上限保护(防极端 OOM;SSRF 职责归运行沙箱)。 */
|
|
21
|
+
declare function readLimitedResponse(resp: Response, maxBytes: number): Promise<Buffer>;
|
|
22
|
+
interface TruncateOptions {
|
|
23
|
+
max_lines?: number;
|
|
24
|
+
max_bytes?: number;
|
|
25
|
+
}
|
|
26
|
+
/** 截断落盘 sink(工具装配点注入;缺席 = 纯截断降级)。 */
|
|
27
|
+
interface TruncateSink {
|
|
28
|
+
(text: string, exec: ToolRunContext): Promise<string | undefined>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 统一输出截断:行/字节双限 head 保留;截断时全量经 sink 落盘(缺席或失败
|
|
32
|
+
* → 纯截断降级,零异常外泄)。截断注记格式对齐投影基准:
|
|
33
|
+
* `[output truncated: N lines omitted]`。
|
|
34
|
+
*/
|
|
35
|
+
declare function truncateOutput(text: string, exec: ToolRunContext, options?: TruncateOptions, sink?: TruncateSink): Promise<{
|
|
36
|
+
content: string;
|
|
37
|
+
truncated: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
interface WebfetchInput {
|
|
40
|
+
url: string;
|
|
41
|
+
format?: 'text' | 'markdown' | 'html';
|
|
42
|
+
timeout?: number;
|
|
43
|
+
}
|
|
44
|
+
interface WebfetchDeps {
|
|
45
|
+
/** 截断参数(插件 config,缺省 2000 行 / 50KB)。 */
|
|
46
|
+
max_lines?: number;
|
|
47
|
+
max_bytes?: number;
|
|
48
|
+
/** 截断落盘 sink(spillStore 装配;缺席 = 纯截断降级)。 */
|
|
49
|
+
spillSink?: TruncateSink;
|
|
50
|
+
}
|
|
51
|
+
declare function executeWebfetch(input: WebfetchInput, exec: ToolRunContext, deps?: WebfetchDeps): Promise<string>;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/skill-provider/frontmatter.d.ts
|
|
54
|
+
interface ParsedSkillFile {
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
allowedTools?: string[];
|
|
58
|
+
hidden: boolean;
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
60
|
+
content: string;
|
|
61
|
+
contentHash: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 解析 SKILL.md 原文。无 frontmatter / 无 name / YAML 解析失败 → undefined。
|
|
65
|
+
* 未知顶层字段并入 metadata(spike 结论"未知字段不破坏解析、技能不丢"的
|
|
66
|
+
* dsh metadata 通道落位);contentHash = sha256(原文) 前 16 hex。
|
|
67
|
+
*/
|
|
68
|
+
declare function parseSkillFile(raw: string, yamlParse: (s: string) => unknown): ParsedSkillFile | undefined;
|
|
69
|
+
/** 目录描述截断上限(`catalogDescriptionMaxLength 1024` 翻译域的语义源头)。 */
|
|
70
|
+
declare const MAX_SKILL_DESC = 1024;
|
|
71
|
+
/** 折行 → 截断至 MAX_SKILL_DESC 码点(确定性——截断点外变更不改 hash)。 */
|
|
72
|
+
declare function formatSkillDesc(desc: string | undefined): string;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { type Config as AutoCommitConfig, type AutoCommitOutcome, DEFAULT_MCP_DENY_PATTERNS, MAX_SKILL_DESC, TBOXCODE_SKILL_RANK, TRUNCATE_MAX_BYTES, TRUNCATE_MAX_LINES, type TruncateOptions, type TruncateSink, type WebfetchDeps, type WebfetchInput, apply as autoCommitApply, name as autoCommitName, collectCwdUpSkillRoots, collectExecutionPaths, detectRedirect, executeWebfetch, extractTextFromHTML, formatSkillDesc, matchDenyPath, matchesMcpDenyPattern, parseSkillFile, apply$1 as preExecuteApply, name$1 as preExecuteName, pushOnly, readLimitedResponse, resolveScratchPath, resolveToolPermission, resolveWithSessionCwd, apply$2 as restrictApply, name$2 as restrictName, runAutoCommit, apply$3 as scratchApply, scratchDirFor, name$3 as scratchName, scratchPolicy, shouldSkip, apply$4 as skillProviderApply, name$4 as skillProviderName, truncateOutput, apply$5 as webfetchApply, name$5 as webfetchName };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,i as n,l as r,o as i,r as a,s as o,t as s,u as c}from"./webfetch-CXvjRbDU.js";import{a as l,c as u,n as d,o as f,r as p,s as m,t as h}from"./skill-provider-DenqO0Yu.js";import{r as g,t as _}from"./restrict-CldLToKG.js";import{a as v,c as y,n as b,o as x,r as S,s as C,t as w}from"./pre-execute-AkMe7eQo.js";import{a as T,i as E,o as D,r as O,t as k}from"./auto-commit-FhjBfiMx.js";import{a as A,c as j,i as M,o as N,s as P,t as F}from"./scratch-ak4Wn8Xe.js";export{w as DEFAULT_MCP_DENY_PATTERNS,f as MAX_SKILL_DESC,h as TBOXCODE_SKILL_RANK,n as TRUNCATE_MAX_BYTES,e as TRUNCATE_MAX_LINES,k as autoCommitApply,O as autoCommitName,p as collectCwdUpSkillRoots,S as collectExecutionPaths,i as detectRedirect,o as executeWebfetch,t as extractTextFromHTML,m as formatSkillDesc,v as matchDenyPath,x as matchesMcpDenyPattern,u as parseSkillFile,b as preExecuteApply,C as preExecuteName,E as pushOnly,r as readLimitedResponse,A as resolveScratchPath,y as resolveToolPermission,N as resolveWithSessionCwd,_ as restrictApply,g as restrictName,T as runAutoCommit,F as scratchApply,P as scratchDirFor,M as scratchName,j as scratchPolicy,D as shouldSkip,d as skillProviderApply,l as skillProviderName,c as truncateOutput,s as webfetchApply,a as webfetchName};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as inject, c as name, i as collectExecutionPaths, l as resolveToolPermission, n as DEFAULT_MCP_DENY_PATTERNS, o as matchDenyPath, r as apply, s as matchesMcpDenyPattern, t as Config } from "../index-BNOJI4FD.js";
|
|
2
|
+
export { Config, DEFAULT_MCP_DENY_PATTERNS, apply, collectExecutionPaths, inject, matchDenyPath, matchesMcpDenyPattern, name, resolveToolPermission };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"../pre-execute-AkMe7eQo.js";export{s as DEFAULT_MCP_DENY_PATTERNS,r as apply,a as collectExecutionPaths,n as inject,e as matchDenyPath,i as matchesMcpDenyPattern,o as name,t as resolveToolPermission};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";import{homedir as t}from"node:os";import{isAbsolute as n,join as r,resolve as i,sep as a}from"node:path";import{existsSync as o,realpathSync as s}from"node:fs";const c=`tboxcode-pre-execute`,l=[`tools`],u=e.enum([`allow`,`ask`,`deny`]),d=e.object({permission:e.record(e.string(),u).optional(),mcpDenyPatterns:e.array(e.string()).optional(),denyPaths:e.array(e.string()).optional()}),f=[`_write`,`_create`,`_update`,`_delete`,`_remove`,`_patch`,`_modify`,`_rename`,`_move`,`_copy`,`_upload`,`_send`,`_deploy`,`_publish`,`_commit`,`_push`,`_post`,`_put`,`_insert`,`_replace`];function p(e,t,n){if(t===void 0)return;let r=t[e];if(r!==void 0)return r;let i=-1,a;for(let n of Object.keys(t))if(n.endsWith(`_*`)){let r=n.slice(0,-2);e.startsWith(`${r}_`)&&r.length>i&&(i=r.length,a=t[n])}if(a!==void 0)return a;if(n!==void 0&&n.length>0){for(let e of n){let n=t[e];if(n!==void 0)return n}for(let e of Object.keys(t))if(e.endsWith(`:*`)){let r=e.slice(0,-2);for(let i of n)if(i.startsWith(`${r}:`))return t[e]}}return t[`*`]}function m(e,t){if(!e.startsWith(`mcp__`))return!1;let n=new Set(e.split(`_`));for(let r of t){if(r===e)return!0;let t=r.startsWith(`_`)?r.slice(1):r;if(t.length>0&&n.has(t))return!0}return!1}const h=new Set([`path`,`paths`,`file`,`files`,`file_path`,`filePath`,`target`,`targetPath`,`workdir`,`cwd`,`directory`,`dir`,`location`,`source`,`destination`]);function g(e,a){let c=e.trim();if(c.length===0)return;let l=c===`~`?t():c.startsWith(`~/`)?r(t(),c.slice(2)):c,u=n(l)?i(l):i(a,l);try{return o(u)?s(u):u}catch{return u}}function _(e){let t=e.replace(/\/+$/,``)||`/`;if(t===`/`)return e=>e.startsWith(`/`);if(!t.includes(`*`))return e=>e===t||e.startsWith(t+a);let n=t.replace(/[.+?^${}()|[\]\\]/g,`\\$&`),r=RegExp(`^${n.replace(/\*\*/g,`.*`).replace(/\*/g,`[^/]*`)}(?:/|$)`);return e=>r.test(e)}function v(e,t){let n=[],r=(t,i,a)=>{if(!(a>6||t==null)){if(typeof t==`string`){i!==void 0&&h.has(i)&&n.push(t);return}if(Array.isArray(t)){for(let e of t)r(e,i,a+1);return}if(typeof t==`object`)for(let[i,o]of Object.entries(t)){if(i===`command`&&typeof o==`string`&&(e===`bash`||e===`scratch_bash`)){for(let e of o.split(/\s+/)){let t=e.replace(/^['"]|['"]$/g,``);(t.startsWith(`~`)||t.includes(`/`))&&n.push(t)}continue}r(o,i,a+1)}}};return r(t,void 0,0),n}function y(e,t,n){let r=g(e,n);if(r!==void 0)for(let e of t){let t=g(e,n);if(t!==void 0&&_(t)(r))return e}}function b(e){let t=e.agent?.session?.header;return typeof t?.cwd==`string`&&t.cwd.length>0?t.cwd:process.cwd()}function x(e,t={}){let n=d.parse(t),r=n.permission,i=n.denyPaths??[],a=n.mcpDenyPatterns??f,o=e.get(`sessionProjections`);return e.on(`tools/pre-execute`,async(e,t)=>{if(i.length>0){let t=b(e);for(let n of v(e.name,e.arguments)){let e=y(n,i,t);if(e!==void 0)return{kind:`deny`,reason:`Path '${n}' is denied by the security configuration (matched '${e}'). Do not retry this path; use an allowed location or ask the user.`}}}if(p(e.name,r)===`deny`)return{kind:`deny`,reason:`Tool '${e.name}' is denied by the permission configuration. Do not retry this tool; use an alternative approach or ask the user.`};if(o!==void 0&&e.agent!==void 0)try{if(o.stateOf(e.agent.session,`sandboxMode`)===`read-only`&&m(e.name,a))return{kind:`deny`,reason:`Plan mode is active (read-only): the MCP tool '${e.name}' may modify external systems, so it is blocked. Record the intended action in the plan instead, or ask the user to switch to build mode to execute it.`}}catch{}return t()}),()=>{}}export{y as a,p as c,l as i,x as n,m as o,v as r,c as s,f as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"../restrict-CldLToKG.js";export{n as apply,e as inject,t as name};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";const t=`tboxcode-restrict`,n=[`tools`],r=e.object({skills:e.literal(`slash-only`).optional()});function i(e){let t=new Map,n=e=>{if(!t.has(e))try{let n=e.ctx.tools.restrict({deny:[`skill`]});t.set(e,n)}catch{}};for(let t of e.agents.list())n(t);return e.on(`agent/created`,({agent:e})=>{n(e)}),e.on(`agent/disposed`,({agent:e})=>{t.delete(e)}),()=>{t.clear()}}function a(e,t={}){return r.parse(t).skills===`slash-only`?i(e):()=>{}}export{n,t as r,a as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as resolveScratchPath, c as scratchPolicy, i as name, n as ensureScratchDir, o as resolveWithSessionCwd, r as inject, s as scratchDirFor, t as apply } from "../index-bkf64gGn.js";
|
|
2
|
+
export { apply, ensureScratchDir, inject, name, resolveScratchPath, resolveWithSessionCwd, scratchDirFor, scratchPolicy };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"../scratch-ak4Wn8Xe.js";export{s as apply,r as ensureScratchDir,a as inject,n as name,e as resolveScratchPath,i as resolveWithSessionCwd,o as scratchDirFor,t as scratchPolicy};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{defineTool as e}from"@deepseek-ai/dsh-tools";import{lstat as t,mkdir as n,rename as r}from"node:fs/promises";import{tmpdir as i}from"node:os";import{basename as a,dirname as o,isAbsolute as s,join as c,resolve as l,sep as u}from"node:path";import{randomUUID as d}from"node:crypto";const f=`tboxcode-scratch`,p=[`tools`,`shell`,`fs`],m=c(i(),`tboxcode-scratch`);function h(e){return c(m,e)}function g(e,t){if(e===void 0)return t;if(s(e))return e;if(t!==void 0)return`${t}${u}${e}`}function _(e,t){return e===void 0?t:s(e)?e:l(t,e)}function v(e){return{mode:`workspace-write`,workspaceRoot:h(e),sessionId:e}}async function y(e){try{return await t(e)}catch(e){let t=e.code;if(t===`ENOENT`||t===`ENOTDIR`)return;throw e}}async function b(e){let t=c(o(e),`.${a(e)}.displaced-${Date.now()}-${d().slice(0,8)}`);try{await r(e,t)}catch(e){if(e.code!==`ENOENT`)throw e}}async function x(e){let t=await y(e);t?.isDirectory()||(t!==void 0&&await b(e),await n(e,{recursive:!0,mode:448}))}async function S(e){let t=o(e),n;for(let r=0;r<3;r++)try{await x(t),await x(e);return}catch(e){n=e;let t=e.code;if(t!==`ENOTDIR`&&t!==`EEXIST`&&t!==`ENOENT`)break}let r=n instanceof Error?n.message:String(n);throw Error(`scratch directory "${e}" could not be prepared: ${r}`)}function C(e){return e===void 0?``:e.truncated===!0?`${e.text}\n[output truncated; full output: ${e.spillPath??`(unavailable)`}]`:e.text}function w(e,t){let n=[`cwd: ${t}`],r=C(e.stdout),i=C(e.stderr);return n.push(`exitCode: ${e.exitCode??`null`}${e.timedOut?` (timed out)`:``}${e.aborted?` (aborted)`:``}`),e.signal&&n.push(`signal: ${e.signal}`),r.trim().length>0&&n.push(`stdout:\n${r}`),i.trim().length>0&&n.push(`stderr:\n${i}`),e.sandbox?.runnerFailed?n.push(`[sandbox: runner failed under ${e.sandbox.mode} mode]`):e.sandbox?.denied&&n.push(`[sandbox: file access denied under ${e.sandbox.mode} mode]`),n.join(`
|
|
2
|
+
`)}function T(e){return typeof e==`object`&&!!e&&e.code===`FS_SANDBOX_DENIED`}function E(e,t,n){return n?`cannot write "${e}": plan (read-only) mode allows writes only inside ${t} (system temp). Record workspace changes in the plan, or ask the user to switch to build mode.`:`cannot write "${e}": use write/edit for workspace files (scratch tools default to ${t}).`}const D={schema:{type:`object`,additionalProperties:!1,properties:{path:{type:`string`,required:!0,description:`Absolute path written.`},operation:{type:`string`,required:!0,enum:[`create`,`update`]},before:{required:!0,oneOf:[{type:`string`},{type:`null`}]},after:{type:`string`,required:!0},message:{type:`string`,required:!0}}},render:(e,t)=>[{type:`text`,text:t.message}],presentationMeta:(e,t)=>({path:t.path,operation:t.operation,diffs:[{path:t.path,oldText:t.before,newText:t.after}]})};function O(t){let n=t.shell,r=t.fs,i=async e=>{let n;try{if(n=e?.session?.header?.id,n===void 0)return;await S(h(n))}catch(e){try{t.logger?.warn?.(`scratch: pre-create failed for ${n??`unknown`}: ${e instanceof Error?e.message:String(e)}`)}catch{}}},a=t.on(`agent/created`,({agent:e})=>i(e)),o=e=>{let t=e.agent?.session?.header?.id??`adhoc-${d()}`;return{sessionId:t,dir:h(t)}},s=e=>{try{let n=t.get?.(`sandboxPolicy`),r=e.agent?.session;return n===void 0||r===void 0?void 0:n.resolve({session:r})}catch{return}},c=(e,t)=>t===void 0||t.mode===`read-only`?v(e):t,l=[t.tools.register(e({name:`scratch_bash`,description:`Run a bash command in the session scratch directory (system temp), not the project workspace. The working directory and relative paths resolve inside the scratch directory; use absolute paths or cd to inspect the workspace. In plan (read-only) mode this is the writable exception (scratch and system temp only); in build mode it follows the session policy like bash.`,parameters:{command:{type:`string`,required:!0,description:`The bash command to execute inside the scratch directory.`},description:{type:`string`,required:!0,description:`Clear, concise description of what this command does, 5-10 words.`},timeoutMs:{type:`number`,description:`Timeout in milliseconds; the executor applies its configured default and cap.`}},output:{schema:{type:`string`},render:(e,t)=>[{type:`text`,text:String(t)}]},async execute(e,t){let{sessionId:r,dir:i}=o(t),a=c(r,s(t));await S(i);let l={command:e.command,workdir:i,...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},signal:t.signal,sandboxPolicy:a},u=n.resolve(l);return w(await(await n.execute(u)).result(),i)}})),t.tools.register(e({name:`scratch_write`,description:`Create or overwrite a file in the session scratch directory (system temp). Relative paths resolve inside the scratch directory, not the workspace; absolute paths follow the session policy. Prefer write for workspace files. In plan (read-only) mode only the scratch directory and system temp are writable.`,parameters:{filePath:{type:`string`,required:!0,description:`Target file path; relative paths resolve inside the scratch directory.`},content:{type:`string`,required:!0,description:`Full file content to write.`}},output:D,async execute(e,t){let{sessionId:n,dir:i}=o(t),a=s(t),l=c(n,a);await S(i);let u=_(e.filePath,i),d=await r.resolve(u,{signal:t.signal}),f;try{f=await r.writeText(d,e.content,void 0,t.signal,l)}catch(e){throw T(e)?Error(E(u,i,a?.mode===`read-only`)):e}return{path:u,operation:f.operation??`update`,before:f.before??null,after:f.after??e.content,message:`written: ${u} (version ${String(f.version)})`}}})),t.tools.register(e({name:`scratch_edit`,description:`Edit a file in the session scratch directory (system temp) by exact literal replacement. Relative paths resolve inside the scratch directory, not the workspace; absolute paths follow the session policy. Prefer edit for workspace files. In plan (read-only) mode only the scratch directory and system temp are writable.`,parameters:{filePath:{type:`string`,required:!0,description:`Target file path; relative paths resolve inside the scratch directory.`},oldString:{type:`string`,required:!0,description:`Literal text to replace; must match exactly.`},newString:{type:`string`,required:!0,description:`Replacement text (empty string deletes the match).`},replaceAll:{type:`boolean`,description:`Replace every match instead of requiring exactly one (default false).`}},output:D,async execute(e,t){let{sessionId:n,dir:i}=o(t),a=s(t),l=c(n,a);await S(i);let u=_(e.filePath,i),d=await r.resolve(u,{signal:t.signal}),f;try{f=await r.editText(d,{oldString:e.oldString,newString:e.newString,replaceAll:e.replaceAll??!1},void 0,t.signal,l)}catch(e){throw T(e)?Error(E(u,i,a?.mode===`read-only`)):e}return{path:u,operation:`update`,before:f.before??``,after:f.after??``,message:`edited: ${u} (version ${String(f.version)})`}}}))];return()=>{a();for(let e of l)e()}}export{_ as a,v as c,f as i,S as n,g as o,p as r,h as s,O as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"../skill-provider-DenqO0Yu.js";export{i as TBOXCODE_SKILL_RANK,n as apply,r as collectCwdUpSkillRoots,t as inject,e as name};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{z as e}from"zod";import{readFile as t,readdir as n}from"node:fs/promises";import{homedir as r}from"node:os";import{dirname as i,join as a,resolve as o}from"node:path";import{parse as s}from"yaml";import{createHash as c}from"node:crypto";function l(e,t){let n;try{n=t(e)}catch{return}if(!n||typeof n!=`object`)return;let r=n;return{...r,name:String(r.name??``),description:r.description==null?void 0:String(r.description),allowedTools:u(r[`allowed-tools`]??r.allowedTools),hidden:r.hidden===!0,metadata:typeof r.metadata==`object`&&r.metadata!==null&&!Array.isArray(r.metadata)?r.metadata:void 0}}function u(e){if(Array.isArray(e))return e.map(String);if(typeof e==`string`)return e.split(`,`).map(e=>e.trim()).filter(Boolean)}const d=new Set([`name`,`description`,`allowed-tools`,`allowedTools`,`hidden`,`metadata`]);function f(e,t){let n=p(e);if(n.frontmatter===null)return;let r=l(n.frontmatter,t);if(r===void 0||!r.name)return;let i={};for(let[e,t]of Object.entries(r))!d.has(e)&&t!==void 0&&(i[e]=t);let a=r.metadata===void 0?Object.keys(i).length>0?i:void 0:{...i,...r.metadata};return{name:r.name,description:r.description??``,...r.allowedTools===void 0?{}:{allowedTools:r.allowedTools},hidden:r.hidden===!0,...a===void 0?{}:{metadata:a},content:n.body,contentHash:c(`sha256`).update(e).digest(`hex`).slice(0,16)}}function p(e){let t=(e.includes(`\r
|
|
2
|
+
`)?e.replace(/\r\n/g,`
|
|
3
|
+
`):e).split(`
|
|
4
|
+
`);if(t[0]?.trim()!==`---`)return{frontmatter:null,body:e};let n=-1;for(let e=1;e<t.length;e++)if(t[e]?.trim()===`---`){n=e;break}return n<0?{frontmatter:null,body:e}:{frontmatter:t.slice(1,n).join(`
|
|
5
|
+
`),body:t.slice(n+1).join(`
|
|
6
|
+
`).trim()}}const m=1024;function h(e){if(!e?.trim())return``;let t=e.trim().replace(/\s*\n\s*/g,` `);if(t.length<=m)return t;let n=Array.from(t);return n.length>m?`${n.slice(0,m).join(``)}…`:t}const g=`tboxcode-skill-provider`,_=[`skills`],v=e.object({paths:e.array(e.string()).optional(),configDir:e.string().optional(),pollIntervalMs:e.number().int().positive().optional(),settleWindowMs:e.number().int().nonnegative().optional()}),y=50;async function b(e,r){let a;try{a=await n(e,{withFileTypes:!0})}catch{return}for(let n of a){let a=o(e,n.name);if(n.isDirectory()){if(n.name.startsWith(`.`))continue;await b(a,r)}else if(n.isFile()&&n.name===`SKILL.md`)try{let e=f(await t(a,`utf-8`),e=>s(e));if(e===void 0)continue;r.has(e.name)||r.set(e.name,{parsed:e,location:a,dir:i(a)})}catch{}}}function x(e){let t=[],n=o(e);for(;;){t.push(a(n,`.claude`,`skills`)),t.push(a(n,`.agents`,`skills`));let e=i(n);if(e===n)break;n=e}return t}function S(e,n={}){let i=v.parse(n),o=e.skills,c=()=>{let e=r(),t=[a(e,`.claude`,`skills`),a(e,`.agents`,`skills`),i.configDir??a(e,`.config`,`tboxcode-dsh`)];return t.push(...i.paths??[]),t},l=async e=>{let t=new Map,n=[...c(),...e===void 0?[]:x(e)];for(let e of n)await b(e,t);return t},u=async e=>[...(await l(e)).values()].map(({parsed:e,location:t})=>`${t}:${e.contentHash}`).sort().join(`
|
|
7
|
+
`),d={invalidate:()=>{}},p,m=!1,g,_,y=o.registerProvider(e=>(d.invalidate=e.invalidate,p=setInterval(()=>{m||(async()=>{try{let t=await u(_);if(g===void 0){g=t;return}t!==g&&(g=t,setTimeout(()=>{m||e.invalidate()},i.settleWindowMs??500))}catch{}})()},i.pollIntervalMs??2e3),typeof p==`object`&&`unref`in p&&p.unref(),{name:`tboxcode`,rank:50,async list(e){_=e.cwd,g===void 0&&(g=await u(e.cwd));let t=await l(e.cwd),n=[];for(let{parsed:e,location:r,dir:i}of t.values())n.push({path:r,name:e.name,description:h(e.description),invocation:{modelInvocable:!e.hidden,userInvocable:!0},source:`custom`,provider:`tboxcode`,resourceBase:{kind:`directory`,path:i},rank:50,locator:r,...e.metadata===void 0?{}:{metadata:e.metadata}});return n},async get(e){let n=String(e.locator);try{let e=f(await t(n,`utf-8`),e=>s(e));return e===void 0?void 0:{name:e.name,description:e.description,invocation:{modelInvocable:!e.hidden,userInvocable:!0},source:`custom`,provider:`tboxcode`,content:e.content,...e.metadata===void 0?{}:{metadata:e.metadata}}}catch{return}}}));return()=>{m=!0,p!==void 0&&clearInterval(p),y()}}export{g as a,f as c,_ as i,S as n,m as o,x as r,h as s,y as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"../webfetch-CXvjRbDU.js";export{n as apply,e as inject,t as name};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{defineTool as e}from"@deepseek-ai/dsh-tools";import{z as t}from"zod";const n=2e3,r=50*1024;function i(e){return e===`text`?`text/plain;q=1.0, text/markdown;q=0.9, text/html;q=0.8, */*;q=0.1`:e===`html`?`text/html;q=1.0, application/xhtml+xml;q=0.9, text/plain;q=0.8, text/markdown;q=0.7, */*;q=0.1`:`text/markdown;q=1.0, text/x-markdown;q=0.9, text/plain;q=0.8, text/html;q=0.7, */*;q=0.1`}function a(e,t){return{"User-Agent":t,Accept:i(e),"Accept-Language":`en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7`,"Upgrade-Insecure-Requests":`1`}}async function o(e,t,n,r){let i=await fetch(e,{signal:r,redirect:`follow`,headers:a(t,n)});return i.status===403&&i.headers.get(`cf-mitigated`)===`challenge`?fetch(e,{signal:r,redirect:`follow`,headers:a(t,`tboxcode/1.0`)}):i}const s=/charset\s*=\s*["']?([\w-]+)/i,c={gb2312:`gbk`,gbk:`gbk`,gb18030:`gbk`,big5:`big5`,"cn-big5":`big5`,"big-5":`big5`,"utf-16":`utf-16le`,utf16le:`utf-16le`,utf16be:`utf-16be`,ascii:`utf-8`,"us-ascii":`utf-8`,"iso-8859-1":`utf-8`,latin1:`utf-8`};function l(e){let t=s.exec(e);if(!t||!t[1])return`utf-8`;let n=t[1].trim().toLowerCase();return c[n]??(n||`utf-8`)}function u(e,t){try{return new TextDecoder(t,{fatal:!1}).decode(e)}catch{return new TextDecoder(`utf-8`,{fatal:!1}).decode(e)}}const d=e=>e.split(`;`,1)[0]?.trim().toLowerCase()??``,f=e=>e.startsWith(`image/`)&&e!==`image/svg+xml`&&e!==`image/vnd.fastbidsheet`,p=e=>!e||e.startsWith(`text/`)||e===`application/json`||e.endsWith(`+json`)||e===`application/xml`||e.endsWith(`+xml`)||e===`application/javascript`||e===`application/x-javascript`,m=[`script`,`style`,`noscript`,`iframe`,`object`,`embed`];async function h(e){let{Parser:t}=await import(`htmlparser2`),n=``,r=0,i=new t({onopentag(e){(r>0||m.includes(e))&&r++},ontext(e){r===0&&(n+=e)},onclosetag(){r>0&&r--}});return i.write(e),i.end(),n.trim()}async function g(e){try{let t=(await import(`turndown`)).default,n=new t({headingStyle:`atx`,hr:`---`,bulletListMarker:`-`,codeBlockStyle:`fenced`,emDelimiter:`*`});return n.remove([`script`,`style`,`meta`,`link`]),n.turndown(e)}catch{return h(e)}}function _(e,t){try{return new URL(e,t||void 0).toString()}catch{return null}}function v(e,t){return!/location\.replace\s*\(\s*location\.href\.replace\s*\(\s*["']https:\/\/["']\s*,\s*["']http:\/\/["']\s*\)\s*\)/i.test(e)||!t.startsWith(`https://`)?null:t.replace(/^https:\/\//,`http://`)}function y(e,t){let n=e.slice(0,65536),r=n.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)??[],i=[/location\.replace\s*\(\s*['"]([^'"]+)['"]\s*\)/i,/location\.href\s*=\s*['"]([^'"]+)['"]/i,/window\.location(?:\.href)?\s*=\s*['"]([^'"]+)['"]/i,/window\.location\.replace\s*\(\s*['"]([^'"]+)['"]\s*\)/i];for(let e of r){let n=e.replace(/<\/?script\b[^>]*>/gi,``),r=v(n,t);if(r)return{url:r,kind:`js`};for(let e of i){let r=e.exec(n)?.[1];if(!r||/^(location|window)\b/i.test(r))continue;let i=_(r,t);if(i&&i!==t)return{url:i,kind:`js`}}}let a=/<meta\s+http-equiv\s*=\s*["']?refresh["']?\s+content\s*=\s*["']([^"']+)["']/i.exec(n);if(a?.[1]){let e=/url\s*=\s*(['"]?)([^'"\s]+)\1/i.exec(a[1]);if(e?.[2]){let n=_(e[2],t);if(n&&n!==t)return{url:n,kind:`meta`}}}return null}function b(e){let{status:t,statusText:n,url:r,cfMitigated:i,retryAfter:a}=e,o=`Fetch failed: HTTP ${t} ${n} (url: ${r}).`;return i?{summary:o,hint:`The site blocks automated access (Cloudflare challenge). Try a different source or ask the user to fetch it manually.`}:t===401||t===403?{summary:o,hint:`The server requires authentication. Ask the user for credentials or try a different source.`}:t===404||t===410?{summary:o,hint:`The URL does not exist. Do not retry the same URL; try a different source.`}:t===429?{summary:o,hint:a?`Retry-After: ${a}. Wait and retry, or try a different source.`:`Retry later or try a different source.`}:t>=400&&t<500?{summary:o,hint:`The request was rejected by the server. Try a different URL or ask the user to verify.`}:t>=500?{summary:o,hint:`The server is temporarily unavailable. Retry once, or try a different source.`}:{summary:o,hint:`Try a different URL or ask the user to verify.`}}async function x(e,t,n){let r,i=[],a=0;try{if(r=e.body?.getReader(),!r)return null;for(;a<800;){let{value:e,done:t}=await r.read();if(t)break;e&&(i.push(e),a+=e.byteLength)}}catch{}finally{try{await r?.cancel()}catch{}}if(i.length===0)return null;let o=new Uint8Array(Math.min(a,800)),s=0;for(let e of i){if(s>=800)break;let t=e.subarray(0,800-s);o.set(t,s),s+=t.byteLength}return u(o,l(n)).replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,` `).replace(/\s+/g,` `).trim().slice(0,t)||null}async function S(e,t){let n=e.headers.get(`content-length`);if(n){let e=Number.parseInt(n,10);if(Number.isFinite(e)&&e>t)throw Error(`Response too large: ${e} bytes (max ${t})`)}let r=e.body?.getReader();if(!r)throw Error(`fetch failed: response has no body`);let i=[],a=0;try{for(;;){let{done:e,value:n}=await r.read();if(e)break;if(a+=n.byteLength,a>t)throw Error(`Response exceeded ${t} byte limit`);i.push(n)}}finally{r.releaseLock()}return Buffer.concat(i)}async function C(e,t,i={},a){let o=i.max_lines??n,s=i.max_bytes??r,c=e.split(`
|
|
2
|
+
`),l=Buffer.byteLength(e,`utf-8`);if(c.length<=o&&l<=s)return{content:e,truncated:!1};let u=[],d=0,f=!1;for(let e=0;e<c.length&&e<o;e++){let t=Buffer.byteLength(c[e]??``,`utf-8`)+(e>0?1:0);if(d+t>s){f=!0;break}u.push(c[e]??``),d+=t}let p;if(a!==void 0)try{p=await a(e,t)}catch{p=void 0}let m=f?l-d:c.length-u.length,h=f?`bytes`:`lines`;return{content:`${u.join(`
|
|
3
|
+
`)}\n\n${`[output truncated: ${m} ${h} omitted]`}\n\n${p===void 0?`The tool call succeeded but the output was truncated.`:`The tool call succeeded but the output was truncated. Full output saved to: ${p}\nUse Grep to search the full content or Read with offset/limit to view specific sections.`}`,truncated:!0}}async function w(e,t,n={}){let r=Math.min((e.timeout??30)*1e3,12e4);try{let i=e.format??`markdown`,a=AbortSignal.any([t.signal,AbortSignal.timeout(r)]),s=e.url;for(let r=0;r<3;r++){let r=await o(s,i,`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`,a);if(!r.ok){let e=(r.headers.get(`content-type`)??``).toLowerCase(),t=r.headers.get(`cf-mitigated`)===`challenge`,n=r.headers.get(`retry-after`),i=n?/^\d+$/.test(n)?`${n}s`:n:null,a=null,o=d(e);if(o===`application/json`||o.endsWith(`+json`))a=await x(r,200,e);else try{await r.body?.cancel()}catch{}let{summary:s,hint:c}=b({status:r.status,statusText:r.statusText,url:r.url,contentType:e,cfMitigated:t,retryAfter:i,bodySnippet:a}),l=[s,c];throw a&&l.push(`Server response: ${a}`),Error(l.join(`
|
|
4
|
+
`))}let c=await S(r,52428800),m=(r.headers.get(`content-type`)??``).toLowerCase(),_=d(m);if(f(_))throw Error(`Cannot fetch image content type: ${_} (url: ${e.url}).\nUse a different URL, or describe the image to the user.`);if(!p(_))throw Error(`Cannot fetch non-textual content type: ${_} (url: ${e.url}).\nUse a different URL, or ask the user to verify the resource.`);let v=u(c,l(m)),w=y(v,r.url||s);if(w&&w.url!==s){s=w.url;continue}let T;T=i===`html`?v:m.includes(`text/html`)?i===`markdown`?await g(v):await h(v):v;let{content:E}=await C(T,t,{max_lines:n.max_lines,max_bytes:n.max_bytes},n.spillSink);return E}throw Error(`Fetch failed: exceeded 3 redirect hops (last url: ${s}).\nThe page uses a redirect loop; try a different source.`)}catch(n){throw t.signal.aborted?n:n instanceof DOMException&&n.name===`TimeoutError`?Error(`Fetch failed: request timed out after ${r}ms (url: ${e.url}).\nRetry with a longer timeout, or try a different source.`):n instanceof TypeError?Error(`Fetch failed: cannot reach ${e.url} (reason: ${n.message}).\nCheck the URL or try again later.`):n}}const T=`tboxcode-webfetch`,E=[`tools`],D=t.object({maxLines:t.number().int().positive().optional(),maxBytes:t.number().int().positive().optional()});function O(t,n={}){let r=D.parse(n),i=t.get(`spillStore`),a=i===void 0?void 0:async(e,t)=>{let n=t.agent?.session.header.id;if(n===void 0)return;let r=await i.saveText({owner:{sessionId:n},source:{kind:`tool`,toolName:`webfetch`,callId:t.callId,label:`result`},suggestedName:`web_fetch.txt`,content:e});return String(r.locator)},o={max_lines:r.maxLines,max_bytes:r.maxBytes,spillSink:a},s=e({name:`webfetch`,description:`Fetch content from a URL and return it as text, markdown, or HTML. Markdown is the default. HTML→markdown strips script/style/meta/link. HTML→text strips all non-content tags via htmlparser2. Follows HTTP 3xx and JS/<meta refresh> redirects (up to 3 hops). Retries Cloudflare bot challenges with an honest User-Agent. Rejects images and non-textual content types.`,parameters:{url:{type:`string`,required:!0,description:`The URL to fetch (https only)`},format:{type:`string`,enum:[`text`,`markdown`,`html`],description:`Output format; defaults to markdown`},timeout:{type:`number`,description:`Timeout in seconds; defaults to 30, max 120`}},output:{schema:{type:`string`},render:(e,t)=>[{type:`text`,text:t}]},async execute(e,t){return w(e,t,o)}});return t.tools.register(s)}export{n as a,h as c,r as i,S as l,E as n,y as o,T as r,w as s,O as t,C as u};
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/tboxcode-dsh-tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-rc.10",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "tboxcode 工具插件族:webfetch(截断链三分支)/ skill provider(rank 50 cwd-up)/ restrict / pre-execute 拦截器 / scratch 三件",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./webfetch": {
|
|
14
|
+
"types": "./lib/webfetch/index.d.ts",
|
|
15
|
+
"default": "./lib/webfetch/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./skill-provider": {
|
|
18
|
+
"types": "./lib/skill-provider/index.d.ts",
|
|
19
|
+
"default": "./lib/skill-provider/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./restrict": {
|
|
22
|
+
"types": "./lib/restrict/index.d.ts",
|
|
23
|
+
"default": "./lib/restrict/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./pre-execute": {
|
|
26
|
+
"types": "./lib/pre-execute/index.d.ts",
|
|
27
|
+
"default": "./lib/pre-execute/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./scratch": {
|
|
30
|
+
"types": "./lib/scratch/index.d.ts",
|
|
31
|
+
"default": "./lib/scratch/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./auto-commit": {
|
|
34
|
+
"types": "./lib/auto-commit/index.d.ts",
|
|
35
|
+
"default": "./lib/auto-commit/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"lib"
|
|
40
|
+
],
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.2"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"htmlparser2": "^10.0.0",
|
|
46
|
+
"turndown": "7.2.4",
|
|
47
|
+
"yaml": "^2.9.1",
|
|
48
|
+
"zod": "4.6.7"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@deepseek-ai/cordis": "4.0.5",
|
|
52
|
+
"@deepseek-ai/dsh-shell": "0.2.1-rc.2",
|
|
53
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.2",
|
|
54
|
+
"@types/turndown": "^5.0.5"
|
|
55
|
+
},
|
|
56
|
+
"dsh": {
|
|
57
|
+
"bundle": {
|
|
58
|
+
"patch": []
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsdown",
|
|
63
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
64
|
+
}
|
|
6
65
|
}
|
package/README.md
DELETED