@getpochi/cli 0.6.3 → 0.6.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +329 -202
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -133488,13 +133488,13 @@ var init_Entity = __esm(() => {
133488
133488
  get client() {
133489
133489
  return shardingTag.pipe(flatMap15((sharding) => sharding.makeClient(this)));
133490
133490
  },
133491
- toLayer(build5, options12) {
133492
- return shardingTag.pipe(flatMap15((sharding) => sharding.registerEntity(this, isEffect2(build5) ? build5 : succeed11(build5), options12)), scopedDiscard2);
133491
+ toLayer(build4, options12) {
133492
+ return shardingTag.pipe(flatMap15((sharding) => sharding.registerEntity(this, isEffect2(build4) ? build4 : succeed11(build4), options12)), scopedDiscard2);
133493
133493
  },
133494
133494
  of: identity,
133495
- toLayerMailbox(build5, options12) {
133495
+ toLayerMailbox(build4, options12) {
133496
133496
  const buildHandlers = gen4(this, function* () {
133497
- const behaviour = isEffect2(build5) ? yield* build5 : build5;
133497
+ const behaviour = isEffect2(build4) ? yield* build4 : build4;
133498
133498
  const mailbox = yield* make80();
133499
133499
  const handler2 = (envelope) => {
133500
133500
  return async((resume2) => {
@@ -135063,14 +135063,14 @@ var init_Sharding = __esm(() => {
135063
135063
  const context15 = yield* context3();
135064
135064
  const reaper = yield* EntityReaper;
135065
135065
  const entityManagerLatches = new Map;
135066
- const registerEntity = fnUntraced2(function* (entity, build5, options12) {
135066
+ const registerEntity = fnUntraced2(function* (entity, build4, options12) {
135067
135067
  if (isNone2(config5.runnerAddress) || entityManagers.has(entity.type))
135068
135068
  return;
135069
135069
  const scope5 = yield* scope3;
135070
135070
  yield* addFinalizer2(scope5, sync6(() => {
135071
135071
  state2.status = "closed";
135072
135072
  }));
135073
- const manager = yield* make178(entity, build5, {
135073
+ const manager = yield* make178(entity, build4, {
135074
135074
  ...options12,
135075
135075
  storage,
135076
135076
  runnerAddress: config5.runnerAddress.value,
@@ -172750,7 +172750,7 @@ var require_main2 = __commonJS((exports, module) => {
172750
172750
  __export3(node_exports, {
172751
172751
  analyzeMetafile: () => analyzeMetafile,
172752
172752
  analyzeMetafileSync: () => analyzeMetafileSync,
172753
- build: () => build5,
172753
+ build: () => build4,
172754
172754
  buildSync: () => buildSync,
172755
172755
  context: () => context15,
172756
172756
  default: () => node_default,
@@ -174725,7 +174725,7 @@ More information: The file containing the code for esbuild's JavaScript API (${_
174725
174725
  }
174726
174726
  };
174727
174727
  var version4 = "0.25.9";
174728
- var build5 = (options14) => ensureServiceIsRunning().build(options14);
174728
+ var build4 = (options14) => ensureServiceIsRunning().build(options14);
174729
174729
  var context15 = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
174730
174730
  var transform14 = (input, options14) => ensureServiceIsRunning().transform(input, options14);
174731
174731
  var formatMessages2 = (messages, options14) => ensureServiceIsRunning().formatMessages(messages, options14);
@@ -175217,7 +175217,7 @@ function build$1(options14, isSynchronous) {
175217
175217
  else
175218
175218
  return isSynchronous ? defaultSync : defaultAsync;
175219
175219
  }
175220
- function build5(isSynchronous) {
175220
+ function build4(isSynchronous) {
175221
175221
  return isSynchronous ? walkSync : walkAsync;
175222
175222
  }
175223
175223
  function promise5(root2, options14) {
@@ -175411,7 +175411,7 @@ var __require3, SLASHES_REGEX, WINDOWS_ROOT_DIR_REGEX, pushDirectory = (director
175411
175411
  this.getArray = build$4(options14);
175412
175412
  this.groupFiles = build$3(options14);
175413
175413
  this.resolveSymlink = build$2(options14, this.isSynchronous);
175414
- this.walkDirectory = build5(this.isSynchronous);
175414
+ this.walkDirectory = build4(this.isSynchronous);
175415
175415
  }
175416
175416
  start() {
175417
175417
  this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
@@ -178023,7 +178023,7 @@ var require_main3 = __commonJS((exports, module) => {
178023
178023
  __export3(node_exports, {
178024
178024
  analyzeMetafile: () => analyzeMetafile,
178025
178025
  analyzeMetafileSync: () => analyzeMetafileSync,
178026
- build: () => build6,
178026
+ build: () => build5,
178027
178027
  buildSync: () => buildSync,
178028
178028
  context: () => context15,
178029
178029
  default: () => node_default,
@@ -179998,7 +179998,7 @@ More information: The file containing the code for esbuild's JavaScript API (${_
179998
179998
  }
179999
179999
  };
180000
180000
  var version4 = "0.25.1";
180001
- var build6 = (options14) => ensureServiceIsRunning().build(options14);
180001
+ var build5 = (options14) => ensureServiceIsRunning().build(options14);
180002
180002
  var context15 = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
180003
180003
  var transform14 = (input, options14) => ensureServiceIsRunning().transform(input, options14);
180004
180004
  var formatMessages2 = (messages, options14) => ensureServiceIsRunning().formatMessages(messages, options14);
@@ -186739,16 +186739,16 @@ var require_babel = __commonJS((exports, module) => {
186739
186739
  if (maps[i8].sources.length > 1)
186740
186740
  throw new Error(`Transformation map ${i8} must have exactly one source file.
186741
186741
  Did you specify these with the most recent transformation maps first?`);
186742
- let tree = build6(map52, loader, "", 0);
186742
+ let tree = build5(map52, loader, "", 0);
186743
186743
  for (let i8 = maps.length - 1;i8 >= 0; i8--)
186744
186744
  tree = MapSource(maps[i8], [tree]);
186745
186745
  return tree;
186746
186746
  }
186747
- function build6(map52, loader, importer, importerDepth) {
186747
+ function build5(map52, loader, importer, importerDepth) {
186748
186748
  const { resolvedSources, sourcesContent, ignoreList } = map52, depth = importerDepth + 1;
186749
186749
  return MapSource(map52, resolvedSources.map((sourceFile, i8) => {
186750
186750
  const ctx = { importer, depth, source: sourceFile || "", content: undefined, ignore: undefined }, sourceMap = loader(ctx.source, ctx), { source, content: content3, ignore: ignore7 } = ctx;
186751
- return sourceMap ? build6(new traceMapping.TraceMap(sourceMap, source), loader, source, depth) : OriginalSource(source, content3 !== undefined ? content3 : sourcesContent ? sourcesContent[i8] : null, ignore7 !== undefined ? ignore7 : !!ignoreList && ignoreList.includes(i8));
186751
+ return sourceMap ? build5(new traceMapping.TraceMap(sourceMap, source), loader, source, depth) : OriginalSource(source, content3 !== undefined ? content3 : sourcesContent ? sourcesContent[i8] : null, ignore7 !== undefined ? ignore7 : !!ignoreList && ignoreList.includes(i8));
186752
186752
  }));
186753
186753
  }
186754
186754
 
@@ -191124,10 +191124,10 @@ See https://babeljs.io/docs/configuration#print-effective-configs for more info.
191124
191124
  }
191125
191125
  Object.defineProperty(exports2, "__esModule", { value: true }), exports2.default = function(allowlist, outputType = "global") {
191126
191126
  let tree;
191127
- const build6 = { global: buildGlobal, module: buildModule, umd: buildUmd, var: buildVar }[outputType];
191128
- if (!build6)
191127
+ const build5 = { global: buildGlobal, module: buildModule, umd: buildUmd, var: buildVar }[outputType];
191128
+ if (!build5)
191129
191129
  throw new Error(`Unsupported output type ${outputType}`);
191130
- tree = build6(allowlist);
191130
+ tree = build5(allowlist);
191131
191131
  return (0, _generator().default)(tree).code;
191132
191132
  };
191133
191133
  const { arrayExpression: arrayExpression2, assignmentExpression: assignmentExpression2, binaryExpression: binaryExpression2, blockStatement: blockStatement2, callExpression: callExpression2, cloneNode, conditionalExpression: conditionalExpression2, exportNamedDeclaration: exportNamedDeclaration2, exportSpecifier: exportSpecifier2, expressionStatement: expressionStatement2, functionExpression: functionExpression2, identifier: identifier3, memberExpression: memberExpression2, objectExpression: objectExpression2, program: program4, stringLiteral, unaryExpression: unaryExpression2, variableDeclaration: variableDeclaration2, variableDeclarator: variableDeclarator2 } = _t(), buildUmdWrapper = (replacements2) => _template().default.statement`
@@ -362928,7 +362928,7 @@ function build$13(options14, isSynchronous) {
362928
362928
  else
362929
362929
  return isSynchronous ? defaultSync2 : defaultAsync2;
362930
362930
  }
362931
- function build7(isSynchronous) {
362931
+ function build6(isSynchronous) {
362932
362932
  return isSynchronous ? walkSync2 : walkAsync2;
362933
362933
  }
362934
362934
  function promise6(root3, options14) {
@@ -363122,7 +363122,7 @@ var __require5, SLASHES_REGEX2, WINDOWS_ROOT_DIR_REGEX2, pushDirectory2 = (direc
363122
363122
  this.getArray = build$42(options14);
363123
363123
  this.groupFiles = build$32(options14);
363124
363124
  this.resolveSymlink = build$23(options14, this.isSynchronous);
363125
- this.walkDirectory = build7(this.isSynchronous);
363125
+ this.walkDirectory = build6(this.isSynchronous);
363126
363126
  }
363127
363127
  start() {
363128
363128
  this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
@@ -441631,7 +441631,7 @@ var require_colors = __commonJS((exports, module) => {
441631
441631
  }
441632
441632
  return str.replace(matchOperatorsRe, "\\$&");
441633
441633
  };
441634
- function build9(_styles) {
441634
+ function build8(_styles) {
441635
441635
  var builder = function builder() {
441636
441636
  return applyStyle2.apply(builder, arguments);
441637
441637
  };
@@ -441646,7 +441646,7 @@ var require_colors = __commonJS((exports, module) => {
441646
441646
  ansiStyles2[key].closeRe = new RegExp(escapeStringRegexp3(ansiStyles2[key].close), "g");
441647
441647
  ret[key] = {
441648
441648
  get: function() {
441649
- return build9(this._styles.concat(key));
441649
+ return build8(this._styles.concat(key));
441650
441650
  }
441651
441651
  };
441652
441652
  });
@@ -441705,7 +441705,7 @@ var require_colors = __commonJS((exports, module) => {
441705
441705
  Object.keys(styles3).forEach(function(name17) {
441706
441706
  ret[name17] = {
441707
441707
  get: function() {
441708
- return build9([name17]);
441708
+ return build8([name17]);
441709
441709
  }
441710
441710
  };
441711
441711
  });
@@ -447848,8 +447848,8 @@ var require_coerce = __commonJS((exports, module) => {
447848
447848
  const minor = match33[3] || "0";
447849
447849
  const patch25 = match33[4] || "0";
447850
447850
  const prerelease = options14.includePrerelease && match33[5] ? `-${match33[5]}` : "";
447851
- const build9 = options14.includePrerelease && match33[6] ? `+${match33[6]}` : "";
447852
- return parse30(`${major}.${minor}.${patch25}${prerelease}${build9}`, options14);
447851
+ const build10 = options14.includePrerelease && match33[6] ? `+${match33[6]}` : "";
447852
+ return parse30(`${major}.${minor}.${patch25}${prerelease}${build10}`, options14);
447853
447853
  };
447854
447854
  module.exports = coerce3;
447855
447855
  });
@@ -493638,7 +493638,7 @@ class BrowserSessionStore {
493638
493638
  // package.json
493639
493639
  var package_default = {
493640
493640
  name: "@getpochi/cli",
493641
- version: "0.6.3",
493641
+ version: "0.6.5",
493642
493642
  devDependencies: {
493643
493643
  "@commander-js/extra-typings": "^14.0.0",
493644
493644
  "@getpochi/common": "workspace:*",
@@ -495979,7 +495979,11 @@ var materializers2 = exports_mod6.SQLite.materializers(events, {
495979
495979
  data: message
495980
495980
  }).where({ id: message.id })),
495981
495981
  "v1.ForkTaskInited": ({ tasks, messages, files }) => [
495982
- ...tasks.map((task) => tables.tasks.insert({ ...task, updatedAt: task.createdAt })),
495982
+ ...tasks.map((task) => tables.tasks.insert({
495983
+ ...task,
495984
+ shareId: task.parentId ? undefined : `p-${task.id.replaceAll("-", "")}`,
495985
+ updatedAt: task.createdAt
495986
+ })),
495983
495987
  ...messages.map((message) => tables.messages.insert(message)),
495984
495988
  ...files.map((file7) => tables.files.insert(file7))
495985
495989
  ]
@@ -497718,143 +497722,10 @@ end
497718
497722
  complete -f -d 'pochi' -c pochi -a "(eval _pochi_completion)"
497719
497723
  ###-end-pochi-completion-###
497720
497724
  `;
497721
- // src/json-renderer.ts
497722
- var runExclusive2 = __toESM(require_runExclusive(), 1);
497723
-
497724
- class JsonRenderer {
497725
- stream;
497726
- store;
497727
- blobStore;
497728
- state;
497729
- outputMessageIds = new Set;
497730
- lastMessageCount = 0;
497731
- mode;
497732
- attemptCompletionSchemaOverride;
497733
- constructor(stream15, store, blobStore, state2, options7 = { mode: "full" }) {
497734
- this.stream = stream15;
497735
- this.store = store;
497736
- this.blobStore = blobStore;
497737
- this.state = state2;
497738
- this.mode = options7.mode;
497739
- this.attemptCompletionSchemaOverride = !!options7.attemptCompletionSchemaOverride;
497740
- if (this.mode === "full") {
497741
- this.state.signal.messages.subscribe(runExclusive2.build(async (messages) => {
497742
- if (messages.length > this.lastMessageCount) {
497743
- await this.outputMessages(messages.slice(0, -1));
497744
- this.lastMessageCount = messages.length;
497745
- }
497746
- }));
497747
- }
497748
- }
497749
- async shutdown() {
497750
- if (this.mode === "result-only") {
497751
- this.outputResult();
497752
- } else {
497753
- await this.outputMessages(this.state.signal.messages.value);
497754
- await this.outputFilesData();
497755
- }
497756
- }
497757
- outputResult() {
497758
- const messages = this.state.signal.messages.value;
497759
- const lastMessage = messages.at(-1);
497760
- if (lastMessage?.role === "assistant") {
497761
- for (const part of lastMessage.parts || []) {
497762
- if (isToolUIPart(part) && part.type === "tool-attemptCompletion") {
497763
- if (part.input) {
497764
- const input = part.input;
497765
- if (this.attemptCompletionSchemaOverride) {
497766
- this.stream.write(`${JSON.stringify(input.result, null, 2)}
497767
- `);
497768
- } else {
497769
- this.stream.write(`${input.result}
497770
- `);
497771
- }
497772
- }
497773
- return;
497774
- }
497775
- }
497776
- }
497777
- }
497778
- async outputMessages(messages) {
497779
- for (const message of messages) {
497780
- if (!this.outputMessageIds.has(message.id)) {
497781
- let outputMessage = await inlineSubTask(this.store, message);
497782
- outputMessage = await mapStoreBlob(this.blobStore, outputMessage);
497783
- this.stream.write(`${JSON.stringify(outputMessage)}
497784
- `);
497785
- this.outputMessageIds.add(message.id);
497786
- }
497787
- }
497788
- }
497789
- async outputFilesData() {
497790
- const files = this.store.query(defaultCatalog.queries.makeStoreFilesQuery());
497791
- if (files.length > 0) {
497792
- const data = {
497793
- type: "files",
497794
- files
497795
- };
497796
- this.stream.write(`${JSON.stringify(data)}
497797
- `);
497798
- }
497799
- }
497800
- }
497801
- async function inlineSubTask(store, message) {
497802
- const partsWithSubtasks = message.parts.map((part) => {
497803
- if (part.type === "tool-newTask" && part.state !== "input-streaming") {
497804
- const input = part.input;
497805
- const subtaskId = input._meta?.uid;
497806
- if (subtaskId) {
497807
- const subtask = store.query(defaultCatalog.queries.makeTaskQuery(subtaskId));
497808
- const subtaskMessages = store.query(defaultCatalog.queries.makeMessagesQuery(subtaskId));
497809
- if (subtask) {
497810
- return {
497811
- ...part,
497812
- input: {
497813
- ...input,
497814
- _transient: {
497815
- task: {
497816
- clientTaskId: subtaskId,
497817
- messages: subtaskMessages.map((m) => m.data),
497818
- todos: subtask.todos.map((t5) => ({ ...t5 }))
497819
- }
497820
- }
497821
- }
497822
- };
497823
- }
497824
- }
497825
- }
497826
- return part;
497827
- });
497828
- return {
497829
- ...message,
497830
- parts: partsWithSubtasks
497831
- };
497832
- }
497833
- async function mapStoreBlob(store, o6) {
497834
- if (t3(o6) && o6.startsWith(store.protocol)) {
497835
- const blob3 = await store.get(o6);
497836
- if (!blob3)
497837
- throw new Error(`Store blob not found at "${o6}"`);
497838
- const base643 = Buffer.from(blob3.data).toString("base64");
497839
- return `data:${blob3.mimeType};base64,${base643}`;
497840
- }
497841
- if (o5(o6)) {
497842
- return Promise.all(o6.map((el) => mapStoreBlob(store, el)));
497843
- }
497844
- if (o4(o6)) {
497845
- const entires = await Promise.all(t4(o6).map(async ([k2, v2]) => [
497846
- k2,
497847
- await mapStoreBlob(store, v2)
497848
- ]));
497849
- return n2(entires);
497850
- }
497851
- return o6;
497852
- }
497853
-
497854
497725
  // src/lib/ffmpeg-mjpeg-to-mp4.ts
497855
497726
  import { PassThrough } from "node:stream";
497856
497727
  var import_fluent_ffmpeg = __toESM(require_fluent_ffmpeg(), 1);
497857
- var runExclusive3 = __toESM(require_runExclusive(), 1);
497728
+ var runExclusive2 = __toESM(require_runExclusive(), 1);
497858
497729
  var logger15 = getLogger("MjpegToMp4");
497859
497730
  function setFfmpegPath(path5) {
497860
497731
  import_fluent_ffmpeg.default.setFfmpegPath(path5);
@@ -497920,7 +497791,7 @@ function startMjpegToMp4Converter(outputPath, opts = {}) {
497920
497791
  command.on("error", (err) => logger15.debug("[ffmpeg] error:", err));
497921
497792
  command.on("end", () => logger15.debug("[ffmpeg] end"));
497922
497793
  command.run();
497923
- const writeRepeatedFrames = runExclusive3.build(async (jpeg, repeat6) => {
497794
+ const writeRepeatedFrames = runExclusive2.build(async (jpeg, repeat6) => {
497924
497795
  for (let i6 = 0;i6 < repeat6; i6++) {
497925
497796
  if (!mjpegStream.write(jpeg)) {
497926
497797
  await new Promise((r6) => mjpegStream.once("drain", r6));
@@ -527152,6 +527023,189 @@ class NodeBlobStore {
527152
527023
  }
527153
527024
  }
527154
527025
 
527026
+ // src/renderers/experimental-trajectory-stream-renderer.ts
527027
+ var runExclusive3 = __toESM(require_runExclusive(), 1);
527028
+
527029
+ // src/renderers/utils.ts
527030
+ async function inlineSubTask(store, message) {
527031
+ const partsWithSubtasks = message.parts.map((part) => {
527032
+ if (part.type === "tool-newTask" && part.state !== "input-streaming") {
527033
+ const input = part.input;
527034
+ const subtaskId = input._meta?.uid;
527035
+ if (subtaskId) {
527036
+ const subtask = store.query(defaultCatalog.queries.makeTaskQuery(subtaskId));
527037
+ const subtaskMessages = store.query(defaultCatalog.queries.makeMessagesQuery(subtaskId));
527038
+ if (subtask) {
527039
+ return {
527040
+ ...part,
527041
+ input: {
527042
+ ...input,
527043
+ _transient: {
527044
+ task: {
527045
+ clientTaskId: subtaskId,
527046
+ messages: subtaskMessages.map((m6) => m6.data),
527047
+ todos: subtask.todos.map((t10) => ({ ...t10 }))
527048
+ }
527049
+ }
527050
+ }
527051
+ };
527052
+ }
527053
+ }
527054
+ }
527055
+ return part;
527056
+ });
527057
+ return {
527058
+ ...message,
527059
+ parts: partsWithSubtasks
527060
+ };
527061
+ }
527062
+ async function mapStoreBlob(store, o14) {
527063
+ if (t3(o14) && o14.startsWith(store.protocol)) {
527064
+ const blob3 = await store.get(o14);
527065
+ if (!blob3)
527066
+ throw new Error(`Store blob not found at "${o14}"`);
527067
+ const base643 = Buffer.from(blob3.data).toString("base64");
527068
+ return `data:${blob3.mimeType};base64,${base643}`;
527069
+ }
527070
+ if (o5(o14)) {
527071
+ return Promise.all(o14.map((el) => mapStoreBlob(store, el)));
527072
+ }
527073
+ if (o4(o14)) {
527074
+ const entires = await Promise.all(t4(o14).map(async ([k6, v6]) => [
527075
+ k6,
527076
+ await mapStoreBlob(store, v6)
527077
+ ]));
527078
+ return n2(entires);
527079
+ }
527080
+ return o14;
527081
+ }
527082
+
527083
+ // src/renderers/experimental-trajectory-stream-renderer.ts
527084
+ class ExperimentalTrajectoryStreamRenderer {
527085
+ stream;
527086
+ store;
527087
+ blobStore;
527088
+ state;
527089
+ emittedParts = new Map;
527090
+ emittedMetadata = new Set;
527091
+ unsubscribe;
527092
+ constructor(stream29, store, blobStore, state2) {
527093
+ this.stream = stream29;
527094
+ this.store = store;
527095
+ this.blobStore = blobStore;
527096
+ this.state = state2;
527097
+ this.unsubscribe = this.state.signal.messages.subscribe(runExclusive3.build(async (messages3) => {
527098
+ await this.outputTrajectory(messages3);
527099
+ }));
527100
+ }
527101
+ async outputTrajectory(messages3, isFinalFlush = false) {
527102
+ for (let msgIdx = 0;msgIdx < messages3.length; msgIdx++) {
527103
+ const message = messages3[msgIdx];
527104
+ const isFinalized = isFinalFlush || msgIdx < messages3.length - 1;
527105
+ const outputMessage = await inlineSubTask(this.store, message);
527106
+ for (let i10 = 0;i10 < outputMessage.parts.length; i10++) {
527107
+ const part = outputMessage.parts[i10];
527108
+ const partId = `${message.id}:${i10}`;
527109
+ const resolvedPart = await mapStoreBlob(this.blobStore, part);
527110
+ const cachedPart = this.emittedParts.get(partId);
527111
+ if (!k(cachedPart, resolvedPart)) {
527112
+ const outputData = {
527113
+ type: "message-part",
527114
+ messageId: message.id,
527115
+ role: message.role,
527116
+ index: i10,
527117
+ part: resolvedPart
527118
+ };
527119
+ this.stream.write(`${JSON.stringify(outputData)}
527120
+ `);
527121
+ this.emittedParts.set(partId, p2(resolvedPart));
527122
+ }
527123
+ }
527124
+ if (isFinalized && !this.emittedMetadata.has(message.id)) {
527125
+ if (outputMessage.metadata !== undefined) {
527126
+ const outputData = {
527127
+ type: "message-metadata",
527128
+ messageId: message.id,
527129
+ role: message.role,
527130
+ metadata: outputMessage.metadata
527131
+ };
527132
+ this.stream.write(`${JSON.stringify(outputData)}
527133
+ `);
527134
+ }
527135
+ this.emittedMetadata.add(message.id);
527136
+ }
527137
+ }
527138
+ }
527139
+ async shutdown() {
527140
+ if (this.unsubscribe) {
527141
+ this.unsubscribe();
527142
+ this.unsubscribe = undefined;
527143
+ }
527144
+ await runExclusive3.build(async () => {
527145
+ await this.outputTrajectory(this.state.signal.messages.value, true);
527146
+ await this.outputFilesData();
527147
+ })();
527148
+ }
527149
+ async outputFilesData() {
527150
+ const files = this.store.query(defaultCatalog.queries.makeStoreFilesQuery());
527151
+ if (files.length > 0) {
527152
+ const data = {
527153
+ type: "files",
527154
+ files
527155
+ };
527156
+ this.stream.write(`${JSON.stringify(data)}
527157
+ `);
527158
+ }
527159
+ }
527160
+ }
527161
+ // src/renderers/json-renderer.ts
527162
+ var runExclusive4 = __toESM(require_runExclusive(), 1);
527163
+ class JsonRenderer {
527164
+ stream;
527165
+ store;
527166
+ blobStore;
527167
+ state;
527168
+ outputMessageIds = new Set;
527169
+ lastMessageCount = 0;
527170
+ constructor(stream29, store, blobStore, state2) {
527171
+ this.stream = stream29;
527172
+ this.store = store;
527173
+ this.blobStore = blobStore;
527174
+ this.state = state2;
527175
+ this.state.signal.messages.subscribe(runExclusive4.build(async (messages3) => {
527176
+ if (messages3.length > this.lastMessageCount) {
527177
+ await this.outputMessages(messages3.slice(0, -1));
527178
+ this.lastMessageCount = messages3.length;
527179
+ }
527180
+ }));
527181
+ }
527182
+ async shutdown() {
527183
+ await this.outputMessages(this.state.signal.messages.value);
527184
+ await this.outputFilesData();
527185
+ }
527186
+ async outputMessages(messages3) {
527187
+ for (const message of messages3) {
527188
+ if (!this.outputMessageIds.has(message.id)) {
527189
+ let outputMessage = await inlineSubTask(this.store, message);
527190
+ outputMessage = await mapStoreBlob(this.blobStore, outputMessage);
527191
+ this.stream.write(`${JSON.stringify(outputMessage)}
527192
+ `);
527193
+ this.outputMessageIds.add(message.id);
527194
+ }
527195
+ }
527196
+ }
527197
+ async outputFilesData() {
527198
+ const files = this.store.query(defaultCatalog.queries.makeStoreFilesQuery());
527199
+ if (files.length > 0) {
527200
+ const data = {
527201
+ type: "files",
527202
+ files
527203
+ };
527204
+ this.stream.write(`${JSON.stringify(data)}
527205
+ `);
527206
+ }
527207
+ }
527208
+ }
527155
527209
  // ../../node_modules/unist-util-find-after/lib/index.js
527156
527210
  var findAfter = function(parent, index3, test3) {
527157
527211
  const is6 = convert(test3);
@@ -537977,7 +538031,7 @@ function findTodos(message) {
537977
538031
  }, []);
537978
538032
  return todos;
537979
538033
  }
537980
- // src/output-renderer.ts
538034
+ // src/renderers/output-renderer.ts
537981
538035
  init_source();
537982
538036
 
537983
538037
  // ../../node_modules/eventemitter3/index.mjs
@@ -539883,7 +539937,7 @@ var Listr = class {
539883
539937
  }
539884
539938
  };
539885
539939
 
539886
- // src/output-renderer.ts
539940
+ // src/renderers/output-renderer.ts
539887
539941
  class OutputRenderer {
539888
539942
  stream;
539889
539943
  state;
@@ -540060,6 +540114,14 @@ ${optionsText}` : ""}`;
540060
540114
  error: errorText
540061
540115
  };
540062
540116
  }
540117
+ if (part.type === "tool-useSkill") {
540118
+ const { skill = "unknown" } = part.input || {};
540119
+ return {
540120
+ text: `\uD83E\uDDE9 Using skill ${source_default.bold(skill)}`,
540121
+ stop: hasError ? "fail" : "succeed",
540122
+ error: errorText
540123
+ };
540124
+ }
540063
540125
  if (part.type === "tool-todoWrite") {
540064
540126
  const { todos = [] } = part.input || {};
540065
540127
  return {
@@ -540254,7 +540316,38 @@ function renderSubtaskMessages(messages3) {
540254
540316
  }
540255
540317
  return output;
540256
540318
  }
540257
-
540319
+ // src/renderers/result-renderer.ts
540320
+ class ResultRenderer {
540321
+ stream;
540322
+ state;
540323
+ attemptCompletionSchemaOverride;
540324
+ constructor(stream29, state2, options14 = {}) {
540325
+ this.stream = stream29;
540326
+ this.state = state2;
540327
+ this.attemptCompletionSchemaOverride = !!options14.attemptCompletionSchemaOverride;
540328
+ }
540329
+ async shutdown() {
540330
+ const messages3 = this.state.signal.messages.value;
540331
+ const lastMessage = messages3.at(-1);
540332
+ if (lastMessage?.role === "assistant") {
540333
+ for (const part of lastMessage.parts || []) {
540334
+ if (isToolUIPart(part) && part.type === "tool-attemptCompletion") {
540335
+ if (part.input) {
540336
+ const input = part.input;
540337
+ if (this.attemptCompletionSchemaOverride) {
540338
+ this.stream.write(`${JSON.stringify(input.result, null, 2)}
540339
+ `);
540340
+ } else {
540341
+ this.stream.write(`${input.result}
540342
+ `);
540343
+ }
540344
+ }
540345
+ return;
540346
+ }
540347
+ }
540348
+ }
540349
+ }
540350
+ }
540258
540351
  // src/task-runner.ts
540259
540352
  import { spawn as spawn6 } from "node:child_process";
540260
540353
 
@@ -545365,6 +545458,26 @@ import {
545365
545458
  exec as exec9
545366
545459
  } from "node:child_process";
545367
545460
  import * as path36 from "node:path";
545461
+ class ExecuteCommandError extends Error {
545462
+ code;
545463
+ stdout;
545464
+ stderr;
545465
+ constructor({
545466
+ message,
545467
+ code: code4,
545468
+ stdout: stdout5,
545469
+ stderr: stderr7
545470
+ }) {
545471
+ super(message);
545472
+ this.name = "ExecuteCommandError";
545473
+ this.code = code4;
545474
+ this.stdout = stdout5;
545475
+ this.stderr = stderr7;
545476
+ }
545477
+ asOutput() {
545478
+ return processCommandOutput(this.stdout, this.stderr, this.message);
545479
+ }
545480
+ }
545368
545481
  var executeCommand2 = () => async ({ command, cwd: cwd3 = ".", timeout: timeout5 = 120 }, { abortSignal, cwd: workspaceDir, envs }) => {
545369
545482
  if (!command) {
545370
545483
  throw new Error("Command is required to execute.");
@@ -545376,27 +545489,20 @@ var executeCommand2 = () => async ({ command, cwd: cwd3 = ".", timeout: timeout5
545376
545489
  resolvedCwd = path36.normalize(path36.join(workspaceDir, cwd3));
545377
545490
  }
545378
545491
  try {
545379
- const {
545380
- code: code4,
545381
- stdout: stdout5 = "",
545382
- stderr: stderr7 = ""
545383
- } = await execWithExitCode(timeout5, command, {
545492
+ const { stdout: stdout5 = "", stderr: stderr7 = "" } = await execWithExitCode(command, {
545384
545493
  shell: getShellPath(),
545385
545494
  timeout: timeout5 * 1000,
545386
545495
  cwd: resolvedCwd,
545387
545496
  signal: abortSignal,
545388
545497
  env: { ...process.env, ...envs, ...getTerminalEnv() }
545389
545498
  });
545390
- const { output, isTruncated } = processCommandOutput(stdout5, stderr7, code4);
545391
- return {
545392
- output,
545393
- isTruncated
545394
- };
545499
+ return processCommandOutput(stdout5, stderr7);
545395
545500
  } catch (error48) {
545396
- if (error48 instanceof Error) {
545397
- if (error48.name === "AbortError") {
545398
- throw new Error("Command execution was aborted");
545399
- }
545501
+ if (error48 instanceof ExecuteCommandError) {
545502
+ throw error48;
545503
+ }
545504
+ if (error48 instanceof Error && error48.name === "AbortError") {
545505
+ throw new Error("Command execution was aborted");
545400
545506
  }
545401
545507
  const errorMessage = error48 instanceof Error ? error48.message : String(error48);
545402
545508
  throw new Error(errorMessage);
@@ -545405,7 +545511,7 @@ var executeCommand2 = () => async ({ command, cwd: cwd3 = ".", timeout: timeout5
545405
545511
  function isExecException(error48) {
545406
545512
  return error48 instanceof Error && "cmd" in error48 && "killed" in error48 && "code" in error48 && "signal" in error48;
545407
545513
  }
545408
- async function execWithExitCode(timeout5, command, options14) {
545514
+ async function execWithExitCode(command, options14) {
545409
545515
  return await new Promise((resolve25, reject3) => {
545410
545516
  const child = exec9(command, options14, (err3, stdout5 = "", stderr7 = "") => {
545411
545517
  if (!err3) {
@@ -545417,15 +545523,21 @@ async function execWithExitCode(timeout5, command, options14) {
545417
545523
  return;
545418
545524
  }
545419
545525
  if (isExecException(err3)) {
545420
- if (err3.signal === "SIGTERM" && err3.killed) {
545421
- reject3(new Error(`Command execution timed out after ${timeout5} seconds.`));
545526
+ if (err3.signal === "SIGTERM" && err3.killed && options14.timeout && options14.timeout > 0) {
545527
+ reject3(new ExecuteCommandError({
545528
+ message: `Command execution timed out after ${options14.timeout / 1000} seconds.`,
545529
+ stdout: err3.stdout ?? stdout5 ?? "",
545530
+ stderr: err3.stderr ?? stderr7 ?? "",
545531
+ code: err3.code ?? 1
545532
+ }));
545422
545533
  return;
545423
545534
  }
545424
- resolve25({
545425
- stdout: err3.stdout || "",
545426
- stderr: err3.stderr || "",
545427
- code: err3.code || 1
545428
- });
545535
+ reject3(new ExecuteCommandError({
545536
+ message: `Command exited with code ${err3.code ?? 1}`,
545537
+ stdout: err3.stdout ?? stdout5 ?? "",
545538
+ stderr: err3.stderr ?? stderr7 ?? "",
545539
+ code: err3.code ?? 1
545540
+ }));
545429
545541
  return;
545430
545542
  }
545431
545543
  reject3(err3);
@@ -545433,14 +545545,17 @@ async function execWithExitCode(timeout5, command, options14) {
545433
545545
  child.stdin?.end();
545434
545546
  });
545435
545547
  }
545436
- function processCommandOutput(stdout5, stderr7, code4) {
545437
- let fullOutput = fixExecuteCommandOutput(stdout5 + stderr7);
545438
- if (code4 !== 0) {
545439
- fullOutput += `
545440
- Command exited with code ${code4}`;
545441
- }
545548
+ function processCommandOutput(stdout5, stderr7, errorMessage) {
545549
+ const fullOutput = fixExecuteCommandOutput(stdout5 + stderr7);
545442
545550
  const isTruncated = fullOutput.length > MaxTerminalOutputSize;
545443
545551
  const output = isTruncated ? fullOutput.slice(-MaxTerminalOutputSize) : fullOutput;
545552
+ if (errorMessage) {
545553
+ return {
545554
+ output,
545555
+ isTruncated,
545556
+ error: errorMessage
545557
+ };
545558
+ }
545444
545559
  return { output, isTruncated };
545445
545560
  }
545446
545561
 
@@ -545753,6 +545868,9 @@ async function executeToolCall(tool2, options14, cwd3, abortSignal, contentType,
545753
545868
  envs
545754
545869
  });
545755
545870
  } catch (e9) {
545871
+ if (e9 instanceof ExecuteCommandError) {
545872
+ return e9.asOutput();
545873
+ }
545756
545874
  return {
545757
545875
  error: toErrorMessage(e9)
545758
545876
  };
@@ -546472,7 +546590,7 @@ var parseNonNegativeInt = (input) => {
546472
546590
  }
546473
546591
  return result2;
546474
546592
  };
546475
- var program7 = new Command().name("pochi").description(`${source_default.bold("Pochi")} v${package_default.version} - A powerful CLI tool for AI-driven development.`).optionsGroup("Prompt:").option("-p, --prompt <prompt>", "Create a new task with a given prompt. Input can also be piped. For example: `cat my-prompt.md | pochi`.").option("-a, --attach <path...>", "Attach one or more files to the prompt, e.g images").optionsGroup("Options:").option("--stream-json [filepath]", "Stream the output in JSON format. This is useful for parsing the output in scripts. If filepath is not specified, the output will be written to stdout, mixed with normal UI output. Cannot be used with --output-result.").option("-x, --output-result [filepath]", "Output the result from attemptCompletion. This is useful for scripts that need to capture the final result. If filepath is not specified, the output will be written to stdout, mixed with normal UI output. Cannot be used with --stream-json.").option("--max-steps <number>", "Set the maximum number of steps for a task. The task will stop if it exceeds this limit.", parsePositiveInt, 24).option("--max-retries <number>", "Set the maximum number of retries for a single step in a task.", parsePositiveInt, 3).option("--async-wait-timeout <ms>", "Wait for async subtasks and background jobs to complete before finalizing attemptCompletion. Set to 0 to disable waiting.", parseNonNegativeInt, 60000).option("--agent <name>", "Run the task as a sub-agent using the specified custom agent. This applies the agent's system prompt and tool restrictions, matching the behavior of sub-tasks created via the newTask tool.").addOption(new Option("--experimental-output-schema <schema>", "Specify a JSON schema for the output of the task. The task will be validated against this schema.").hideHelp()).addOption(new Option("--attempt-completion-schema <schema>", "Specify a JSON schema that attempt-completion will enforce.").hideHelp()).addOption(new Option("--attempt-completion-hook <command>", "Specify a command that attempt-completion will run").hideHelp()).addOption(new Option("--ffmpeg <path>", "Specify the path to the ffmpeg executable for browser session recording. Pochi will try to use the ffmpeg executable in the system path if this option is not specified. Browser session recording is disabled when no ffmpeg executable available.").hideHelp()).addOption(new Option("--blobs-dir <path>", "Specify the path to be used as a storage directory for blobs.").default(path40.join(os16.tmpdir(), "pochi", "blobs")).hideHelp()).optionsGroup("Model:").option("-m, --model <model>", "Specify the model to be used for the task.", "google/gemini-3-flash").optionsGroup("MCP:").option("--no-mcp", "Disable MCP (Model Context Protocol) integration completely.").action(async (options14) => {
546593
+ var program7 = new Command().name("pochi").description(`${source_default.bold("Pochi")} v${package_default.version} - A powerful CLI tool for AI-driven development.`).optionsGroup("Prompt:").option("-p, --prompt <prompt>", "Create a new task with a given prompt. Input can also be piped. For example: `cat my-prompt.md | pochi`.").option("-a, --attach <path...>", "Attach one or more files to the prompt, e.g images").optionsGroup("Options:").option("--stream-json [filepath]", "Stream the output in JSON format. This is useful for parsing the output in scripts. If filepath is not specified, the output will be written to stdout, mixed with normal UI output. Cannot be used with --output-result.").option("-x, --output-result [filepath]", "Output the result from attemptCompletion. This is useful for scripts that need to capture the final result. If filepath is not specified, the output will be written to stdout, mixed with normal UI output. Cannot be used with --stream-json.").option("--experimental-stream-trajectory [filepath]", "Stream message parts whenever signal.messages updates. Cannot be used with --stream-json or --output-result.").option("--max-steps <number>", "Set the maximum number of steps for a task. The task will stop if it exceeds this limit.", parsePositiveInt, 24).option("--max-retries <number>", "Set the maximum number of retries for a single step in a task.", parsePositiveInt, 3).option("--async-wait-timeout <ms>", "Wait for async subtasks and background jobs to complete before finalizing attemptCompletion. Set to 0 to disable waiting.", parseNonNegativeInt, 60000).option("--agent <name>", "Run the task as a sub-agent using the specified custom agent. This applies the agent's system prompt and tool restrictions, matching the behavior of sub-tasks created via the newTask tool.").addOption(new Option("--experimental-output-schema <schema>", "Specify a JSON schema for the output of the task. The task will be validated against this schema.").hideHelp()).addOption(new Option("--attempt-completion-schema <schema>", "Specify a JSON schema that attempt-completion will enforce.").hideHelp()).addOption(new Option("--attempt-completion-hook <command>", "Specify a command that attempt-completion will run").hideHelp()).addOption(new Option("--ffmpeg <path>", "Specify the path to the ffmpeg executable for browser session recording. Pochi will try to use the ffmpeg executable in the system path if this option is not specified. Browser session recording is disabled when no ffmpeg executable available.").hideHelp()).addOption(new Option("--blobs-dir <path>", "Specify the path to be used as a storage directory for blobs.").default(path40.join(os16.tmpdir(), "pochi", "blobs")).hideHelp()).optionsGroup("Model:").option("-m, --model <model>", "Specify the model to be used for the task.", "google/gemini-3-flash").optionsGroup("MCP:").option("--no-mcp", "Disable MCP (Model Context Protocol) integration completely.").action(async (options14) => {
546476
546594
  const customAgents = await loadAgents(process.cwd());
546477
546595
  const skills = await loadSkills(process.cwd());
546478
546596
  let selectedAgent;
@@ -546515,8 +546633,8 @@ ${available2 || " (none)"}`);
546515
546633
  setFfmpegPath(options14.ffmpeg);
546516
546634
  }
546517
546635
  let jsonOutputStream = undefined;
546518
- if (options14.streamJson && options14.outputResult) {
546519
- program7.error("Cannot use --stream-json and --output-result at same time.");
546636
+ if ((options14.streamJson ? 1 : 0) + (options14.outputResult ? 1 : 0) + (options14.experimentalStreamTrajectory ? 1 : 0) > 1) {
546637
+ program7.error("Cannot use more than one of --stream-json, --output-result, or --experimental-stream-trajectory at the same time.");
546520
546638
  }
546521
546639
  if (options14.streamJson === true) {
546522
546640
  jsonOutputStream = process.stdout;
@@ -546526,6 +546644,10 @@ ${available2 || " (none)"}`);
546526
546644
  jsonOutputStream = process.stdout;
546527
546645
  } else if (typeof options14.outputResult === "string") {
546528
546646
  jsonOutputStream = fs21.createWriteStream(options14.outputResult);
546647
+ } else if (options14.experimentalStreamTrajectory === true) {
546648
+ jsonOutputStream = process.stdout;
546649
+ } else if (typeof options14.experimentalStreamTrajectory === "string") {
546650
+ jsonOutputStream = fs21.createWriteStream(options14.experimentalStreamTrajectory);
546529
546651
  }
546530
546652
  const mcpHub = options14.mcp ? await initializeMcp(program7) : undefined;
546531
546653
  const abortController = createAbortControllerWithGracefulShutdown();
@@ -546565,12 +546687,17 @@ ${available2 || " (none)"}`);
546565
546687
  const outputRenderer = new OutputRenderer(process.stdout, runner.state, {
546566
546688
  attemptCompletionSchemaOverride: !!options14.attemptCompletionSchema
546567
546689
  });
546568
- let jsonRenderer = undefined;
546690
+ let streamRenderer = undefined;
546569
546691
  if (jsonOutputStream) {
546570
- jsonRenderer = new JsonRenderer(jsonOutputStream, store, blobStore, runner.state, {
546571
- mode: options14.outputResult ? "result-only" : "full",
546572
- attemptCompletionSchemaOverride: !!options14.attemptCompletionSchema
546573
- });
546692
+ if (options14.experimentalStreamTrajectory) {
546693
+ streamRenderer = new ExperimentalTrajectoryStreamRenderer(jsonOutputStream, store, blobStore, runner.state);
546694
+ } else if (options14.outputResult) {
546695
+ streamRenderer = new ResultRenderer(jsonOutputStream, runner.state, {
546696
+ attemptCompletionSchemaOverride: !!options14.attemptCompletionSchema
546697
+ });
546698
+ } else {
546699
+ streamRenderer = new JsonRenderer(jsonOutputStream, store, blobStore, runner.state);
546700
+ }
546574
546701
  }
546575
546702
  let runtimeError = undefined;
546576
546703
  try {
@@ -546579,7 +546706,7 @@ ${available2 || " (none)"}`);
546579
546706
  runtimeError = error48 instanceof Error ? error48 : new Error(String(error48));
546580
546707
  } finally {
546581
546708
  outputRenderer.shutdown();
546582
- await jsonRenderer?.shutdown();
546709
+ await streamRenderer?.shutdown();
546583
546710
  if (jsonOutputStream && jsonOutputStream instanceof fs21.WriteStream) {
546584
546711
  jsonOutputStream.end();
546585
546712
  await finished(jsonOutputStream);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpochi/cli",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "devDependencies": {
5
5
  "@commander-js/extra-typings": "^14.0.0",
6
6
  "@getpochi/common": "0.1.0-dev",