Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

docs: make topHeadlines' comment match its code, and pin it (#372)

Brenno Ferrari76c0357cdf39
diff --git a/.claude/scripts/lib/session-start.ts b/.claude/scripts/lib/session-start.ts
index 1771680..1fd5fc8 100644
--- a/.claude/scripts/lib/session-start.ts
+++ b/.claude/scripts/lib/session-start.ts
@@ -1055,8 +1055,10 @@ export function renderHeadlines(headlines: readonly string[]): string {
/**
* The first N headlines that `fits` accepts, with a line saying how many
- * more there are. Null when not even one fits, or when all of them do (that
- * is the `headlines` level, not this one).
+ * more there are. The body always names at least one goal it left out, so N
+ * stays below the count even when all would fit (the whole list is the
+ * `headlines` level). Null when not even one fits, or when there is only one
+ * headline.
*/
export function topHeadlines(headlines: readonly string[], fits: (body: string) => boolean): string | null {
for (let n = headlines.length - 1; n >= 1; n--) {
diff --git a/.claude/scripts/tests/budget-ladder.test.ts b/.claude/scripts/tests/budget-ladder.test.ts
index 5258e96..171cbc0 100644
--- a/.claude/scripts/tests/budget-ladder.test.ts
+++ b/.claude/scripts/tests/budget-ladder.test.ts
@@ -235,14 +235,18 @@ describe("northStarLadder", () => {
describe("topHeadlines", () => {
const heads = ["one", "two", "three"];
+ const two = `${renderHeadlines(["one", "two"])}\n_(+1 more goals in brain/North Star.md)_`;
test("the first N that fit, and how many more", () => {
- const two = `${renderHeadlines(["one", "two"])}\n_(+1 more goals in brain/North Star.md)_`;
assert.equal(topHeadlines(heads, (b) => bytes(b) <= bytes(two)), two);
assert.equal(topHeadlines(heads, (b) => bytes(b) <= bytes(two) - 1), `${renderHeadlines(["one"])}\n_(+2 more goals in brain/North Star.md)_`);
});
test("null when not one fits", () => {
assert.equal(topHeadlines(heads, (b) => bytes(b) <= 5), null);
});
+ test("one short of all, even when every headline fits (#371)", () => {
+ assert.equal(topHeadlines(heads, () => true), two);
+ assert.equal(topHeadlines(["only"], () => true), null);
+ });
});
describe("session-start — #304's fixture on the hook path", () => {