@@ -122,6 +122,8 @@ def write_knowledge_base(
122122 _collect (files , skipped , knowledge / "sync.md" , _sync_template (shared_remote ))
123123 if backend == "obsidian" :
124124 _collect_obsidian_files (files , skipped , knowledge )
125+ if backend == "foam" :
126+ _collect_foam_files (files , skipped , knowledge )
125127 if backend == "mempalace" :
126128 _collect (files , skipped , knowledge / "mempalace.md" , _mempalace_template ())
127129 if adapter == "opencode" :
@@ -344,6 +346,15 @@ def _knowledge_json(backend: str, shared_remote: str | None) -> str:
344346 "vault_path" : ".coding-scaffold/knowledge" ,
345347 "open" : "Open .coding-scaffold/knowledge as an Obsidian vault." ,
346348 },
349+ "foam" : {
350+ "optional" : True ,
351+ "workspace_path" : ".coding-scaffold/knowledge" ,
352+ "extension" : "foam.foam-vscode" ,
353+ "open" : (
354+ "Open .coding-scaffold/knowledge as a VS Code workspace; "
355+ "the Foam extension recommends itself on first open."
356+ ),
357+ },
347358 }
348359 return json .dumps (payload , indent = 2 , sort_keys = True ) + "\n "
349360
@@ -360,6 +371,15 @@ def _knowledge_guide(backend: str, shared_remote: str | None) -> str:
360371 if backend == "obsidian"
361372 else "Run `coding-scaffold knowledge --backend obsidian` later if you want an Obsidian vault."
362373 )
374+ foam_line = (
375+ "This scaffold also generated a VS Code workspace and Foam templates under "
376+ "`.coding-scaffold/knowledge/`."
377+ if backend == "foam"
378+ else (
379+ "Run `coding-scaffold knowledge --backend foam` later if you want a Foam workspace "
380+ "(MIT-licensed VS Code extension)."
381+ )
382+ )
363383 return f"""# Team Knowledge Base
364384
365385The knowledge base is the shared memory for AI-enabled coding: decisions, project facts, useful
@@ -418,6 +438,15 @@ def _knowledge_guide(backend: str, shared_remote: str | None) -> str:
418438Obsidian is useful when humans want backlinks, graph navigation, templates, and a pleasant reading
419439surface. It still uses Markdown files, so Git remains the review and sharing mechanism.
420440
441+ ## Optional Foam
442+
443+ { foam_line }
444+
445+ Foam is a free, MIT-licensed VS Code extension that adds backlinks, a graph view, and templates on
446+ top of plain Markdown. Use it when teammates want Obsidian-style ergonomics without the commercial
447+ license (Obsidian is free for personal use but requires a paid Commercial license for
448+ organizations of more than two people).
449+
421450## Optional MemPalace
422451
423452{ mempalace_line }
@@ -972,3 +1001,147 @@ def _opencode_share_agent_pattern() -> str:
9721001context. Propose a small documented agent role or update an existing one. Include when to use it,
9731002what it may read or edit, verification expectations, and handoff rules.
9741003"""
1004+
1005+
1006+ def _collect_foam_files (files : list [Path ], skipped : list [Path ], knowledge : Path ) -> None :
1007+ _collect (files , skipped , knowledge / "FOAM.md" , _foam_start_here ())
1008+ _collect (files , skipped , knowledge / ".vscode" / "extensions.json" , _foam_extensions_json ())
1009+ _collect (files , skipped , knowledge / ".vscode" / "settings.json" , _foam_settings_json ())
1010+ _collect (files , skipped , knowledge / ".foam" / "templates" / "decision.md" , _foam_decision_template ())
1011+ _collect (files , skipped , knowledge / ".foam" / "templates" / "skill.md" , _foam_skill_template ())
1012+ _collect (files , skipped , knowledge / ".foam" / "templates" / "agent.md" , _foam_agent_template ())
1013+
1014+
1015+ def _foam_start_here () -> str :
1016+ return """# Foam Workspace
1017+
1018+ This directory is also wired as a Foam workspace. Open `.coding-scaffold/knowledge/` in VS Code
1019+ and accept the `foam.foam-vscode` recommendation to enable backlinks, the graph view, and the
1020+ templates under `.foam/templates/`.
1021+
1022+ Foam reads plain Markdown with `[[wikilink]]` syntax. The scaffold's curated wiki pages under
1023+ `wiki/` use standard relative links so they render on GitHub; feel free to use `[[wikilinks]]` in
1024+ your own notes under `raw/`, `sessions/`, `decisions/`, and the layered scopes.
1025+
1026+ ## Suggested workflow
1027+
1028+ 1. Capture raw notes from agent sessions in `raw/code-notes/` or `raw/incidents/`.
1029+ 2. Use Foam's graph view to spot recurring topics.
1030+ 3. Promote stable notes into `wiki/`, `decisions/`, or one of the hierarchical-sharing scopes
1031+ (`team/`, `department/`, `unit/`, `company/`) via pull request.
1032+ 4. Use the templates under `.foam/templates/` when starting a new decision, skill, or agent note
1033+ (right-click in VS Code → "Foam: Create new note from template").
1034+
1035+ ## Why Foam
1036+
1037+ Foam is MIT-licensed and runs entirely in VS Code. It's a free alternative to Obsidian for teams
1038+ that need a commercial license for organizational use. Markdown stays the source of truth — Git
1039+ remains the review and sharing mechanism.
1040+ """
1041+
1042+
1043+ def _foam_extensions_json () -> str :
1044+ return json .dumps (
1045+ {
1046+ "recommendations" : [
1047+ "foam.foam-vscode" ,
1048+ ],
1049+ },
1050+ indent = 2 ,
1051+ sort_keys = True ,
1052+ ) + "\n "
1053+
1054+
1055+ def _foam_settings_json () -> str :
1056+ return json .dumps (
1057+ {
1058+ "foam.edit.linkReferenceDefinitions" : "off" ,
1059+ "foam.files.defaultExtension" : ".md" ,
1060+ "foam.files.ignore" : [
1061+ "**/.git/**" ,
1062+ "**/.coding-scaffold/**/_repo/**" ,
1063+ ],
1064+ "foam.graph.style" : {
1065+ "background" : "#202020" ,
1066+ "fontSize" : 12 ,
1067+ },
1068+ "foam.openDailyNote.directory" : "raw/meetings" ,
1069+ },
1070+ indent = 2 ,
1071+ sort_keys = True ,
1072+ ) + "\n "
1073+
1074+
1075+ def _foam_decision_template () -> str :
1076+ return """---
1077+ foam_template:
1078+ name: Decision
1079+ description: Architecture, model routing, tool choice, data handling, or workflow decision.
1080+ ---
1081+ # Decision: $FOAM_TITLE
1082+
1083+ Date: $FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE
1084+ Status: proposed | accepted | superseded
1085+
1086+ Related: [[FOAM]]
1087+
1088+ ## Context
1089+
1090+ What forced this decision?
1091+
1092+ ## Decision
1093+
1094+ What did we decide?
1095+
1096+ ## Consequences
1097+
1098+ What changes downstream? What did we trade off?
1099+
1100+ ## Agent Notes
1101+
1102+ What should an AI coding agent know about this decision?
1103+ """
1104+
1105+
1106+ def _foam_skill_template () -> str :
1107+ return """---
1108+ foam_template:
1109+ name: Skill
1110+ description: A reusable prompt or workflow that the team has validated.
1111+ ---
1112+ # Skill: $FOAM_TITLE
1113+
1114+ Status: draft | validated | recommended | standard
1115+
1116+ Related agents:
1117+
1118+ ## When To Use
1119+
1120+ ## Workflow
1121+
1122+ ## Verification
1123+
1124+ ## Maintenance Notes
1125+ """
1126+
1127+
1128+ def _foam_agent_template () -> str :
1129+ return """---
1130+ foam_template:
1131+ name: Agent
1132+ description: A trusted agent role with explicit scope and handoff rules.
1133+ ---
1134+ # Agent: $FOAM_TITLE
1135+
1136+ Status: draft | validated | recommended | standard
1137+
1138+ Related skills:
1139+
1140+ ## Responsibility
1141+
1142+ ## Allowed Context
1143+
1144+ ## Write Scope
1145+
1146+ ## Handoff Rules
1147+ """
0 commit comments