← All Examples Example 08 / 12 Cross-Harness Session Sensemaking & Promotion in Pi
Prompt-First Example 08 · Sessions & Pi CLI · @umwelten/pi · Explorations

Cross-Harness Sessions &
Knowledge Promotion

Install @umwelten/pi into Pi CLI to index Pi JSONL v3 trees, Pi Durable SQLite databases, Claude Code, and Cursor into unified Explorations — and promote durable rules into FACTS.md.

File: examples/pi-extension/demo.ts Recreate: pnpm tsx examples/pi-extension/demo.ts Packages: @umwelten/pi @umwelten/sessions @umwelten/habitat
01 — The Prompt You Give Pi
“Write a runnable demo showing how @umwelten/pi extends Pi: (1) open a SQLite-backed DurableHabitat and run a turn so a pi-durable conversation is persisted on disk, (2) run @umwelten/sessions initializeAdapters() + projectSessions() to discover that SQLite conversation alongside Pi JSONL / Claude Code / Cursor sessions as an Exploration without mutating foreign SQLite files, and (3) invoke umweltenPiExtension's umwelten_promote_knowledge tool to write a durable rule into FACTS.md.”
Paste directly into pi or your coding agent with @umwelten/* installed. 5 min walkthrough
02 — The Example That Gets Built

Live workspace source: examples/pi-extension/demo.ts

Read directly from disk at site-build time — byte-for-byte identical to the typechecked script in this repo.

TypeScript examples/pi-extension/demo.ts
pnpm tsx examples/pi-extension/demo.ts
1#!/usr/bin/env node
2/**
3 * `@umwelten/pi` Extension Demo — Cross-Harness Session Sensemaking & Promotion.
4 *
5 * Shows how `umweltenPiExtension` plugs into `@earendil-works/pi-coding-agent`
6 * (`pi install ./packages/pi`) to search sessions across Pi JSONL v3, Pi Durable
7 * SQLite, Claude Code, and Cursor, project Explorations, and promote distilled
8 * knowledge into `FACTS.md` / `AGENTS.md`.
9 *
10 * Run: pnpm tsx examples/pi-extension/demo.ts
11 */
12
13import { mkdtemp, readFile, rm } from "node:fs/promises";
14import { tmpdir } from "node:os";
15import { join } from "node:path";
16import { fauxAssistantMessage, fauxProvider, createModels } from "@earendil-works/pi-ai";
17import { umweltenPiExtension } from "@umwelten/pi";
18import { DurableHabitat } from "@umwelten/habitat";
19import { initializeAdapters, projectSessions } from "@umwelten/sessions";
20
21const workspace = await mkdtemp(join(tmpdir(), "umwelten-pi-demo-"));
22
23try {
24  // 1. Seed a durable Pi Durable SQLite conversation inside the project workspace
25  const faux = fauxProvider({ provider: "faux", models: [{ id: "demo-1" }] });
26  faux.setResponses([
27    fauxAssistantMessage("Always run `pnpm test:run` instead of watch-mode `pnpm test`."),
28  ]);
29  const models = createModels();
30  models.setProvider(faux.provider);
31
32  const habitat = await DurableHabitat.open({
33    id: "repo-assistant",
34    workDir: workspace,
35    models,
36    model: { provider: "faux", modelId: "demo-1" },
37  });
38  await habitat.ask("How should tests run in CI?");
39  await habitat.close();
40
41  // 2. Project discovered Source Sessions (including pi-durable SQLite) into Explorations
42  initializeAdapters();
43  const projected = await projectSessions(workspace);
44  console.log(
45    `Discovered ${projected.explorations.length} Exploration(s):`,
46    projected.explorations.map((e) => ({ id: e.id, name: e.name })),
47  );
48
49  // 3. Load `umweltenPiExtension` onto a mock Pi ExtensionAPI host and promote a fact
50  const tools = new Map<string, any>();
51  umweltenPiExtension({
52    registerTool: (t: any) => tools.set(t.name, t),
53    registerCommand: () => undefined,
54  } as any);
55
56  const promote = tools.get("umwelten_promote_knowledge");
57  await promote.execute(
58    "call-1",
59    {
60      target: "project-fact",
61      title: "CI test runner",
62      content: "Run `pnpm test:run` (never watch-mode `pnpm test`) in automation.",
63    },
64    undefined,
65    undefined,
66    { cwd: workspace },
67  );
68
69  console.log("\nPromoted FACTS.md:\n" + (await readFile(join(workspace, "FACTS.md"), "utf8")));
70} finally {
71  await rm(workspace, { recursive: true, force: true });
72}
03 — Captured Execution Telemetry

Captured stdout from running pnpm tsx examples/pi-extension/demo.ts

Captured Run Output pnpm tsx examples/pi-extension/demo.ts
Discovered 1 Exploration(s): [
  {
    id: 'exp-default-pi-durable:L3Zhci9mb2xkZXJzLzJmL19kdjVjc2pzMjgzMHJyc2Y2Z3hna3JfbTAwMDBnbi9UL3Vtd2VsdGVuLXBpLWRlbW8tNEswUEF1L2hhYml0YXQuc3FsaXRl:1',
    name: 'How should tests run in CI?'
  }
]

Promoted FACTS.md:
# Project Facts

*Declarative truths about this project.*

- Run `pnpm test:run` (never watch-mode `pnpm test`) in automation.
04 — How & Why This Extends Pi

Architectural notes

@umwelten/sessions correlates Pi CLI JSONL v3 trees, pi-durable SQLite journals, Claude Code, and Cursor into unified Explorations, while @umwelten/pi exposes search and knowledge promotion directly inside Pi.