@yefengr/steward 0.3.0 → 0.3.1

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/extension.js CHANGED
@@ -320,8 +320,9 @@ var claimedAttemptSchema = z.strictObject({
320
320
  taskId: uuidSchema,
321
321
  projectId: projectIdSchema,
322
322
  agent: z.literal("pi"),
323
- sessionId: tmuxSessionSchema,
323
+ sessionId: piSessionIdSchema,
324
324
  restoreSession: z.boolean(),
325
+ sessionLocator: piSessionLocatorSchema.optional(),
325
326
  displayName: z.string().min(1).max(80),
326
327
  kind: z.enum(["new", "rework"])
327
328
  });
@@ -1076,6 +1077,12 @@ var TERMINAL = /* @__PURE__ */ new Set([
1076
1077
  ]);
1077
1078
  function registerSessionReport(pi, request, resumed) {
1078
1079
  let active;
1080
+ let queue = Promise.resolve();
1081
+ function serial(run) {
1082
+ const result = queue.then(run);
1083
+ queue = result.catch(() => void 0);
1084
+ return result;
1085
+ }
1079
1086
  pi.on("session_start", (_event, ctx) => {
1080
1087
  active?.abort();
1081
1088
  const controller = new AbortController();
@@ -1083,7 +1090,7 @@ function registerSessionReport(pi, request, resumed) {
1083
1090
  const { signal } = controller;
1084
1091
  async function send() {
1085
1092
  const locator = await currentSessionLocator(ctx, resumed);
1086
- if (!locator) return;
1093
+ if (!locator || signal.aborted) return;
1087
1094
  const body = {
1088
1095
  requestId: randomUUID(),
1089
1096
  locator
@@ -1099,9 +1106,12 @@ function registerSessionReport(pi, request, resumed) {
1099
1106
  });
1100
1107
  }
1101
1108
  }
1102
- send().catch(() => void 0);
1109
+ serial(send).catch(() => void 0);
1103
1110
  });
1104
1111
  pi.on("session_shutdown", () => active?.abort());
1112
+ return { workspace(run) {
1113
+ return serial(run);
1114
+ } };
1105
1115
  }
1106
1116
  // packages/pi-extension/dist/task-session.js
1107
1117
  var SOURCE_ENTRY = "steward-launch-source";
@@ -1245,7 +1255,7 @@ function registerSteward(pi, options = { env: process.env }) {
1245
1255
  registerTaskSession(pi, attempt.success);
1246
1256
  if (!attempt.success) return;
1247
1257
  const request = agentClient(attempt.data, options);
1248
- registerSessionReport(pi, request, options.env.STEWARD_RESUME === "1");
1258
+ const sessionReport = registerSessionReport(pi, request, options.env.STEWARD_RESUME === "1");
1249
1259
  const control = registerAttemptControl(pi, attempt.data, request);
1250
1260
  const write = retryableWrites();
1251
1261
  const requestId = deliveryId(attempt.data);
@@ -1275,15 +1285,18 @@ function registerSteward(pi, options = { env: process.env }) {
1275
1285
  parameters: Type.Object({}),
1276
1286
  execute: (_id, _args, signal, _update, ctx) => report(async () => {
1277
1287
  if (taskContext?.task.type !== "implementation") throw new AgentError("task_context_required");
1278
- const workspace = await currentWorkspace(ctx, taskContext.workspace.path);
1279
- await write("POST", "workspace", workspace, (requestId) => request("POST", "workspace", okResponseSchema, validatedBody(agentWorkspaceRequestSchema, {
1280
- workspace,
1281
- requestId
1282
- }), signal));
1283
- return {
1284
- ok: true,
1285
- workspace
1286
- };
1288
+ const registeredPath = taskContext.workspace.path;
1289
+ return sessionReport.workspace(async () => {
1290
+ const workspace = await currentWorkspace(ctx, registeredPath);
1291
+ await write("POST", "workspace", workspace, (requestId) => request("POST", "workspace", okResponseSchema, validatedBody(agentWorkspaceRequestSchema, {
1292
+ workspace,
1293
+ requestId
1294
+ }), signal));
1295
+ return {
1296
+ ok: true,
1297
+ workspace
1298
+ };
1299
+ });
1287
1300
  })
1288
1301
  });
1289
1302
  pi.registerTool({
package/dist/index.js CHANGED
@@ -321,8 +321,9 @@ var claimedAttemptSchema = z.strictObject({
321
321
  taskId: uuidSchema,
322
322
  projectId: projectIdSchema,
323
323
  agent: z.literal("pi"),
324
- sessionId: tmuxSessionSchema,
324
+ sessionId: piSessionIdSchema,
325
325
  restoreSession: z.boolean(),
326
+ sessionLocator: piSessionLocatorSchema.optional(),
326
327
  displayName: z.string().min(1).max(80),
327
328
  kind: z.enum(["new", "rework"])
328
329
  });
@@ -862,6 +863,8 @@ function tmuxClient(config, options) {
862
863
  },
863
864
  async launch(target, claim, projectPath) {
864
865
  const message = `${claim.kind === "rework" ? "返修本任务。" : "开始执行本任务。"}${instructions}`;
866
+ const locator = claim.sessionLocator;
867
+ if (claim.kind === "rework" && !locator) throw new TmuxError(true);
865
868
  try {
866
869
  await exec([
867
870
  "new-session",
@@ -869,7 +872,8 @@ function tmuxClient(config, options) {
869
872
  "-s",
870
873
  target,
871
874
  "-c",
872
- `${projectPath.replaceAll("#", "##")}/.`,
875
+ `${(locator?.path ?? projectPath).replaceAll("#", "##")}/.`,
876
+ ...locator ? ["-e", "STEWARD_RESUME=1"] : [],
873
877
  "-e",
874
878
  `STEWARD_ATTEMPT_ID=${claim.id}`,
875
879
  "-e",
@@ -881,8 +885,7 @@ function tmuxClient(config, options) {
881
885
  ...config.pi.extraArgs,
882
886
  "-e",
883
887
  options.extensionPath,
884
- "--session-id",
885
- claim.sessionId,
888
+ ...locator ? ["--session", escapedTmuxArg(locator.sessionFile)] : ["--session-id", claim.sessionId],
886
889
  "-n",
887
890
  displayName(claim.displayName),
888
891
  "--",
@@ -1447,11 +1450,19 @@ var Launcher = class {
1447
1450
  this.exited(record);
1448
1451
  return;
1449
1452
  }
1453
+ if (claim.kind === "rework") {
1454
+ const failure = !claim.sessionLocator ? "session_record_missing" : validateLocator(claim.sessionLocator) ?? (supportsResumeArgs(this.options.config.pi.extraArgs) ? void 0 : "session_config_unsupported");
1455
+ if (failure) {
1456
+ this.options.warn?.(`返修无法启动(${failure}),未回退到登记目录或其他会话。`);
1457
+ this.exited(record);
1458
+ return;
1459
+ }
1460
+ }
1450
1461
  record.phase = "launching";
1451
1462
  record.startedAt = this.now();
1452
1463
  this.persist();
1453
1464
  if (await this.retryable(async () => {
1454
- await this.options.tmux.launch(record.target, claim, project.path);
1465
+ await this.options.tmux.launch(record.target, claim, claim.sessionLocator?.path ?? project.path);
1455
1466
  return true;
1456
1467
  })) this.started(record);
1457
1468
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yefengr/steward",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Task Steward macOS launcher and task extension",
5
5
  "repository": {
6
6
  "type": "git",