tycono 0.1.27 → 0.1.29

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/bin/tycono.ts CHANGED
@@ -131,13 +131,20 @@ async function startServer(): Promise<void> {
131
131
  const port = process.env.PORT ? Number(process.env.PORT) : await findFreePort();
132
132
  process.env.PORT = String(port);
133
133
 
134
- // Detect company name from CLAUDE.md
134
+ // Detect company name from company/company.md (user-owned), fallback to CLAUDE.md
135
135
  let companyName = 'My Company';
136
136
  if (initialized) {
137
137
  try {
138
- const claudeContent = fs.readFileSync(claudeMdPath, 'utf-8');
139
- const titleMatch = claudeContent.match(/^#\s+(.+)/m);
140
- if (titleMatch) companyName = titleMatch[1].trim();
138
+ const companyMdPath = path.join(process.env.COMPANY_ROOT!, 'company', 'company.md');
139
+ if (fs.existsSync(companyMdPath)) {
140
+ const companyContent = fs.readFileSync(companyMdPath, 'utf-8');
141
+ const titleMatch = companyContent.match(/^#\s+(.+)/m);
142
+ if (titleMatch) companyName = titleMatch[1].trim();
143
+ } else {
144
+ const claudeContent = fs.readFileSync(claudeMdPath, 'utf-8');
145
+ const titleMatch = claudeContent.match(/^#\s+(.+)/m);
146
+ if (titleMatch) companyName = titleMatch[1].trim();
147
+ }
141
148
  } catch {
142
149
  // ignore
143
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tycono",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Build an AI company. Watch them work.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,6 +32,7 @@ import { skillsRouter } from './routes/skills.js';
32
32
  import { importKnowledge } from './services/knowledge-importer.js';
33
33
  import { AnthropicProvider, type LLMProvider } from './engine/llm-adapter.js';
34
34
  import { readConfig } from './services/company-config.js';
35
+ import { ensureClaudeMd } from './services/claude-md-manager.js';
35
36
 
36
37
  const __filename = fileURLToPath(import.meta.url);
37
38
  const __dirname = path.dirname(__filename);
@@ -102,7 +103,11 @@ function handleImportKnowledge(req: http.IncomingMessage, res: http.ServerRespon
102
103
  }
103
104
 
104
105
  export function createHttpServer(): http.Server {
105
- cleanupStaleActivities();
106
+ // Only cleanup/ensure if a company is already initialized (avoid creating dirs in CWD)
107
+ if (COMPANY_ROOT && fs.existsSync(path.join(COMPANY_ROOT, 'CLAUDE.md'))) {
108
+ cleanupStaleActivities();
109
+ ensureClaudeMd(COMPANY_ROOT);
110
+ }
106
111
 
107
112
  const app = createExpressApp();
108
113
 
@@ -166,8 +171,9 @@ export function createExpressApp(): express.Application {
166
171
  let companyName: string | null = null;
167
172
  if (initialized) {
168
173
  try {
169
- const claudeMdPath = path.join(COMPANY_ROOT, 'CLAUDE.md');
170
- const content = fs.readFileSync(claudeMdPath, 'utf-8');
174
+ // Read company name from company/company.md (user-owned data)
175
+ const companyMdPath = path.join(COMPANY_ROOT, 'company', 'company.md');
176
+ const content = fs.readFileSync(companyMdPath, 'utf-8');
171
177
  const match = content.match(/^#\s+(.+)/m);
172
178
  if (match) companyName = match[1].trim();
173
179
  } catch { /* ignore */ }
@@ -57,10 +57,10 @@ export function assembleContext(
57
57
 
58
58
  const sections: string[] = [];
59
59
 
60
- // 1. CLAUDE.md (전사 규칙 축약)
60
+ // 1. Company Rules (CLAUDE.md + custom-rules.md + company.md)
61
61
  const companyRules = loadCompanyRules(companyRoot);
62
62
  if (companyRules) {
63
- sections.push('# Company Rules\n\n' + companyRules);
63
+ sections.push(companyRules);
64
64
  }
65
65
 
66
66
  // 2. Org Context
@@ -164,14 +164,33 @@ export function assembleContext(
164
164
  /* ─── Section Builders ───────────────────────── */
165
165
 
166
166
  function loadCompanyRules(companyRoot: string): string | null {
167
+ const parts: string[] = [];
168
+
169
+ // 1. System rules (CLAUDE.md — Tycono managed)
167
170
  const claudeMdPath = path.join(companyRoot, 'CLAUDE.md');
168
- if (!fs.existsSync(claudeMdPath)) return null;
171
+ if (fs.existsSync(claudeMdPath)) {
172
+ parts.push(fs.readFileSync(claudeMdPath, 'utf-8'));
173
+ }
174
+
175
+ // 2. User custom rules (.tycono/custom-rules.md — user owned)
176
+ const customPath = path.join(companyRoot, '.tycono', 'custom-rules.md');
177
+ if (fs.existsSync(customPath)) {
178
+ const custom = fs.readFileSync(customPath, 'utf-8').trim();
179
+ if (custom) {
180
+ parts.push('---\n\n## Company Custom Rules\n\n' + custom);
181
+ }
182
+ }
183
+
184
+ // 3. Company info (company/company.md — user owned)
185
+ const companyMdPath = path.join(companyRoot, 'company', 'company.md');
186
+ if (fs.existsSync(companyMdPath)) {
187
+ const companyInfo = fs.readFileSync(companyMdPath, 'utf-8').trim();
188
+ if (companyInfo) {
189
+ parts.push('---\n\n## Company Info\n\n' + companyInfo);
190
+ }
191
+ }
169
192
 
170
- // Give the full CLAUDE.md it contains the routing table, folder structure,
171
- // Hub-first principle, and other navigation info that roles need to work effectively.
172
- // Previously we extracted only AKB + Git rules, but that stripped out the most
173
- // practically useful parts (routing table, folder structure, skill principle).
174
- return fs.readFileSync(claudeMdPath, 'utf-8');
193
+ return parts.length > 0 ? parts.join('\n\n') : null;
175
194
  }
176
195
 
177
196
  function buildOrgContextSection(orgTree: OrgTree, node: OrgNode): string {
@@ -99,9 +99,6 @@ export class RoleLifecycleManager {
99
99
 
100
100
  // 5. Update roles.md Hub
101
101
  this.addToRolesHub(def);
102
-
103
- // 6. Update CLAUDE.md org table
104
- this.addToClaudeMdOrgTable(def);
105
102
  }
106
103
 
107
104
  /**
@@ -160,8 +157,6 @@ export class RoleLifecycleManager {
160
157
 
161
158
  // Remove from roles.md Hub
162
159
  this.removeFromRolesHub(id);
163
- // Remove from CLAUDE.md org table
164
- this.removeFromClaudeMdOrgTable(id);
165
160
  }
166
161
 
167
162
  /**
@@ -337,25 +332,6 @@ ${def.authority.needsApproval.map((a) => `- ${a}`).join('\n')}
337
332
  fs.writeFileSync(hubPath, updatedContent);
338
333
  }
339
334
 
340
- private addToClaudeMdOrgTable(def: RoleDefinition): void {
341
- const claudeMdPath = path.join(this.companyRoot, 'CLAUDE.md');
342
- if (!fs.existsSync(claudeMdPath)) return;
343
-
344
- const content = fs.readFileSync(claudeMdPath, 'utf-8');
345
- if (content.includes(`| **${def.name}**`)) {
346
- return; // Already exists
347
- }
348
-
349
- const row = `| **${def.name}** | AI (${def.id}) | ${def.level} | ${def.reportsTo.toUpperCase()} | Active |`;
350
-
351
- const orgSectionMatch = content.match(/## (?:조직|Organization)[\s\S]*?\n(\|[^\n]*\n)+/);
352
- if (orgSectionMatch) {
353
- const insertPos = (orgSectionMatch.index ?? 0) + orgSectionMatch[0].length;
354
- const updated = content.slice(0, insertPos) + row + '\n' + content.slice(insertPos);
355
- fs.writeFileSync(claudeMdPath, updated);
356
- }
357
- }
358
-
359
335
  private removeFromRolesHub(id: string): void {
360
336
  const hubPath = path.join(this.companyRoot, 'roles', 'roles.md');
361
337
  if (!fs.existsSync(hubPath)) return;
@@ -369,16 +345,6 @@ ${def.authority.needsApproval.map((a) => `- ${a}`).join('\n')}
369
345
  fs.writeFileSync(hubPath, lines.join('\n'));
370
346
  }
371
347
 
372
- private removeFromClaudeMdOrgTable(id: string): void {
373
- const claudeMdPath = path.join(this.companyRoot, 'CLAUDE.md');
374
- if (!fs.existsSync(claudeMdPath)) return;
375
-
376
- const content = fs.readFileSync(claudeMdPath, 'utf-8');
377
- const lines = content.split('\n').filter((line) => {
378
- return !line.includes(`(${id})`) || !line.startsWith('|');
379
- });
380
- fs.writeFileSync(claudeMdPath, lines.join('\n'));
381
- }
382
348
  }
383
349
 
384
350
  /* ─── Helpers ──────────────────────────────── */
@@ -0,0 +1,93 @@
1
+ /**
2
+ * claude-md-manager.ts — CLAUDE.md lifecycle management
3
+ *
4
+ * CLAUDE.md is 100% Tycono-managed. This module handles:
5
+ * - Version tracking via .tycono/rules-version
6
+ * - Auto-regeneration on version mismatch (server startup)
7
+ * - Backup of pre-existing CLAUDE.md (first time only)
8
+ * - Stub creation for .tycono/custom-rules.md
9
+ */
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+ const TEMPLATES_DIR = path.resolve(__dirname, '../../../../templates');
17
+
18
+ /**
19
+ * Read the current package version from package.json
20
+ */
21
+ function getPackageVersion(): string {
22
+ const pkgPath = path.resolve(__dirname, '../../../../package.json');
23
+ try {
24
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
25
+ return pkg.version || '0.0.0';
26
+ } catch {
27
+ return '0.0.0';
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Generate CLAUDE.md content from template with version marker
33
+ */
34
+ function generateClaudeMd(version: string): string {
35
+ const tmplPath = path.join(TEMPLATES_DIR, 'CLAUDE.md.tmpl');
36
+ const template = fs.readFileSync(tmplPath, 'utf-8');
37
+ return template.replaceAll('{{VERSION}}', version);
38
+ }
39
+
40
+ /**
41
+ * Ensure CLAUDE.md is up-to-date with the current package version.
42
+ *
43
+ * Called on server startup. Compares .tycono/rules-version with package version.
44
+ * If different, regenerates CLAUDE.md from template (safe because CLAUDE.md
45
+ * contains 0% user data — all user customization is in .tycono/custom-rules.md).
46
+ */
47
+ export function ensureClaudeMd(companyRoot: string): void {
48
+ const tyconoDir = path.join(companyRoot, '.tycono');
49
+ const rulesVersionPath = path.join(tyconoDir, 'rules-version');
50
+ const claudeMdPath = path.join(companyRoot, 'CLAUDE.md');
51
+ const customRulesPath = path.join(tyconoDir, 'custom-rules.md');
52
+ const backupPath = path.join(tyconoDir, 'CLAUDE.md.backup');
53
+
54
+ // Skip if not initialized (no .tycono/ directory)
55
+ if (!fs.existsSync(tyconoDir)) return;
56
+
57
+ const currentVersion = getPackageVersion();
58
+
59
+ // Read stored version
60
+ let storedVersion = '0.0.0';
61
+ if (fs.existsSync(rulesVersionPath)) {
62
+ storedVersion = fs.readFileSync(rulesVersionPath, 'utf-8').trim();
63
+ }
64
+
65
+ // Skip if already up-to-date
66
+ if (storedVersion === currentVersion) return;
67
+
68
+ // Backup existing CLAUDE.md (first time only — don't overwrite previous backup)
69
+ if (fs.existsSync(claudeMdPath) && !fs.existsSync(backupPath)) {
70
+ fs.copyFileSync(claudeMdPath, backupPath);
71
+ console.log(`[CLAUDE.md] Backed up existing CLAUDE.md to .tycono/CLAUDE.md.backup`);
72
+ }
73
+
74
+ // Regenerate CLAUDE.md from template
75
+ const content = generateClaudeMd(currentVersion);
76
+ fs.writeFileSync(claudeMdPath, content);
77
+
78
+ // Update rules-version
79
+ fs.writeFileSync(rulesVersionPath, currentVersion);
80
+
81
+ // Create custom-rules.md stub if not exists
82
+ if (!fs.existsSync(customRulesPath)) {
83
+ fs.writeFileSync(customRulesPath, `# Custom Rules
84
+
85
+ > Company-specific rules, constraints, and processes.
86
+ > This file is owned by you — Tycono will never overwrite it.
87
+
88
+ <!-- Add your custom rules below -->
89
+ `);
90
+ }
91
+
92
+ console.log(`[CLAUDE.md] System rules updated to v${currentVersion} (was v${storedVersion})`);
93
+ }
@@ -13,6 +13,16 @@ const __filename = fileURLToPath(import.meta.url);
13
13
  const __dirname = path.dirname(__filename);
14
14
  const TEMPLATES_DIR = path.resolve(__dirname, '../../../../templates');
15
15
 
16
+ function getPackageVersion(): string {
17
+ const pkgPath = path.resolve(__dirname, '../../../../package.json');
18
+ try {
19
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
20
+ return pkg.version || '0.0.0';
21
+ } catch {
22
+ return '0.0.0';
23
+ }
24
+ }
25
+
16
26
  export interface ScaffoldConfig {
17
27
  companyName: string;
18
28
  description: string;
@@ -155,11 +165,23 @@ export function scaffold(config: ScaffoldConfig): string[] {
155
165
  created.push(dir + '/');
156
166
  }
157
167
 
158
- // Write CLAUDE.md
168
+ // Write CLAUDE.md (no variable substitution — 100% Tycono managed)
159
169
  const claudeTmpl = loadTemplate('CLAUDE.md.tmpl');
160
- fs.writeFileSync(path.join(root, 'CLAUDE.md'), renderTemplate(claudeTmpl, vars));
170
+ const pkgVersion = getPackageVersion();
171
+ fs.writeFileSync(path.join(root, 'CLAUDE.md'), claudeTmpl.replaceAll('{{VERSION}}', pkgVersion));
161
172
  created.push('CLAUDE.md');
162
173
 
174
+ // Write .tycono/rules-version
175
+ fs.writeFileSync(path.join(root, '.tycono', 'rules-version'), pkgVersion);
176
+ created.push('.tycono/rules-version');
177
+
178
+ // Write .tycono/custom-rules.md (empty stub — user owned)
179
+ const customRulesPath = path.join(root, '.tycono', 'custom-rules.md');
180
+ if (!fs.existsSync(customRulesPath)) {
181
+ fs.writeFileSync(customRulesPath, `# Custom Rules\n\n> Company-specific rules, constraints, and processes.\n> This file is owned by you — Tycono will never overwrite it.\n\n<!-- Add your custom rules below -->\n`);
182
+ created.push('.tycono/custom-rules.md');
183
+ }
184
+
163
185
  // Write company/company.md
164
186
  const companyTmpl = loadTemplate('company.md.tmpl');
165
187
  fs.writeFileSync(path.join(root, 'company', 'company.md'), renderTemplate(companyTmpl, vars));
@@ -310,16 +332,4 @@ function createRole(root: string, role: TeamRole): void {
310
332
  fs.writeFileSync(rolesHubPath, hubContent.trimEnd() + '\n' + row + '\n');
311
333
  }
312
334
 
313
- // Append to CLAUDE.md org table
314
- const claudeMdPath = path.join(root, 'CLAUDE.md');
315
- if (fs.existsSync(claudeMdPath)) {
316
- const claudeContent = fs.readFileSync(claudeMdPath, 'utf-8');
317
- const orgRow = `| **${role.name}** | AI (${role.id}) | ${role.level} | ${role.reportsTo} | Active |`;
318
- const orgMatch = claudeContent.match(/(## Organization[\s\S]*?\n(\|[^\n]*\n)+)/);
319
- if (orgMatch) {
320
- const insertPos = (orgMatch.index ?? 0) + orgMatch[0].length;
321
- const updated = claudeContent.slice(0, insertPos) + orgRow + '\n' + claudeContent.slice(insertPos);
322
- fs.writeFileSync(claudeMdPath, updated);
323
- }
324
- }
325
335
  }
@@ -81,12 +81,18 @@ function loadAll(): void {
81
81
  }
82
82
  }
83
83
 
84
- // Load on startup
85
- loadAll();
84
+ // Lazy load: defer until first access (avoids creating dirs in CWD before scaffold)
85
+ let loaded = false;
86
+ function ensureLoaded(): void {
87
+ if (loaded) return;
88
+ loaded = true;
89
+ loadAll();
90
+ }
86
91
 
87
92
  /* ─── Public API ────────────────────────── */
88
93
 
89
94
  export function createSession(roleId: string, mode: 'talk' | 'do' = 'talk'): Session {
95
+ ensureLoaded();
90
96
  const id = `ses-${roleId}-${Date.now()}`;
91
97
  const now = new Date().toISOString();
92
98
  const session: Session = {
@@ -105,10 +111,12 @@ export function createSession(roleId: string, mode: 'talk' | 'do' = 'talk'): Ses
105
111
  }
106
112
 
107
113
  export function getSession(id: string): Session | undefined {
114
+ ensureLoaded();
108
115
  return cache.get(id);
109
116
  }
110
117
 
111
118
  export function listSessions(): Omit<Session, 'messages'>[] {
119
+ ensureLoaded();
112
120
  return Array.from(cache.values())
113
121
  .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
114
122
  .map(({ messages: _, ...meta }) => meta);
@@ -1,13 +1,6 @@
1
- # {{COMPANY_NAME}}
1
+ # Company Rules
2
2
 
3
- > {{DESCRIPTION}}
4
-
5
- ---
6
-
7
- ## Organization
8
-
9
- | Role | Assignee | Level | Reports To | Status |
10
- |------|----------|-------|------------|--------|
3
+ > Powered by [Tycono](https://tycono.ai) — AI Company Operating Platform
11
4
 
12
5
  ---
13
6
 
@@ -40,12 +33,46 @@
40
33
 
41
34
  ## AI Work Rules
42
35
 
36
+ ### The Loop (Work Cycle)
37
+
38
+ Every task follows this cycle. Implementing without completing the cycle is only half the job.
39
+
40
+ | Step | Action | Why |
41
+ |------|--------|-----|
42
+ | ① Knowledge | Check/research related docs | Without context, direction goes wrong |
43
+ | ② Task | Define task from docs | Without requirements, you'll rework |
44
+ | ③ Implement | Execute the actual work | Value creation |
45
+ | ④ Knowledge Update | Update docs with new insights | Prevents knowledge decay |
46
+ | ⑤ Task Update | Update task status, check next work | Ensures continuity |
47
+
48
+ **C-Level**: Execute The Loop autonomously — decompose tasks, analyze dependencies, dispatch independent tasks in parallel, collect results.
49
+ **Member**: After implementation, always complete steps ④ and ⑤.
50
+
43
51
  ### Hub-First Principle
44
52
 
45
- > **Read the relevant Hub document before starting any work.**
53
+ > **Read the relevant Hub document before starting any work.**
46
54
 
55
+ Check the Task Routing table above to find the right "Read First" path.
47
56
  Every folder has a Hub file (`{folder-name}.md`) as its entry point.
48
- Check the Task Routing table above to find the right Hub, then read it first.
57
+ Read the Hub's existing tools/scripts/guides before starting work.
58
+
59
+ ### Skill Check Principle
60
+
61
+ > ⛔ **If `.claude/skills/{role-id}/SKILL.md` exists, you MUST read it.**
62
+
63
+ Skill files define the tools, commands, and guides for each Role.
64
+ Working without reading skills means missing existing tools and starting from scratch.
65
+
66
+ ### Custom Rules (CRITICAL)
67
+
68
+ > ⛔ **Before starting work, check if `.tycono/custom-rules.md` exists and read it.**
69
+ > This file contains company-specific rules, constraints, and processes.
70
+ > If the file doesn't exist, ignore this section.
71
+
72
+ ### Git Rules
73
+
74
+ - Source code changes: feature branch → PR → merge
75
+ - Direct push to main is prohibited
49
76
 
50
77
  ### Knowledge Gate
51
78
 
@@ -69,6 +96,7 @@ Check the Task Routing table above to find the right Hub, then read it first.
69
96
  |------|-------------|
70
97
  | No orphan docs | Every document must be reachable from a Hub |
71
98
  | Hub pattern | Each folder's entry point is `{folder}.md` |
99
+ | Prefer existing | Adding 1 doc = maintenance cost. Strengthen existing > create new |
72
100
  | Cross-link | New docs must reference at least 1 related doc |
73
101
  | Source attribution | External research must cite source and date |
74
102
 
@@ -146,26 +174,35 @@ Check the Hub's existing tools/guides/constraints before exploring code.
146
174
  | Process change | Update procedure guide |
147
175
  | Feature removed | Remove related section |
148
176
 
149
- ### Work Completion Checklist
177
+ ### AKB Management (CRITICAL)
150
178
 
151
- After completing any task:
179
+ > **Every Role manages knowledge as part of their work. Don't just code and stop.**
152
180
 
153
- ```
154
- 1. Did this work produce new knowledge? -> Document it (Knowledge Gate)
155
- 2. Are existing docs still accurate? -> Update if needed
156
- 3. Is the new/updated doc reachable from a Hub? -> Add link
157
- 4. Are there cross-links to related docs? -> Add references
158
- ```
181
+ After completing any task, check:
182
+
183
+ | # | Item | Description |
184
+ |---|------|-------------|
185
+ | 1 | **New knowledge?** | Did this task produce new insights/decisions/analysis? |
186
+ | 2 | **Search existing docs** | Are there related docs already? (grep 3+ keywords) |
187
+ | 3 | **Decide location** | Add to existing doc vs create new (prefer existing) |
188
+ | 4 | **Hub connection** | Is the new/updated doc reachable from a Hub? |
189
+ | 5 | **Cross-link** | Are there mutual references between related docs? |
190
+ | 6 | **Task update** | Is the task status updated? Next work identified? |
159
191
 
160
192
  ---
161
193
 
162
194
  ## Folder Structure
163
195
 
164
196
  ```
165
- {{COMPANY_NAME}}/
166
- +-- CLAUDE.md <- AI entry point
197
+ {company}/
198
+ +-- CLAUDE.md <- AI entry point (Tycono managed)
199
+ +-- .tycono/
200
+ | +-- config.json <- Engine settings
201
+ | +-- preferences.json <- UI preferences
202
+ | +-- custom-rules.md <- Company custom rules (user owned)
203
+ | +-- rules-version <- Current CLAUDE.md version
167
204
  +-- company/
168
- | +-- company.md <- Mission, vision
205
+ | +-- company.md <- Mission, vision, company info
169
206
  +-- roles/
170
207
  | +-- roles.md <- Role listing (Hub)
171
208
  | +-- {role-id}/
@@ -189,4 +226,5 @@ After completing any task:
189
226
 
190
227
  ---
191
228
 
192
- *Powered by [tycono](https://github.com/seongsu-kang/the-company)*
229
+ <!-- tycono:managed v{{VERSION}} — This file is managed by Tycono. Do not edit manually. -->
230
+ <!-- Company-specific rules go in .tycono/custom-rules.md -->