pi-awaken 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/index.ts +15 -8
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -22,7 +22,7 @@ const sleep = (ms: number) => new Promise((done) => setTimeout(done, ms));
22
22
 
23
23
  function installCli() {
24
24
  const target = join(agentBin(), "pi-wake");
25
- const shim = `#!/bin/sh\nexec node "${cliPath}" "$@"\n`;
25
+ const shim = `#!/bin/sh\nexec "${process.execPath}" "${cliPath}" "$@"\n`;
26
26
  try {
27
27
  if (existsSync(target) && readFileSync(target, "utf8") === shim) return;
28
28
  mkdirSync(agentBin(), { recursive: true });
@@ -101,21 +101,23 @@ export default function (pi: ExtensionAPI) {
101
101
  const s = store;
102
102
  const items = queue.splice(0);
103
103
  if (!s || !items.length) return;
104
- const body = items.map(renderWake).join("\n\n");
105
- const title = items.length > 1 ? `[pi-wake] ${items.length} background events` : "[pi-wake]";
104
+ const fresh = items.filter((item) => item.kind !== "exit" || !s.get(item.job.id)?.delivered);
105
+ for (const item of items) queued.delete(item.key);
106
+ if (!fresh.length) return;
107
+ const body = fresh.map(renderWake).join("\n\n");
108
+ const title = fresh.length > 1 ? `[pi-wake] ${fresh.length} background events` : "[pi-wake]";
106
109
  pi.sendMessage(
107
110
  {
108
111
  customType: "pi-wake",
109
112
  content: `${title}\n${body}`,
110
113
  display: true,
111
- details: { events: items.map((item) => item.key) },
114
+ details: { events: fresh.map((item) => item.key) },
112
115
  },
113
116
  { triggerTurn: true, deliverAs: "steer" },
114
117
  );
115
- for (const item of items) {
118
+ for (const item of fresh) {
116
119
  if (item.kind === "exit") s.markDelivered(item.job.id);
117
120
  if (item.kind === "message") s.consume(item.message.file);
118
- queued.delete(item.key);
119
121
  }
120
122
  }
121
123
 
@@ -245,8 +247,13 @@ export default function (pi: ExtensionAPI) {
245
247
  PATH: [agentBin(), process.env.PATH ?? ""].join(delimiter),
246
248
  },
247
249
  });
248
- const early = await waitForExit(s, job.id, INLINE_WINDOW_MS, signal);
249
- if (early) return finishedResult(s, early);
250
+ busy.add(job.id);
251
+ try {
252
+ const early = await waitForExit(s, job.id, INLINE_WINDOW_MS, signal);
253
+ if (early) return finishedResult(s, early);
254
+ } finally {
255
+ busy.delete(job.id);
256
+ }
250
257
  tick();
251
258
  const text = [
252
259
  `Started ${header(job)} in the background (pid ${job.pid}).`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-awaken",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Pi extension: run long shell scripts in the background and get woken when they finish, match output, or anything calls pi-wake.",
5
5
  "type": "module",
6
6
  "keywords": [