trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
183 lines (160 loc) • 5.27 kB
JavaScript
import {
inferProjectContext,
init_infer,
init_profile,
init_write,
loadProfile
} from "./chunk-O56VT7VP.js";
// src/scaffold/seed.ts
init_profile();
init_infer();
import { existsSync, writeFileSync } from "fs";
import { join } from "path";
async function seedContext(opts) {
const { rootPath, ide = "none", force = false } = opts;
const filesUpdated = [];
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
const profile = loadProfile();
const context = await inferProjectContext(rootPath);
const agentsDir = join(rootPath, ".trellis", "agents");
if (existsSync(agentsDir)) {
const agentsMdPath = join(agentsDir, "AGENTS.md");
if (existsSync(agentsMdPath) || force) {
const content = renderSeedAgentsMd(profile, context, timestamp);
writeFileSync(agentsMdPath, content, "utf-8");
filesUpdated.push(".trellis/agents/AGENTS.md");
}
const agentContextPath = join(agentsDir, "agent-context.json");
if (existsSync(agentContextPath) || force) {
const config = {
domain: context.domain,
ecosystem: context.ecosystem,
tools: [],
ontologies: [],
generatedAt: timestamp,
confidence: context.confidence,
lastSeed: timestamp
};
writeFileSync(agentContextPath, JSON.stringify(config, null, 2), "utf-8");
filesUpdated.push(".trellis/agents/agent-context.json");
}
}
switch (ide) {
case "cursor": {
const cursorRulesPath = join(rootPath, ".cursor", "rules.md");
if (existsSync(cursorRulesPath) || force) {
const content = renderSeedIdeRules(
profile,
context,
"cursor",
timestamp
);
writeFileSync(cursorRulesPath, content, "utf-8");
filesUpdated.push(".cursor/rules.md");
}
break;
}
case "devin": {
const devinRulesPath = join(rootPath, ".devin", "rules.md");
if (existsSync(devinRulesPath) || force) {
const content = renderSeedIdeRules(
profile,
context,
"devin",
timestamp
);
writeFileSync(devinRulesPath, content, "utf-8");
filesUpdated.push(".devin/rules.md");
}
break;
}
case "claude": {
const claudeSettingsPath = join(rootPath, ".claude", "settings.md");
if (existsSync(claudeSettingsPath) || force) {
const content = renderSeedIdeRules(
profile,
context,
"claude",
timestamp
);
writeFileSync(claudeSettingsPath, content, "utf-8");
filesUpdated.push(".claude/settings.md");
}
break;
}
case "none":
break;
}
return {
success: true,
filesUpdated,
timestamp
};
}
function renderSeedAgentsMd(profile, context, timestamp) {
const userName = profile?.name ?? "the user";
const userBio = profile?.bio ?? "(not provided)";
const userSkills = profile?.skills?.length ? profile.skills.join(", ") : "(not specified)";
return `
> This file was seeded by \`trellis seed\` on ${timestamp}
> Inference confidence: **${context.confidence}**
---
| Field | Value |
|-------|-------|
| **Name** | ${userName} |
| **Bio** | ${userBio} |
| **Skills** | ${userSkills} |
---
| Field | Value |
|-------|-------|
| **Name** | ${context.name ?? "(unnamed)"} |
| **Domain** | ${context.domain ?? "(not determined)"} |
| **Description** | ${context.description ?? "(no description found)"} |
| **Ecosystem** | ${context.ecosystem ?? "unknown"} |
| **File count** | ~${context.fileCount} |
---
You are operating in a Trellis-tracked repository. Follow these guidelines:
1. **Read \`agent-context.json\`** in this directory for registered tools, ontologies, and domain settings.
2. **Check \`skills/\`** for domain-specific operating instructions relevant to this project.
3. **Check \`workflows/\`** for repeatable task procedures.
4. **Run \`trellis seed\`** to refresh this context file when the project evolves.
---
\`\`\`bash
trellis status
trellis log
trellis seed
trellis milestone
\`\`\`
`;
}
function renderSeedIdeRules(profile, context, ide, timestamp) {
const ideName = ide.charAt(0).toUpperCase() + ide.slice(1);
const projectName = context.name ?? "this project";
return `
> Generated by \`trellis seed\` on ${timestamp}
- **Domain**: ${context.domain ?? "(not determined)"}
- **Ecosystem**: ${context.ecosystem ?? "unknown"}
- **File count**: ~${context.fileCount}
- **Confidence**: ${context.confidence}
You are working in a Trellis-tracked repository. See \`.trellis/agents/AGENTS.md\` for full context.
- \`trellis status\` \u2014 Check repo state
- \`trellis seed\` \u2014 Refresh this context file
- \`trellis log\` \u2014 View causal history
---
*Auto-generated by Trellis. Run \`trellis seed\` to refresh context.*
`;
}
// src/scaffold/index.ts
init_infer();
init_profile();
init_write();
export {
seedContext
};