acp-kernel 0.0.29 → 0.0.31

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.
@@ -32,6 +32,7 @@ export interface ResolvedRange {
32
32
  nestedBlockIds: string[];
33
33
  boundaryKind: BoundaryKind;
34
34
  protectedGaps: number[];
35
+ snappedBoundaries: string[];
35
36
  }
36
37
  export declare function resolveBoundaries(input: ResolveBoundariesInput): ResolvedRange;
37
38
  export declare function earliestIndexOfIds(ids: string[], indexByRawId: Map<string, number>): number | null;
@@ -1 +1 @@
1
- {"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAehE;AAED;;;;;;GAMG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,wBAAwB;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,CAAC;gBAGjC,IAAI,EAAE,SAAS,GAAG,UAAU,EAC5B,QAAQ,EAAE,OAAO,GAAG,KAAK,EACzB,OAAO,EAAE,MAAM;CAQlB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,MA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MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IACJ,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnC;AA2BD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAyR7D;AAqxBD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -442,8 +442,13 @@ function resolveBoundaries(input) {
442
442
  input.messages.forEach(
443
443
  (message, index) => indexByRawId.set(message.id, index)
444
444
  );
445
- let startIndex = resolveAnchorIndex(start, input.state, indexByRawId, "start");
446
- let endIndex = resolveAnchorIndex(end, input.state, indexByRawId, "end");
445
+ let snappedBoundaries = [];
446
+ const startAnchor = resolveAnchorIndex(start, input.state, indexByRawId, "start");
447
+ if (startAnchor.snapped) snappedBoundaries.push(startAnchor.snapped);
448
+ const endAnchor = resolveAnchorIndex(end, input.state, indexByRawId, "end");
449
+ if (endAnchor.snapped) snappedBoundaries.push(endAnchor.snapped);
450
+ let startIndex = startAnchor.index;
451
+ let endIndex = endAnchor.index;
447
452
  if (startIndex > endIndex) {
448
453
  [startIndex, endIndex] = [endIndex, startIndex];
449
454
  }
@@ -471,7 +476,8 @@ function resolveBoundaries(input) {
471
476
  messageIds,
472
477
  nestedBlockIds,
473
478
  boundaryKind,
474
- protectedGaps
479
+ protectedGaps,
480
+ snappedBoundaries
475
481
  };
476
482
  }
477
483
  function resolveAnchorIndex(boundary, state, indexByRawId, endpoint) {
@@ -486,14 +492,21 @@ function resolveAnchorIndex(boundary, state, indexByRawId, endpoint) {
486
492
  );
487
493
  }
488
494
  const index = indexByRawId.get(rawId);
489
- if (index === void 0) {
490
- throw new BoundaryNotFoundError(
491
- "consumed",
492
- endpoint,
493
- `${label}="${boundary.raw}" not found in visible context (likely consumed by an existing block).`
494
- );
495
+ if (index !== void 0) {
496
+ return { index, snapped: null };
495
497
  }
496
- return index;
498
+ const owner2 = activeOwnerAnchor(state, [rawId], indexByRawId);
499
+ if (owner2 !== null) {
500
+ return {
501
+ index: owner2,
502
+ snapped: `${label}="${boundary.raw}" refers to a message already compressed into an active block \u2014 anchored to that block's summary instead.`
503
+ };
504
+ }
505
+ throw new BoundaryNotFoundError(
506
+ "consumed",
507
+ endpoint,
508
+ `${label}="${boundary.raw}" not found in visible context (likely consumed by an existing block).`
509
+ );
497
510
  }
498
511
  const block = blockById(state, `b${boundary.numericId}`);
499
512
  if (!block) {
@@ -503,6 +516,19 @@ function resolveAnchorIndex(boundary, state, indexByRawId, endpoint) {
503
516
  `${label}="b${boundary.numericId}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
504
517
  );
505
518
  }
519
+ if (block.active) {
520
+ const anchor = earliestIndexOfIds(block.effectiveMessageIds, indexByRawId);
521
+ if (anchor !== null) {
522
+ return { index: anchor, snapped: null };
523
+ }
524
+ }
525
+ const owner = activeOwnerAnchor(state, block.effectiveMessageIds, indexByRawId);
526
+ if (owner !== null) {
527
+ return {
528
+ index: owner,
529
+ snapped: `${label}="b${boundary.numericId}" was consumed by a higher-tier block \u2014 anchored to the active block covering its content instead.`
530
+ };
531
+ }
506
532
  if (!block.active) {
507
533
  throw new BoundaryNotFoundError(
508
534
  "consumed",
@@ -510,15 +536,26 @@ function resolveAnchorIndex(boundary, state, indexByRawId, endpoint) {
510
536
  `${label}="b${boundary.numericId}" not found in visible context (block distilled/consumed by a higher-tier block).`
511
537
  );
512
538
  }
513
- const anchor = earliestIndexOfIds(block.effectiveMessageIds, indexByRawId);
514
- if (anchor === null) {
515
- throw new BoundaryNotFoundError(
516
- "consumed",
517
- endpoint,
518
- `${label}="b${boundary.numericId}" not found in visible context (block messages consumed by a higher-tier block).`
519
- );
539
+ throw new BoundaryNotFoundError(
540
+ "consumed",
541
+ endpoint,
542
+ `${label}="b${boundary.numericId}" not found in visible context (block messages consumed by a higher-tier block).`
543
+ );
544
+ }
545
+ function activeOwnerAnchor(state, ownedIds, indexByRawId) {
546
+ if (ownedIds.length === 0) return null;
547
+ const owned = new Set(ownedIds);
548
+ let best = null;
549
+ for (const block of state.blocks) {
550
+ if (!block.active) continue;
551
+ const anchor = earliestIndexOfIds(block.effectiveMessageIds, indexByRawId);
552
+ if (anchor === null) continue;
553
+ const ownsContent = block.effectiveMessageIds.some((id) => owned.has(id));
554
+ if (ownsContent && (best === null || anchor < best)) {
555
+ best = anchor;
556
+ }
520
557
  }
521
- return anchor;
558
+ return best;
522
559
  }
523
560
  function formatPaddedRef(index) {
524
561
  return `m${String(index).padStart(5, "0")}`;
@@ -1185,6 +1222,10 @@ function runPipeline(nodes, initial, ctx) {
1185
1222
  function rangeError(spec, message) {
1186
1223
  return `range ${spec.startRef}..${spec.endRef}: ${message}`;
1187
1224
  }
1225
+ function numericBlockId(id) {
1226
+ const parsed = /^b(\d+)$/.exec(id);
1227
+ return parsed ? Number(parsed[1]) : 0;
1228
+ }
1188
1229
  function createCore(ports = {}) {
1189
1230
  const countTokens = ports.countTokens ?? defaultCountTokens;
1190
1231
  function applyCompression(input) {
@@ -1230,6 +1271,12 @@ function createCore(ports = {}) {
1230
1271
  }
1231
1272
  }
1232
1273
  }
1274
+ let resolvableCount = 0;
1275
+ let unknownCount = 0;
1276
+ for (const resolution of classifications.values()) {
1277
+ if (resolution.status === "ok") resolvableCount++;
1278
+ else if (resolution.status === "unknown") unknownCount++;
1279
+ }
1233
1280
  const rangeIndexSets = [];
1234
1281
  for (const [spec, resolution] of classifications) {
1235
1282
  if (resolution.status !== "ok") continue;
@@ -1274,7 +1321,9 @@ function createCore(ports = {}) {
1274
1321
  }
1275
1322
  }
1276
1323
  if (!hasBlockBoundaryRange && totalRangeChars < input.config.compress.minCompressRange) {
1277
- const gateMessage = consumedRanges.length > 0 ? `Requested range(s) already compressed (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}); remaining compressible content ${totalRangeChars} chars < min ${input.config.compress.minCompressRange}. Nothing to do \u2014 run acp_status to see current compressible ranges.` : `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`;
1324
+ const live = activeBlocks(state).map((b) => b.blockId).sort((x, y) => numericBlockId(x) - numericBlockId(y));
1325
+ const liveHint = live.length > 0 ? ` Current active blocks span ${live[0]}..${live[live.length - 1]} \u2014 retry with startId/endId set to active block IDs in that span.` : "";
1326
+ const gateMessage = resolvableCount === 0 && consumedRanges.length === 0 && unknownCount > 0 ? `None of the ${input.ranges.length} requested range(s) resolved \u2014 every ref failed with "does not exist in this session". Refs recorded before an earlier compress are stale: each successful compress renumbers the remaining refs. Run acp_status, then re-issue the compress in the same turn using only the refs it reports.` : consumedRanges.length > 0 ? `Requested range(s) already compressed (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}); remaining compressible content ${totalRangeChars} chars < min ${input.config.compress.minCompressRange}. Nothing to do.${liveHint}` : `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`;
1278
1327
  return {
1279
1328
  state: input.state,
1280
1329
  result: {
@@ -1300,6 +1349,7 @@ function createCore(ports = {}) {
1300
1349
  errors.push(rangeError(spec, resolution.error.message));
1301
1350
  continue;
1302
1351
  }
1352
+ warnings.push(...resolution.resolved.snappedBoundaries);
1303
1353
  try {
1304
1354
  const outcome = applySingleRange({
1305
1355
  spec,