paracosm 0.4.147 → 0.4.153
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/dist/src/runtime/agent-memory.d.ts +1 -1
- package/dist/src/runtime/agent-memory.d.ts.map +1 -1
- package/dist/src/runtime/agent-memory.js +4 -4
- package/dist/src/runtime/agent-memory.js.map +1 -1
- package/dist/src/runtime/agent-reactions.d.ts +7 -3
- package/dist/src/runtime/agent-reactions.d.ts.map +1 -1
- package/dist/src/runtime/agent-reactions.js +2 -2
- package/dist/src/runtime/agent-reactions.js.map +1 -1
- package/dist/src/runtime/commander-setup.d.ts +70 -0
- package/dist/src/runtime/commander-setup.d.ts.map +1 -0
- package/dist/src/runtime/commander-setup.js +116 -0
- package/dist/src/runtime/commander-setup.js.map +1 -0
- package/dist/src/runtime/orchestrator.d.ts.map +1 -1
- package/dist/src/runtime/orchestrator.js +52 -238
- package/dist/src/runtime/orchestrator.js.map +1 -1
- package/dist/src/runtime/output-writer.d.ts +35 -0
- package/dist/src/runtime/output-writer.d.ts.map +1 -0
- package/dist/src/runtime/output-writer.js +40 -0
- package/dist/src/runtime/output-writer.js.map +1 -0
- package/dist/src/runtime/reaction-step.d.ts +78 -0
- package/dist/src/runtime/reaction-step.d.ts.map +1 -0
- package/dist/src/runtime/reaction-step.js +168 -0
- package/dist/src/runtime/reaction-step.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run-output file writer.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from orchestrator.ts so the end-of-run side-effect (JSON
|
|
5
|
+
* snapshot to disk + summary log line) lives separately from the
|
|
6
|
+
* turn-loop coordinator. Pure function over its inputs; returns the
|
|
7
|
+
* absolute path it wrote to so the caller can log or surface it.
|
|
8
|
+
*
|
|
9
|
+
* @module paracosm/runtime/output-writer
|
|
10
|
+
*/
|
|
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));
|
|
15
|
+
/**
|
|
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.
|
|
19
|
+
*
|
|
20
|
+
* The tag slot comes from the leader's archetype so side-by-side runs
|
|
21
|
+
* get distinguishable filenames even when they start in the same
|
|
22
|
+
* millisecond (e.g. `v3-the-engineer-...` vs `v3-the-visionary-...`).
|
|
23
|
+
*/
|
|
24
|
+
export function writeRunOutput(output, args) {
|
|
25
|
+
const outDir = resolve(__dirname, '..', '..', 'output');
|
|
26
|
+
mkdirSync(outDir, { recursive: true });
|
|
27
|
+
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
28
|
+
const tag = args.leaderArchetype.toLowerCase().replace(/\s+/g, '-');
|
|
29
|
+
const path = resolve(outDir, `v3-${tag}-${ts}.json`);
|
|
30
|
+
writeFileSync(path, JSON.stringify(output, null, 2));
|
|
31
|
+
console.log(`\n${'═'.repeat(60)}`);
|
|
32
|
+
console.log(` COMPLETE — ${args.leaderName}`);
|
|
33
|
+
console.log(` Output: ${path}`);
|
|
34
|
+
console.log(` Turns: ${args.turns} | Citations: ${output.totalCitations} | Tools: ${output.totalToolsForged}`);
|
|
35
|
+
console.log(` Final: Pop ${output.finalState.colony.population} | Morale ${Math.round(output.finalState.colony.morale * 100)}%`);
|
|
36
|
+
console.log(` Registries: ${JSON.stringify(args.toolRegs)}`);
|
|
37
|
+
console.log(`${'═'.repeat(60)}\n`);
|
|
38
|
+
return path;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=output-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-writer.js","sourceRoot":"","sources":["../../../src/runtime/output-writer.ts"],"names":[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AM,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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn agent reaction pass.
|
|
3
|
+
*
|
|
4
|
+
* Pulls the colony's alive agents, picks an eligible subset (full roster
|
|
5
|
+
* on turn 1, ~30 most-relevant on turn 2+ via progressive reactions),
|
|
6
|
+
* fires a batched reaction call, writes the outputs into each agent's
|
|
7
|
+
* memory, computes an aggregate mood summary, and emits two SSE events:
|
|
8
|
+
* `agent_reactions` (detail list for the dashboard roster) and
|
|
9
|
+
* `bulletin` (4 short quotes for the ticker).
|
|
10
|
+
*
|
|
11
|
+
* Extracted from orchestrator.ts so the turn-loop coordinator reads as
|
|
12
|
+
* orchestration instead of a 110-line reaction/memory/bulletin block.
|
|
13
|
+
* All kernel mutations, SSE emits, and cost-tracker calls flow through
|
|
14
|
+
* callbacks supplied by the orchestrator.
|
|
15
|
+
*
|
|
16
|
+
* @module paracosm/runtime/reaction-step
|
|
17
|
+
*/
|
|
18
|
+
import { type AgentReaction } from './agent-reactions.js';
|
|
19
|
+
import { type SimulationExecutionConfig } from '../cli/sim-config.js';
|
|
20
|
+
import type { SimulationKernel } from '../engine/core/kernel.js';
|
|
21
|
+
import type { LlmProvider, ScenarioPackage, SimulationModelConfig } from '../engine/types.js';
|
|
22
|
+
import type { TurnOutcome } from '../engine/core/state.js';
|
|
23
|
+
import type { CallUsage } from './cost-tracker.js';
|
|
24
|
+
import type { SimEvent } from './orchestrator.js';
|
|
25
|
+
/**
|
|
26
|
+
* Context snapshot passed to generateAgentReactions so each agent's
|
|
27
|
+
* reaction is grounded in the turn's actual events, outcome, and
|
|
28
|
+
* aggregate colony state rather than just the latest event title.
|
|
29
|
+
*/
|
|
30
|
+
export interface ReactionContext {
|
|
31
|
+
eventTitle: string;
|
|
32
|
+
eventCategory: string;
|
|
33
|
+
outcome: TurnOutcome | null;
|
|
34
|
+
decision: string;
|
|
35
|
+
year: number;
|
|
36
|
+
turn: number;
|
|
37
|
+
colonyMorale: number;
|
|
38
|
+
colonyPopulation: number;
|
|
39
|
+
}
|
|
40
|
+
export interface RunReactionStepArgs {
|
|
41
|
+
kernel: SimulationKernel;
|
|
42
|
+
scenario: ScenarioPackage;
|
|
43
|
+
turn: number;
|
|
44
|
+
year: number;
|
|
45
|
+
seed: number;
|
|
46
|
+
turnEvents: Array<{
|
|
47
|
+
relevantDepartments?: string[];
|
|
48
|
+
}>;
|
|
49
|
+
turnEventTitles: string[];
|
|
50
|
+
lastEventCategory: string;
|
|
51
|
+
lastOutcome: TurnOutcome | null;
|
|
52
|
+
provider: LlmProvider;
|
|
53
|
+
modelConfig: SimulationModelConfig;
|
|
54
|
+
execution?: Partial<SimulationExecutionConfig>;
|
|
55
|
+
trackUsage: (result: {
|
|
56
|
+
usage?: CallUsage;
|
|
57
|
+
}, site?: 'reactions') => void;
|
|
58
|
+
reportProviderError: (err: unknown, site: string) => void;
|
|
59
|
+
emit: (type: SimEvent['type'], data?: Record<string, unknown>) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface ReactionStepResult {
|
|
62
|
+
/** Full reaction list produced this turn. Empty when generation failed. */
|
|
63
|
+
reactions: AgentReaction[];
|
|
64
|
+
/** Human-readable mood summary to surface in the next turn's UI header. */
|
|
65
|
+
moodSummary: string | null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run the full reaction step for the current turn and return the
|
|
69
|
+
* reactions + an aggregate mood summary. Side effects: memory writes
|
|
70
|
+
* into every reacting agent, relationship-sentiment updates across the
|
|
71
|
+
* roster, and two SSE emits (`agent_reactions`, `bulletin`).
|
|
72
|
+
*
|
|
73
|
+
* Returning the reactions array lets the turn-loop caller append into
|
|
74
|
+
* allAgentReactions and fold the mood summary into the next
|
|
75
|
+
* DirectorContext.
|
|
76
|
+
*/
|
|
77
|
+
export declare function runReactionStep(args: RunReactionStepArgs): Promise<ReactionStepResult>;
|
|
78
|
+
//# sourceMappingURL=reaction-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reaction-step.d.ts","sourceRoot":"","sources":["../../../src/runtime/reaction-step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAOlF,OAAO,EAAqB,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,I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
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn agent reaction pass.
|
|
3
|
+
*
|
|
4
|
+
* Pulls the colony's alive agents, picks an eligible subset (full roster
|
|
5
|
+
* on turn 1, ~30 most-relevant on turn 2+ via progressive reactions),
|
|
6
|
+
* fires a batched reaction call, writes the outputs into each agent's
|
|
7
|
+
* memory, computes an aggregate mood summary, and emits two SSE events:
|
|
8
|
+
* `agent_reactions` (detail list for the dashboard roster) and
|
|
9
|
+
* `bulletin` (4 short quotes for the ticker).
|
|
10
|
+
*
|
|
11
|
+
* Extracted from orchestrator.ts so the turn-loop coordinator reads as
|
|
12
|
+
* orchestration instead of a 110-line reaction/memory/bulletin block.
|
|
13
|
+
* All kernel mutations, SSE emits, and cost-tracker calls flow through
|
|
14
|
+
* callbacks supplied by the orchestrator.
|
|
15
|
+
*
|
|
16
|
+
* @module paracosm/runtime/reaction-step
|
|
17
|
+
*/
|
|
18
|
+
import { generateAgentReactions } from './agent-reactions.js';
|
|
19
|
+
import { recordReactionMemory, consolidateMemory, updateRelationshipsFromReactions, } from './agent-memory.js';
|
|
20
|
+
import { SeededRng } from '../engine/core/rng.js';
|
|
21
|
+
import { DEFAULT_EXECUTION } from '../cli/sim-config.js';
|
|
22
|
+
/**
|
|
23
|
+
* Run the full reaction step for the current turn and return the
|
|
24
|
+
* reactions + an aggregate mood summary. Side effects: memory writes
|
|
25
|
+
* into every reacting agent, relationship-sentiment updates across the
|
|
26
|
+
* roster, and two SSE emits (`agent_reactions`, `bulletin`).
|
|
27
|
+
*
|
|
28
|
+
* Returning the reactions array lets the turn-loop caller append into
|
|
29
|
+
* allAgentReactions and fold the mood summary into the next
|
|
30
|
+
* DirectorContext.
|
|
31
|
+
*/
|
|
32
|
+
export async function runReactionStep(args) {
|
|
33
|
+
const { kernel, scenario, turn, year, seed, turnEvents, turnEventTitles, lastEventCategory, lastOutcome, provider, modelConfig, execution, trackUsage, reportProviderError, emit, } = args;
|
|
34
|
+
const reactionCtx = {
|
|
35
|
+
eventTitle: turnEventTitles.join(' / '),
|
|
36
|
+
eventCategory: turnEvents.map(e => e.category || '').filter(Boolean).join(', '),
|
|
37
|
+
outcome: lastOutcome,
|
|
38
|
+
decision: turnEventTitles.join('. '),
|
|
39
|
+
year, turn,
|
|
40
|
+
colonyMorale: kernel.getState().colony.morale,
|
|
41
|
+
colonyPopulation: kernel.getState().colony.population,
|
|
42
|
+
};
|
|
43
|
+
// Progressive reactions: turn 1 always runs the full colony so
|
|
44
|
+
// baseline personalities + memories get established. Turns 2+ pick
|
|
45
|
+
// only agents who materially experienced this turn's events
|
|
46
|
+
// (featured + promoted heads + anyone in a relevantDepartments for
|
|
47
|
+
// the turn), capped at ~30. This cuts ~70% of reaction calls after
|
|
48
|
+
// turn 1 with minor memory-sparsity tradeoff.
|
|
49
|
+
const progressiveReactions = execution?.progressiveReactions ?? DEFAULT_EXECUTION.progressiveReactions;
|
|
50
|
+
const reactionBatchSize = execution?.reactionBatchSize ?? DEFAULT_EXECUTION.reactionBatchSize;
|
|
51
|
+
const allAlive = kernel.getState().agents.filter(a => a.health.alive);
|
|
52
|
+
const eligibleAgents = (() => {
|
|
53
|
+
if (!progressiveReactions || turn === 1)
|
|
54
|
+
return allAlive;
|
|
55
|
+
const relevantDepts = new Set();
|
|
56
|
+
for (const ev of turnEvents) {
|
|
57
|
+
for (const d of ev.relevantDepartments || [])
|
|
58
|
+
relevantDepts.add(String(d));
|
|
59
|
+
}
|
|
60
|
+
const picked = new Map();
|
|
61
|
+
const add = (a) => { if (!picked.has(a.core.id))
|
|
62
|
+
picked.set(a.core.id, a); };
|
|
63
|
+
// Featured: always react. These are the colonists users see in
|
|
64
|
+
// the bulletin and care about narratively.
|
|
65
|
+
for (const a of allAlive)
|
|
66
|
+
if (a.narrative.featured)
|
|
67
|
+
add(a);
|
|
68
|
+
// Promoted department heads: always react. They shape next turn's
|
|
69
|
+
// analysis so their psych state matters.
|
|
70
|
+
for (const a of allAlive)
|
|
71
|
+
if (a.promotion)
|
|
72
|
+
add(a);
|
|
73
|
+
// Department-affected agents: up to 6 per relevant dept, priority
|
|
74
|
+
// by absolute deviation from neutral psych (dramatic reactors
|
|
75
|
+
// first) so the bulletin stays textured with in-crisis voices.
|
|
76
|
+
for (const dept of relevantDepts) {
|
|
77
|
+
const candidates = allAlive
|
|
78
|
+
.filter(a => a.core.department === dept && !picked.has(a.core.id))
|
|
79
|
+
.sort((a, b) => Math.abs(b.health.psychScore - 0.5) - Math.abs(a.health.psychScore - 0.5))
|
|
80
|
+
.slice(0, 6);
|
|
81
|
+
for (const a of candidates)
|
|
82
|
+
add(a);
|
|
83
|
+
}
|
|
84
|
+
// Hard cap so a scenario with many relevant departments can't
|
|
85
|
+
// blow past budget by accident.
|
|
86
|
+
return Array.from(picked.values()).slice(0, 30);
|
|
87
|
+
})();
|
|
88
|
+
if (progressiveReactions && turn > 1) {
|
|
89
|
+
console.log(` [agents] Progressive: ${eligibleAgents.length}/${allAlive.length} react this turn`);
|
|
90
|
+
}
|
|
91
|
+
let reactions = [];
|
|
92
|
+
try {
|
|
93
|
+
reactions = await generateAgentReactions(eligibleAgents, reactionCtx, {
|
|
94
|
+
provider,
|
|
95
|
+
model: modelConfig.agentReactions || 'gpt-4o-mini',
|
|
96
|
+
maxConcurrent: 25,
|
|
97
|
+
reactionContextHook: scenario.hooks.reactionContextHook,
|
|
98
|
+
batchSize: reactionBatchSize,
|
|
99
|
+
onUsage: (result) => trackUsage(result, 'reactions'),
|
|
100
|
+
onProviderError: (err) => reportProviderError(err, 'reactions'),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.log(` [agents] Reaction generation failed: ${err}`);
|
|
105
|
+
}
|
|
106
|
+
if (reactions.length === 0)
|
|
107
|
+
return { reactions, moodSummary: null };
|
|
108
|
+
const agentMap = new Map(kernel.getState().agents.map(c => [c.core.id, c]));
|
|
109
|
+
emit('agent_reactions', {
|
|
110
|
+
turn, year,
|
|
111
|
+
reactions: reactions.slice(0, 8).map(r => {
|
|
112
|
+
const agent = agentMap.get(r.agentId);
|
|
113
|
+
const mem = agent?.memory;
|
|
114
|
+
return {
|
|
115
|
+
name: r.name, age: r.age, department: r.department, role: r.role,
|
|
116
|
+
specialization: r.specialization, marsborn: r.marsborn,
|
|
117
|
+
quote: r.quote, mood: r.mood, intensity: r.intensity,
|
|
118
|
+
hexaco: r.hexaco, psychScore: r.psychScore, boneDensity: r.boneDensity, radiation: r.radiation,
|
|
119
|
+
agentId: r.agentId,
|
|
120
|
+
memory: mem ? {
|
|
121
|
+
recentMemories: mem.shortTerm.slice(-3).map(m => ({ year: m.year, content: m.content, valence: m.valence })),
|
|
122
|
+
beliefs: mem.longTerm.slice(-3),
|
|
123
|
+
stances: Object.entries(mem.stances).filter(([, v]) => Math.abs(v) > 0.2).map(([k, v]) => ({ topic: k, value: v })),
|
|
124
|
+
relationships: Object.entries(mem.relationships).filter(([, v]) => Math.abs(v) > 0.2).sort((a, b) => Math.abs(b[1]) - Math.abs(a[1])).slice(0, 3).map(([id, v]) => ({ name: agentMap.get(id)?.core.name || id, sentiment: v })),
|
|
125
|
+
} : null,
|
|
126
|
+
};
|
|
127
|
+
}),
|
|
128
|
+
totalReactions: reactions.length,
|
|
129
|
+
});
|
|
130
|
+
// Memory + relationship updates for every reactor, then consolidate
|
|
131
|
+
// the shortTerm/longTerm split for the whole alive roster (even
|
|
132
|
+
// non-reactors drift; they just don't have a fresh personal reaction
|
|
133
|
+
// memory this turn).
|
|
134
|
+
// recordReactionMemory takes `outcome: string` (not nullable) so coerce
|
|
135
|
+
// the TurnOutcome|null into a stable placeholder when the turn ended
|
|
136
|
+
// before the outcome roll (e.g. director batch produced zero events).
|
|
137
|
+
const outcomeLabel = lastOutcome ?? 'unknown';
|
|
138
|
+
for (const r of reactions) {
|
|
139
|
+
const c = agentMap.get(r.agentId);
|
|
140
|
+
if (c)
|
|
141
|
+
recordReactionMemory(c, r, turnEventTitles.join(' / '), lastEventCategory, outcomeLabel, turn, year);
|
|
142
|
+
}
|
|
143
|
+
updateRelationshipsFromReactions(kernel.getState().agents, reactions);
|
|
144
|
+
for (const c of kernel.getState().agents)
|
|
145
|
+
if (c.health.alive)
|
|
146
|
+
consolidateMemory(c);
|
|
147
|
+
const moodCounts = {};
|
|
148
|
+
for (const r of reactions)
|
|
149
|
+
moodCounts[r.mood] = (moodCounts[r.mood] || 0) + 1;
|
|
150
|
+
const moodParts = Object.entries(moodCounts)
|
|
151
|
+
.sort((a, b) => b[1] - a[1])
|
|
152
|
+
.map(([m, c]) => `${Math.round(c / reactions.length * 100)}% ${m}`);
|
|
153
|
+
const moodSummary = `${reactions.length} colonists: ${moodParts.join(', ')}`;
|
|
154
|
+
// Bulletin: 4 quotes sampled via a seeded RNG so the same run always
|
|
155
|
+
// produces the same bulletin on replay. Turn-offset so turn N doesn't
|
|
156
|
+
// repeat turn N+1's sample.
|
|
157
|
+
const bulletinRng = new SeededRng(seed).turnSeed(turn + 3000);
|
|
158
|
+
const bulletinPosts = reactions.slice(0, 4).map(r => ({
|
|
159
|
+
name: r.name, department: r.department, role: r.role, marsborn: r.marsborn, age: r.age,
|
|
160
|
+
post: r.quote.length > 140 ? r.quote.slice(0, 137) + '...' : r.quote,
|
|
161
|
+
mood: r.mood, intensity: r.intensity,
|
|
162
|
+
likes: Math.floor(r.intensity * 20 + bulletinRng.next() * 10),
|
|
163
|
+
replies: Math.floor(r.intensity * 5 + bulletinRng.next() * 3),
|
|
164
|
+
}));
|
|
165
|
+
emit('bulletin', { turn, year, posts: bulletinPosts });
|
|
166
|
+
return { reactions, moodSummary };
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=reaction-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reaction-step.js","sourceRoot":"","sources":["../../../src/runtime/reaction-step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,sBAAsB,EAAsB,MAAM,sBAAsB,CAA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AAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KAC9D,CAAC,CAAC,CAAC;IACJ,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IAEvD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paracosm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.153",
|
|
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",
|