Repository navigation
refactor(ptc): ship TypeScript sources instead of tsc output - #443
yanfei0725 wants to merge 12 commits into
Conversation
…azy engine
把「调用次数」当主要成本:每次工具往返都要重发整个上下文,省一次往返胜过省几百字节回执。
- locate 附赠命中正文:body 缺省 true(≤8 KiB 随 hits[].body 返回)、数字(上限 32 KiB)、
false(只给行号)。不附时给 bodyOmitted 与 readHint(约 70 B),把第二轮从「自己算
offset 试错」变成「照抄参数」。40 行/1583 B 的符号 437 B + 一轮 -> 1911 B 一次到位;
182 行/12.7 KB 的符号 -> 473 B + readHint。
- 回执 24 KiB 闸门:先退正文并补 readHint -> 再按稠密前缀削 hits/files/edits 并报
${key}Omitted 与 nextOffset -> 最后只留计数。27 KB 输入 -> 943 B。
- 命中字段瘦身:删 chars/bodyBytes/fileBytes/savedRatio 与顶层 contextBytes,
find 的 savedTokensRatio 同步删除。每命中 -82 B 约 -21 token。
- 引擎懒加载:inputSchema 改由 dist/ptc/schema.json 承载,引擎引用挪到首调用。
会话启动导入 19.01 ms -> 4.56 ms,启动期 require 缓存不再有 @ast-grep/napi。
README 与 AUDIT 同步到 2.1.0。
…r engine load, stale-index walk retry
…tead of a tarball The PR carried ops-ptc-2.1.1.tgz, so the engine could not be read or reviewed in the diff at all. - packages/ops-ptc/src/ptc/ the CommonJS implementation plus its hand-written .d.ts - packages/ops-ptc/test/ AST, worker, protocol, pipeline, mode-audit regressions - packages/ops-ptc/scripts/ build.mjs copies src/ to dist/ (same bytes, no compiler step) - packages/ops-ptc/vendor/ placement note for es.exe; the binary itself stays out - drop the tarball and the duplicated root README and AUDIT files - test fixes: Everything checks accept E_BIN_MISSING, locate asserts the 8 KiB body gate - .gitignore: release archives, vendored .exe and test scratch trees
… output packages/ops-ptc/src/ptc/ used to hold tsc output (.js + hand-written .d.ts), so the PR diff showed only exports.x = x and (0, mod.fn)(). The 13 modules are back as TypeScript with their types and comments intact; dist/ is generated by tsc and stays out of the tree. Build is now real compilation instead of a copy: scripts/build.mjs runs tsc, then copies the two non-TS resources (agentbox.worker.cjs, schema.json). Relative imports drop the .js suffix so the same sources run under both the tsc build and the node --experimental-strip-types test harness. inproc.ts is split at the enumeration seam: enumerate.ts carries the walk/Everything strategy, the 30s cache, and the substring prefilter; inproc-error.ts carries the shared error class. Largest file is now 884 lines, down from 1023. npm run verify passes: 22/22 pipeline, 11 audit-root-cache, 28 MCP checks, plus the smoke and safety suites.
…t_* and drop the MCP exit - Move the prototype out of packages/ops-ptc into src/ast as reviewed repository source: dsh-ops/ast* package exports, the ops-ast bin, bench/ast benchmarks and bilingual docs. The standalone-package shape could not support tool registration. - Rename the five tools ops_ptc_* -> ops_ast_*: the PTC naming collides with the existing dsh-ops-ptc row; titles drop the PTC branding and the .ops-ptc.lock / .ptc- artifact names follow. - Fix the locate body parameter: the host assertSupportedJsonSchema rejects type arrays, so the boolean/number dual shape becomes an exact-one oneOf; all five inputSchemas now pass the real host validator. - Remove the MCP stdio exit and its two suites: an independent endpoint serves handlers with no sandbox policy, credential fence or host authority -- the bypass dsh-ops itself removed with FastCtx in 0.3.2. createHostTools/registerHostTools with a trusted bridge stay the only model-facing wiring point. - The engine remains unregistered with the running host; progressive-discovery wiring (discovery row pool plus the trusted bridge) is the follow-up.
|
按 review 结论对这个 PR 做了一轮重整(提交 1. 文件整理最初以压缩包形式提交、后来落到
2. 工具重命名
|
…opt 0.5.0-alpha3 section
reparseEscape walked to the volume root, so on macOS — where tmpdir sits behind /var -> /private/var — every candidate under a tmpdir workspace was named as an escape and silently skipped: inproc locate/refactor always returned E_INPROC_NO_MATCH with no firstError, while win32/linux passed. The lstat walk now stops at the workspace boundary (the enumerated root, or cwd for a caller-named file); links at or above the boundary are the caller's authority decision, links inside the workspace are still refused. Windows junctions in the smoke suite pin both sides of that line.
The pinned 0.2.0-rc.2 host types declare `agent/created` as `(payload) => Promise<undefined> | undefined`, so a void block body fails `tsc` and `npm run build` aborts before it copies assets or writes the PTC declarations. Three call sites had a void body; each now returns undefined explicitly, which is what the runtime already did.
Registers the AST engine that landed under `src/ast` as host tools instead of leaving it unregistered: `src/execution/ast-inproc.ts` is dispatched from both execution bridges (`src/execution/files.ts`, `src/execution/jobs.ts`) before any worker spawn or policy resolve, so a locate/rewrite/audit never starts a subprocess. The five rows (`ast_locate`, `ast_find`, `ast_refactor`, `ast_inproc`, `ast_audit`) enter the catalogue with their schemas spread from `src/ast/schema.json`, so `required` cannot drift from the engine's own. Availability follows the file rows: locate and inproc stay resident, find, refactor and audit arrive through discovery. Only `ast_refactor` mutates, so the other four are concurrency-safe. The adapter is the trusted bridge and carries the native worker's four fences in the same order: session identity plus absolute cwd, one authoritative policy resolve with a mode whitelist, the credential fence before anchoring, and write intent requiring workspace-write. Outside danger-full-access every named file and enumeration root must stay inside the workspace or session cwd by real path, so a junction that points outside is refused rather than trusted by name. Receipts are canonicalised to the host vocabulary and degraded by item (bodies first, then a dense prefix with nextOffset) past 24 KiB. `test/ast-inproc.test.mjs` (18 checks) covers the dispatch, the fences, the receipt shape, enumerate caps and the unresolved-placeholder gate.
这次只改一件事:把包从「压缩包 / 编译产物」变回可 review 的源码
上一版提交进来的
src/ptc/*.js是tsc编译结果,外加 11 份手写.d.ts。diff 里只能看到exports.x = x和(0, mod.fn)(),reviewer 无法判断改了什么。这个 PR 把 13 个模块还原成 TypeScript 源,带原来的注释和类型。目录
没有
.tgz、没有.tar.gz、没有.exe、没有dist/、没有node_modules/。.gitignore只拦这三类产物,src/下任何.ts/.js都不受影响。构建变成真编译
build.mjs原来是cpSync(src, dist)—— 因为源就是产物。现在跑tsc -p tsconfig.json,然后只拷两样不进 tsc 的东西:手写的agentbox.worker.cjs(proc.ts按__dirname直接拉起)和schema.json(宿主当纯数据读)。相对 import 去掉了
.js后缀('./engine-load.js'→'./engine-load'),这样同一份源既能被 tsc 编译,也能被node --experimental-strip-types直接跑 —— 测试套件里有几支就是直引src/ptc/*.ts的。单文件 1000 行
原
inproc.ts1023 行,超了。按枚举接缝拆开:inproc.tsenumerate.tsinproc-error.tsenumerate/clearEnumCache/EnumerateResult/LocateStrategy仍从./inproc导出,包对外 import 路径不变。当前最大文件 884 行,全部提交都在 1000 行以内。验证
verify展开后:22/22 pipeline regression、11 项 audit root cache、28 项 MCP 契约、safety / worker / protocol / mode-audit / locate-parity 各套件全过。导出面与旧dist逐模块比对一致(dist-shape只对基线里存在的模块比对,新增的engine-load/enumerate不算导出变更)。一个提醒
src/ptc/的手写.d.ts不在了 —— 声明文件现在由tsc的declaration: true生成,跟着类型走。如果维护者希望保留手工声明(比如为了压注释体积),那是另一个决定,这里按「源码即唯一真相」处理。