portable-agent-layer 0.114.0-canary.21 → 0.114.0-canary.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portable-agent-layer",
3
- "version": "0.114.0-canary.21",
3
+ "version": "0.114.0-canary.22",
4
4
  "description": "PAL — Portable Agent Layer: persistent personal context for AI coding assistants",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,7 +21,7 @@ import { COMMAND_KEYS, resultOf, stringIn } from "./tool-events";
21
21
  const GH_PR_CREATE_RE = /\bgh\s+pr\s+create\b/;
22
22
  const PR_URL_RE = /https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/g;
23
23
  const FACTORY_BUILD_RE =
24
- /\bdark-factory[\\/](?:\S*[\\/])?scripts[\\/]build\.mjs["']?\s+["']?(\w[\w.-]*)/;
24
+ /\b(?:node|bun)(?:\.exe)?\s+(?:run\s+)?["']?\S*\bdark-factory[\\/](?:\S*[\\/])?scripts[\\/]build\.mjs["']?\s+["']?(\w[\w.-]*)/;
25
25
  const FACTORY_RUN_PREFIX = "dark-factory:";
26
26
  const OUTPUT_KEYS = [
27
27
  "stdout",
@@ -194,6 +194,39 @@ export function appendEvent<T extends WorkEvent["type"]>(
194
194
  return event;
195
195
  }
196
196
 
197
+ type ArtifactRef = { kind: ArtifactKind; ref: string };
198
+
199
+ const PR_URL_RE = /^https?:\/\//;
200
+ const SHORT_SHA_LENGTH = 7;
201
+
202
+ function prNumberOf(ref: string): string | null {
203
+ return /(\d+)$/.exec(ref)?.[1] ?? null;
204
+ }
205
+
206
+ function samePr(a: string, b: string): boolean {
207
+ if (PR_URL_RE.test(a) && PR_URL_RE.test(b)) return a === b;
208
+ const number = prNumberOf(a);
209
+ return number !== null && number === prNumberOf(b);
210
+ }
211
+
212
+ function sameCommit(a: string, b: string): boolean {
213
+ const [short, long] = a.length <= b.length ? [a, b] : [b, a];
214
+ return short.length >= SHORT_SHA_LENGTH && long.startsWith(short);
215
+ }
216
+
217
+ function sameArtifact(a: ArtifactRef, b: ArtifactRef): boolean {
218
+ if (a.kind !== b.kind) return false;
219
+ if (a.kind === "pr") return samePr(a.ref, b.ref);
220
+ if (a.kind === "commit") return sameCommit(a.ref, b.ref);
221
+ return a.ref === b.ref;
222
+ }
223
+
224
+ function addArtifact(node: WorkNode, artifact: Artifact): void {
225
+ const known = node.artifacts.find((a) => sameArtifact(a, artifact));
226
+ if (!known) node.artifacts.push(artifact);
227
+ else known.label ??= artifact.label;
228
+ }
229
+
197
230
  export function attachOnce(
198
231
  scope: string,
199
232
  node: WorkNode,
@@ -202,8 +235,7 @@ export function attachOnce(
202
235
  now: Date = new Date(),
203
236
  session: string | undefined = progressSession()
204
237
  ): boolean {
205
- if (node.artifacts.some((a) => a.kind === artifact.kind && a.ref === artifact.ref))
206
- return false;
238
+ if (node.artifacts.some((a) => sameArtifact(a, artifact))) return false;
207
239
  appendEvent(scope, node.id, "attach", artifact, file, now, session);
208
240
  return true;
209
241
  }
@@ -314,7 +346,7 @@ function applyToNode(tree: ScopeTree, node: WorkNode, event: WorkEvent): void {
314
346
  node.decisions.push({ ts: event.ts, text: event.text, why: event.why });
315
347
  break;
316
348
  case "attach":
317
- node.artifacts.push({
349
+ addArtifact(node, {
318
350
  ts: event.ts,
319
351
  kind: event.kind,
320
352
  ref: event.ref,