pi-ptc-subagents 6.1.0 → 6.2.0

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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
2
2
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
+ import { execSync, spawn } from "node:child_process";
4
5
  import { randomUUID } from "node:crypto";
5
6
  import { mkdir, open, readFile, rename, writeFile } from "node:fs/promises";
6
- import { spawn } from "node:child_process";
7
7
  import { gunzipSync, gzip } from "node:zlib";
8
8
  import { promisify } from "node:util";
9
9
  import { fileURLToPath } from "node:url";
@@ -3062,6 +3062,7 @@ const REPORT_CONTRACT_BLOCK = [
3062
3062
  "```json",
3063
3063
  "{ \"summary\": \"one sentence conclusion\", \"findings\": [{ \"what\": \"claim\", \"evidence\": \"where it comes from\" }], \"files_touched\": [\"relative/path\"], \"usage\": { \"input\": 0, \"output\": 0, \"cost\": 0, \"turns\": 0 } }",
3064
3064
  "```",
3065
+ "Rules: \"summary\" is your deliverable — answer the task asked, in one sentence. \"findings\" carries load-bearing evidence only; never recap content you merely read. Do NOT write report/summary .md files — your final message is what the parent reads.",
3065
3066
  "findings/files_touched/usage may be omitted when empty. Your prose answer stays; the report is checked alongside it.",
3066
3067
  "</child-report-contract>"
3067
3068
  ].join("\n");
@@ -3132,6 +3133,14 @@ function spawnChild(argv, env = process.env) {
3132
3133
  function escapeXmlText(text) {
3133
3134
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3134
3135
  }
3136
+ function supportsNoMcp(piVersion) {
3137
+ if (!piVersion) return false;
3138
+ const [major = "0", minor = "0"] = piVersion.trim().replace(/^v/, "").split(".");
3139
+ const M = Number.parseInt(major, 10);
3140
+ const m = Number.parseInt(minor, 10);
3141
+ if (Number.isNaN(M) || Number.isNaN(m)) return false;
3142
+ return M > 1 || M === 1 && m >= 1;
3143
+ }
3135
3144
  function buildPiArgv(input, context) {
3136
3145
  const argv = [
3137
3146
  "pi",
@@ -3148,6 +3157,8 @@ function buildPiArgv(input, context) {
3148
3157
  "</pi-ptc-context>"
3149
3158
  ].filter(Boolean).join("\n")
3150
3159
  ];
3160
+ argv.push("--no-extensions", "--no-skills");
3161
+ if (supportsNoMcp(context.piVersion)) argv.push("--no-mcp");
3151
3162
  const model = input.model ?? input.agentModel ?? context.sessionModel;
3152
3163
  const thinking = input.thinkingLevel ?? input.agentThinkingLevel;
3153
3164
  if (model) argv.push("--model", thinking ? `${model}:${thinking}` : model);
@@ -3235,6 +3246,8 @@ function parseChildStream(stdout) {
3235
3246
  observedUsage = {
3236
3247
  input: message.usage.input,
3237
3248
  output: message.usage.output,
3249
+ ...message.usage.cacheRead !== void 0 ? { cacheRead: message.usage.cacheRead } : {},
3250
+ ...message.usage.cacheWrite !== void 0 ? { cacheWrite: message.usage.cacheWrite } : {},
3238
3251
  ...cost !== void 0 ? { cost } : {}
3239
3252
  };
3240
3253
  }
@@ -4964,6 +4977,7 @@ function assemblePtcSession(options = {}) {
4964
4977
  registry,
4965
4978
  gates: options.gates,
4966
4979
  whyEnabled: options.whyEnabled,
4980
+ context: options.context,
4967
4981
  ...options.engine
4968
4982
  });
4969
4983
  return {
@@ -4994,6 +5008,20 @@ const textResult = (value) => ({
4994
5008
  const packageRoot = fileURLToPath(new URL("..", import.meta.url));
4995
5009
  const publishedDetailDir = join(packageRoot, "docs", "routes");
4996
5010
  const detailDir = existsSync(publishedDetailDir) ? publishedDetailDir : join(packageRoot, "..", "routes", "docs", "routes");
5011
+ function resolvePiVersion() {
5012
+ try {
5013
+ return execSync("pi --version", {
5014
+ encoding: "utf8",
5015
+ stdio: [
5016
+ "ignore",
5017
+ "pipe",
5018
+ "ignore"
5019
+ ]
5020
+ }).trim() || void 0;
5021
+ } catch {
5022
+ return;
5023
+ }
5024
+ }
4997
5025
  function piPtcEntry(pi) {
4998
5026
  pi.on("session_start", (_event, ctx) => {
4999
5027
  if (Number(process.env.PI_PTC_DEPTH ?? 0) > 0) {
@@ -5034,6 +5062,7 @@ function piPtcEntry(pi) {
5034
5062
  userDir: join(getAgentDir(), "agents"),
5035
5063
  projectDir: join(process.cwd(), ".pi", "agents")
5036
5064
  };
5065
+ const piVersion = resolvePiVersion();
5037
5066
  let session;
5038
5067
  const faceAddedByUs = /* @__PURE__ */ new Set();
5039
5068
  const applyTaskFaceVisibility = () => {
@@ -5055,6 +5084,10 @@ function piPtcEntry(pi) {
5055
5084
  session = assemblePtcSession({
5056
5085
  onTransition: () => applyTaskFaceVisibility(),
5057
5086
  whyEnabled: () => whyEnabledOverride ?? whyEnabledPersisted,
5087
+ context: {
5088
+ depth: 0,
5089
+ piVersion
5090
+ },
5058
5091
  engine: {
5059
5092
  notifications,
5060
5093
  resolveAgent: (name, scope) => findAgent(name, agentDirs, scope),
@@ -13,3 +13,14 @@ agent 定义里的 `tools / model / thinkingLevel / childReport` 由 frontmatter
13
13
 
14
14
  任务建成后在任务记录里排队(满员排队不拒绝,ADR-0010),经
15
15
  `ptc_task_list / ptc_task_output / ptc_task_stop` 查/停。
16
+
17
+ ## Briefing 纪律(省 token,派发前自查)
18
+
19
+ - **给确切路径、命令、决策**:孩子看不到父会话。task 里写死一个路径,省孩子一轮探索
20
+ (每轮探索 = 一次工具调用结果 + 推理 token)。
21
+ - **写明最终消息要带回什么**:孩子只回一次。要什么格式、哪些字段,task 里说清。
22
+ - **不确定能否一次搜中才派**:目标明确(已知路径、已知行号)的活别派,主会话直接
23
+ `tools.read` 更省。
24
+ - **同域的活合并给一个串行孩子**:每个孩子都付一份固定 harness 税(系统提示词 +
25
+ 项目上下文)。多个重叠的小活拆并行 = 同一份探索被付费多次。
26
+ - **孩子不写报告文件**:交付物就是最终消息(含报告 JSON 块),落盘 .md 是浪费。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ptc-subagents",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Programmable tool calling (PTC) and subagent fan-out for pi",
5
5
  "keywords": [
6
6
  "pi",
@@ -30,10 +30,12 @@
30
30
  ".": "./dist/index.js"
31
31
  },
32
32
  "scripts": {
33
- "build": "pnpm -r run build",
33
+ "build": "pnpm -r --filter=!@pi-ptc/website run build",
34
34
  "prepack": "pnpm run build && rm -rf dist docs/routes && cp -R packages/entry/dist dist && cp -R packages/routes/docs/routes docs/routes",
35
- "check": "pnpm -r run check",
35
+ "check": "pnpm -r --filter=!@pi-ptc/website run check",
36
36
  "lint": "oxlint",
37
+ "test": "node --test tests/*.test.mjs",
38
+ "pretest": "pnpm run build",
37
39
  "fmt": "oxfmt",
38
40
  "fmt:check": "oxfmt --check"
39
41
  },