paracosm 0.4.377 → 0.4.378

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/README.md CHANGED
@@ -160,7 +160,18 @@ const results = await Promise.all(
160
160
  scenario,
161
161
  maxTurns: 8,
162
162
  seed: 42,
163
- onEvent(e) { console.log(leader.name, e.type, e.data?.title); },
163
+ // ~15 event types fire per turn (dept_start, forge_attempt, drift…).
164
+ // Filter to the ones that tell the story end-to-end so the console
165
+ // stays readable. See the SimEvent type for the full list.
166
+ onEvent(e) {
167
+ const turn = e.turn ?? (e.data?.turn as number | undefined);
168
+ if (e.type === 'event_start')
169
+ console.log(leader.name, `T${turn}`, 'event:', e.data?.title);
170
+ else if (e.type === 'outcome')
171
+ console.log(leader.name, `T${turn}`, e.data?.outcome, `(${e.data?.category})`);
172
+ else if (e.type === 'turn_done')
173
+ console.log(leader.name, `T${turn}`, 'complete');
174
+ },
164
175
  })
165
176
  )
166
177
  );
@@ -374,6 +385,18 @@ try {
374
385
 
375
386
  The resolver inspects `process.env` once up front, so a missing key fails loudly at the top of the run instead of retrying silently on every LLM call.
376
387
 
388
+ ### Where run output lands
389
+
390
+ Every finished run writes a JSON snapshot to `<cwd>/output/v3-<archetype>-<timestamp>.json` — the same payload `runSimulation` returns, persisted so you can diff runs, reload them into the dashboard, or feed them into downstream tooling. Set `PARACOSM_OUTPUT_DIR` to redirect (absolute path, or relative to cwd). The directory is created on first write if it doesn't exist.
391
+
392
+ ```bash
393
+ # Default: ./output/v3-the-pragmatist-2026-04-21T16-02-41-550Z.json
394
+ bun src/index.ts
395
+
396
+ # Custom location
397
+ PARACOSM_OUTPUT_DIR=./artifacts/run-001 bun src/index.ts
398
+ ```
399
+
377
400
  ## Seed Enrichment & Citation Flow
378
401
 
379
402
  Pass real-world source material into the compiler and Paracosm grounds the scenario in citations that flow all the way through to department reports.
@@ -9,9 +9,10 @@
9
9
  * @module paracosm/runtime/output-writer
10
10
  */
11
11
  /**
12
- * Write a simulation result payload to `<repo>/output/v3-<tag>-<ts>.json`
13
- * and log a one-screen summary to stdout. Ensures the output dir exists
14
- * before writing. Returns the absolute path of the written file.
12
+ * Write a simulation result payload to `<cwd>/output/v3-<tag>-<ts>.json`
13
+ * (or `$PARACOSM_OUTPUT_DIR/...`) and log a one-screen summary to stdout.
14
+ * Ensures the output dir exists before writing. Returns the absolute
15
+ * path of the written file.
15
16
  *
16
17
  * The tag slot comes from the leader's archetype so side-by-side runs
17
18
  * get distinguishable filenames even when they start in the same
@@ -1 +1 @@
1
- {"version":3,"file":"output-writer.d.ts","sourceRoot":"","sources":["../../src/runtime/output-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE;IACN,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE;QAAE,MAAM,EAAE;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAChE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3B,IAAI,EAAE;IACJ,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACpC,GACA,MAAM,CAiBR"}
1
+ {"version":3,"file":"output-writer.d.ts","sourceRoot":"","sources":["../../src/runtime/output-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkCH;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE;IACN,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE;QAAE,MAAM,EAAE;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAChE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3B,IAAI,EAAE;IACJ,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACpC,GACA,MAAM,CAiBR"}
@@ -9,20 +9,47 @@
9
9
  * @module paracosm/runtime/output-writer
10
10
  */
11
11
  import { mkdirSync, writeFileSync } from 'node:fs';
12
- import { resolve, dirname } from 'node:path';
13
- import { fileURLToPath } from 'node:url';
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ import { resolve } from 'node:path';
15
13
  /**
16
- * Write a simulation result payload to `<repo>/output/v3-<tag>-<ts>.json`
17
- * and log a one-screen summary to stdout. Ensures the output dir exists
18
- * before writing. Returns the absolute path of the written file.
14
+ * Resolve the output directory to write run snapshots into.
15
+ *
16
+ * Priority order:
17
+ * 1. `PARACOSM_OUTPUT_DIR` env var — absolute or cwd-relative, lets
18
+ * hosting / CI write outside the project tree without a code change.
19
+ * 2. `<cwd>/output` — the user's current working directory when they
20
+ * invoked the process. This is the right default both for the
21
+ * in-repo CLI (`npm run smoke` from the paracosm repo root writes
22
+ * to `<repo>/output`) AND for library consumers (`bun src/index.ts`
23
+ * from their project root writes to `<their project>/output`).
24
+ *
25
+ * The previous default resolved `output/` relative to the installed
26
+ * module location (`__dirname/../..`). That landed inside the package
27
+ * install directory — fine during local development of paracosm itself,
28
+ * but on any downstream consumer it wrote to
29
+ * `node_modules/paracosm/output/` (or worse, a pnpm virtual-store path
30
+ * like `node_modules/.pnpm/paracosm@x.y.z_hash/node_modules/paracosm/output/`),
31
+ * which is impossible to find, invisible to git, and gets nuked on
32
+ * `rm -rf node_modules`.
33
+ */
34
+ function resolveOutputDir() {
35
+ const override = process.env.PARACOSM_OUTPUT_DIR;
36
+ if (override && override.trim().length > 0) {
37
+ return resolve(process.cwd(), override);
38
+ }
39
+ return resolve(process.cwd(), 'output');
40
+ }
41
+ /**
42
+ * Write a simulation result payload to `<cwd>/output/v3-<tag>-<ts>.json`
43
+ * (or `$PARACOSM_OUTPUT_DIR/...`) and log a one-screen summary to stdout.
44
+ * Ensures the output dir exists before writing. Returns the absolute
45
+ * path of the written file.
19
46
  *
20
47
  * The tag slot comes from the leader's archetype so side-by-side runs
21
48
  * get distinguishable filenames even when they start in the same
22
49
  * millisecond (e.g. `v3-the-engineer-...` vs `v3-the-visionary-...`).
23
50
  */
24
51
  export function writeRunOutput(output, args) {
25
- const outDir = resolve(__dirname, '..', '..', 'output');
52
+ const outDir = resolveOutputDir();
26
53
  mkdirSync(outDir, { recursive: true });
27
54
  const ts = new Date().toISOString().replace(/[:.]/g, '-');
28
55
  const tag = args.leaderArchetype.toLowerCase().replace(/\s+/g, '-');
@@ -1 +1 @@
1
- {"version":3,"file":"output-writer.js","sourceRoot":"","sources":["../../src/runtime/output-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,MAI2B,EAC3B,IAKC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACxD,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CA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AU,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,KAAK,iBAAiB,MAAM,CAAC,cAAc,aAAa,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAChH,OAAO,CAAC,GAAG,CAAC,gBAAgB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,aAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAClI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paracosm",
3
- "version": "0.4.377",
3
+ "version": "0.4.378",
4
4
  "description": "AI agent swarm simulation engine with emergent crises, runtime tool forging, HEXACO personality drift, and deterministic kernels. Built on AgentOS.",
5
5
  "type": "module",
6
6
  "main": "dist/engine/index.js",