akbo-cli 1.9.4 β 2.0.0
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 +85 -5
- package/dist/catalog_store.d.ts +53 -0
- package/dist/catalog_store.js +131 -0
- package/dist/cli.js +371 -6
- package/dist/dream_engine.d.ts +61 -0
- package/dist/dream_engine.js +330 -0
- package/dist/graph_builder.js +19 -1
- package/dist/guard_service.d.ts +33 -0
- package/dist/guard_service.js +167 -0
- package/dist/hook_generator.d.ts +8 -0
- package/dist/hook_generator.js +67 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/mcp_server.js +214 -0
- package/dist/types.d.ts +59 -1
- package/dist/types.js +20 -2
- package/dist/version.js +2 -2
- package/package.json +2 -2
- package/schemas/knowledge-unit.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# π§ akbo-cli β AI-Native Knowledge Base Oracle & Operator
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/akbo-cli)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://modelcontextprotocol.io/)
|
|
6
|
-
[](https://vitest.dev/)
|
|
7
7
|
[](https://www.npmjs.com/package/akbo-cli)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
|
-
> **Deterministic AST Harvester,
|
|
11
|
-
> Empowers AI coding assistants (**Google Antigravity, Cursor, Claude Code, Gemini CLI, Windsurf, Copilot, Codex**) with zero-token topological context slices, cross-lingual GraphRAG query grounding, and strict architectural invariant enforcement.
|
|
10
|
+
> **Deterministic AST Harvester, Agent Memory Consolidation ("Dreaming"), CKG Engine & Runtime Guardrails**
|
|
11
|
+
> Empowers AI coding assistants (**Google Antigravity, Cursor, Claude Code, Gemini CLI, Windsurf, Copilot, Codex**) with zero-token topological context slices, out-of-band memory consolidation, cross-lingual GraphRAG query grounding, pre-tool runtime execution rails, and strict architectural invariant enforcement.
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -40,7 +40,14 @@ flowchart LR
|
|
|
40
40
|
## β¨ Key Features
|
|
41
41
|
|
|
42
42
|
- **π‘οΈ External Knowledge Pool (Zero-Touch Monorepo Isolation)**: Completely separates scanned code (`targetDir`) from knowledge bases and caches (`poolDir`) via `--pool <path>` or `AKBO_POOL_DIR`. Zero files (`.akb`, `cache.json`, `AGENTS.md`) are ever created in your target repository or subprojects. Caches are safely keyed by target directory inside `poolDir/.akb/caches/${scopeSlug}-${hash8}.json`, walks ancestor `.gitignore` files up to the git repository root with rebasing, supports zero-touch exclusions via `poolDir/.akb/ignore`, and dual-path `applies_to` matching ensures central architectural rules match when scanning any subproject.
|
|
43
|
-
-
|
|
43
|
+
- **π Out-of-Band Memory Consolidation ("Dreaming") (`akbo dream`)**: Asynchronous offline cognitive pipeline inspired by biological sleep cycles. Ingests session observations, tool invocations, and error traces across past runs, discards one-off transient noise, and synthesizes recurring trial-and-error patterns into compounding Architecture Decision Records (`ADR-xxx.yaml`) and patched standards (`authority: synthesized_dream`), allowing daytime agents to wake up sharper with continuously compounding intelligence.
|
|
44
|
+
- **π‘οΈ Active Runtime Guardrails (`akbo guard` & `akbo_guard`)**: Pre-tool execution rail intercepting proposed file modifications, snippets, or diffs before execution. Evaluates proposed changes against active `dont` directives and `.akb/standards.yaml` deprecated patterns, blocking violations before code is written or committed.
|
|
45
|
+
- **π¦ Deterministic Git Pre-Commit & CI Gates (`akbo check --staged`)**: Fast, zero-token pre-commit and CI verification gate that scans git staged diffs against repository invariants, blocking PR merges that violate approved standards.
|
|
46
|
+
- **π In-Memory Code-Execution & Projection Filter (`akbo filter` & `akbo_filter`)**: Evaluates sandboxed JavaScript predicate expressions against in-memory CKG nodes, edges, or invariants with strict field projection, eliminating context window saturation on massive monorepos.
|
|
47
|
+
- **π Multi-Agent Ephemeral Scratchpads & Observation Logging (`akbo scratchpad`, `akbo observe`, `akbo_scratchpad`, `akbo_record_observation`)**: Dedicated isolated session notes (`.akb/sessions/<agent_id>/scratchpad.md` and `observations.jsonl`) eliminating multi-agent write collisions and preventing short-term scratchpads from polluting durable organizational knowledge.
|
|
48
|
+
- **π Declarative Operational Contracts (`llms.txt` & `llms-full.txt`)**: Generates standard `llms.txt` and `llms-full.txt` manifests alongside `AGENTS.md` and `CLAUDE.md`, providing clean machine-readable documentation indexes and API manifests for LLM crawlers and agents.
|
|
49
|
+
- **β³ Bi-Temporal CKG & State Invalidation (`SUPERSEDES` links)**: Tracks invariant lineage (`supersedes`, `superseded_by`, `valid_from`) and alerts when code matches superseded conventions, preventing stale memory poisoning.
|
|
50
|
+
- **β‘ Native Model Context Protocol (MCP 2.0) Server**: Built on `@modelcontextprotocol/sdk` over STDIO (`akbo mcp` / `akbo-mcp`), exposing 18 high-performance tools (`akbo_search`, `akbo_impact`, `akbo_context`, `akbo_query`, `akbo_harvest`, `akbo_validate`, `akbo_graph`, `akbo_list_invariants`, `akbo_upsert_unit`, `akbo_upsert_units`, `akbo_get_unit`, `akbo_delete_unit`, `akbo_import_skills`, `akbo_filter`, `akbo_record_observation`, `akbo_scratchpad`, `akbo_dream`, `akbo_guard`) and direct catalog resources with native Google Antigravity CLI (`agy`) support, tool allowlist/denylist flags (`--disable-tools`, `--zero-token-only`, `--disallow-root-scan`), `summaryOnly` payload capping, and recursive agent spawning protection (`AKBO_NESTED_AGENT: '1'`).
|
|
44
51
|
- **π¦ Atomic Knowledge Store & Batch Upserts (`akbo upsert`, `akbo get-unit`, `akbo delete-unit`)**: Exposes programmatic and CLI-driven atomic knowledge unit management powered by `CatalogStore`. Supports single or batch JSON/YAML unit arrays, automatic PowerShell UTF-8 BOM stripping, path normalization on `applies_to`, atomic `knowledge/index.yaml` updates via rename, built-in validation, and Windows CRLF line ending preservation.
|
|
45
52
|
- **π€ Windows-1252 (CP1252) Source File Decoding**: Decodes non-UTF-8 legacy C# source files (e.g. Western European Windows-1252/CP1252 files with `Γ±`, `Γ©`, `ΓΌ`, `Γ€`, `ΓΆ`) using native `TextDecoder` fallback, preventing Unicode replacement character corruption and regex breakdown.
|
|
46
53
|
- **π Interface-to-Class `IMPLEMENTS` Edge Wiring**: Connects interface symbols directly to their concrete implementation classes (`implementsGroup` in custom extractors and Pass 2 graph linking), enabling bidirectional blast-radius impact analysis across interface abstraction layers.
|
|
@@ -199,6 +206,11 @@ Running `akbo init-hooks .` or `akbo generate .` automatically generates `.curso
|
|
|
199
206
|
| **`akbo_search`** | Tool | Fast, zero-token in-memory symbol search across symbols, endpoints, schemas (<5ms). |
|
|
200
207
|
| **`akbo_impact`** | Tool | Directional blast-radius and inbound dependent calculation with topological build ordering and `IMPLEMENTS` interface traversal. |
|
|
201
208
|
| **`akbo_context`** | Tool | Extracts 0-token topological neighborhood (1β2 hops) & active invariants for an entity, class, file, or endpoint. |
|
|
209
|
+
| **`akbo_filter`** | Tool | Fast in-memory sandboxed JavaScript projection and filtering of CKG nodes, edges, or invariants without flooding context. |
|
|
210
|
+
| **`akbo_record_observation`** | Tool | Records runtime observations, bug fixes, or convention discoveries into isolated agent session logs for offline consolidation. |
|
|
211
|
+
| **`akbo_scratchpad`** | Tool | Reads or updates an agent's isolated session scratchpad (`.akb/sessions/<agent_id>/scratchpad.md`) avoiding write collisions. |
|
|
212
|
+
| **`akbo_dream`** | Tool | Runs out-of-band memory consolidation ("Dreaming") to synthesize durable compounding knowledge units or staged proposals from session observations. |
|
|
213
|
+
| **`akbo_guard`** | Tool | Evaluates proposed code modifications, snippets, or diffs against active invariants and standards as a pre-tool execution rail. |
|
|
202
214
|
| **`akbo_query`** | Tool | Executes GraphRAG query strictly grounded in the CKG (supports `provider: 'agy'`, Gemini, OpenAI, Claude). |
|
|
203
215
|
| **`akbo_harvest`** | Tool | Deterministically scans codebase topology, manifests, schemas, endpoints, and validation rules (0 tokens). |
|
|
204
216
|
| **`akbo_validate`** | Tool | Validates `knowledge/` directory against runtime Zod schemas and cross-reference standards. |
|
|
@@ -487,6 +499,74 @@ standards:
|
|
|
487
499
|
- "**/*Service.cs"
|
|
488
500
|
```
|
|
489
501
|
|
|
502
|
+
#### 20. `akbo dream [dir] [--since <hours>] [--stage-only] [--no-auto-approve] [--provider <llm>] [--cli] [--agy] [--pool <path>] [-j, --json]` (Out-of-Band Memory Consolidation)
|
|
503
|
+
Runs the asynchronous offline memory consolidation pipeline ("Dreaming"):
|
|
504
|
+
- Ingests task observations (`observations.jsonl`) and error traces from past agent sessions.
|
|
505
|
+
- Distills recurring patterns and traps while discarding transient noise.
|
|
506
|
+
- Synthesizes durable Architecture Decisions (`ADR-xxx.yaml`) or patches existing knowledge units with updated `do`/`dont` rules (`authority.level: synthesized_dream`).
|
|
507
|
+
```bash
|
|
508
|
+
# Run consolidation across all recent session observations
|
|
509
|
+
akbo dream .
|
|
510
|
+
|
|
511
|
+
# Stage proposals into .akb/staged/ without directly updating knowledge/index.yaml
|
|
512
|
+
akbo dream . --stage-only
|
|
513
|
+
|
|
514
|
+
# Run dreaming using local Antigravity agy CLI
|
|
515
|
+
akbo dream . --agy
|
|
516
|
+
|
|
517
|
+
# Consolidate observations inside an external knowledge pool
|
|
518
|
+
akbo dream . --pool C:/AKBO/EnterprisePool --json
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
#### 21. `akbo guard <file> [dir] [-c <content>] [--file-content <path>] [--pool <path>] [-j, --json]` (Runtime Pre-Tool Guardrails)
|
|
522
|
+
Pre-tool execution rail that intercepts proposed code modifications before files are touched:
|
|
523
|
+
- Matches applicable invariants by file path (`applies_to`).
|
|
524
|
+
- Verifies proposed changes against `dont` directives (e.g. forbidden CommonJS `require`, raw `eval`, dangerous SQL statements) and `.akb/standards.yaml` deprecated patterns.
|
|
525
|
+
- Exits with code 0 if allowed; exits with code 1 and prints actionable failure reasons if blocked.
|
|
526
|
+
```bash
|
|
527
|
+
# Evaluate a code snippet against applicable repository invariants
|
|
528
|
+
akbo guard src/data/UserRepository.ts -c "const mysql = require('mysql');"
|
|
529
|
+
|
|
530
|
+
# Output machine-readable JSON for agent pre-tool hooks
|
|
531
|
+
akbo guard src/controllers/OrderController.cs --file-content proposed_patch.diff --json
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### 22. `akbo check [dir] [--staged] [--pool <path>] [-j, --json]` (Git Pre-Commit & CI Verification Gate)
|
|
535
|
+
Fast deterministic verification gate that scans git staged diffs against repository invariants:
|
|
536
|
+
```bash
|
|
537
|
+
# Check all git staged files before committing
|
|
538
|
+
akbo check . --staged
|
|
539
|
+
|
|
540
|
+
# Use in pre-commit hooks or CI/CD pipelines
|
|
541
|
+
akbo check . --staged --json
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### 23. `akbo filter <target> [dir] [-p <expr>] [--fields <list>] [--limit <n>] [--pool <path>] [-j, --json]` (In-Memory Graph Projection)
|
|
545
|
+
Executes sandboxed in-memory JavaScript expressions against CKG nodes, edges, or invariants without bloating context:
|
|
546
|
+
```bash
|
|
547
|
+
# Filter endpoints in billing domain with field projection
|
|
548
|
+
akbo filter nodes . -p "n.type === 'endpoint' && n.domain === 'billing'" --fields id,label,file
|
|
549
|
+
|
|
550
|
+
# Filter invariants applicable to TypeScript
|
|
551
|
+
akbo filter invariants . -p "inv.applies_to.some(p => p.includes('ts'))" --limit 10 -j
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
#### 24. `akbo observe [dir] -t <topic> -f <finding> [--fix <fix>] [--files <list>] [--agent <id>] [--pool <path>] [-j, --json]`
|
|
555
|
+
Records an ephemeral runtime finding or bug workaround into an isolated session log for offline dreaming:
|
|
556
|
+
```bash
|
|
557
|
+
akbo observe . -t "MassTransit" -f "Consumers must not swallow exceptions directly" --fix "Allow exceptions to bubble to retry middleware" --files "Consumers/OrderConsumer.cs" --agent "agent-1"
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
#### 25. `akbo scratchpad [dir] [--agent <id>] [--set <text>] [--append <text>] [--pool <path>] [-j, --json]`
|
|
561
|
+
Reads or updates an agent's isolated session scratchpad (`.akb/sessions/<agent_id>/scratchpad.md`), eliminating multi-agent write collisions:
|
|
562
|
+
```bash
|
|
563
|
+
# Read scratchpad for agent
|
|
564
|
+
akbo scratchpad . --agent "agent-1"
|
|
565
|
+
|
|
566
|
+
# Append working notes
|
|
567
|
+
akbo scratchpad . --agent "agent-1" --append "- Investigating deadlock in event queue"
|
|
568
|
+
```
|
|
569
|
+
|
|
490
570
|
---
|
|
491
571
|
|
|
492
572
|
### π€ Execution Providers (Multi-LLM & CLI Engines)
|
package/dist/catalog_store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ValidationResult } from './validator.js';
|
|
2
|
+
import { type AgentObservation, type StagedKnowledgeUnitProposal } from './types.js';
|
|
2
3
|
export interface UpsertUnitsOptions {
|
|
3
4
|
targetDir: string;
|
|
4
5
|
poolDir?: string;
|
|
@@ -75,4 +76,56 @@ export declare class CatalogStore {
|
|
|
75
76
|
poolDir?: string;
|
|
76
77
|
validate?: boolean;
|
|
77
78
|
}): Promise<DeleteUnitResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Records a task-level observation into an isolated agent session log (.akb/sessions/<agent_id>/observations.jsonl).
|
|
81
|
+
*/
|
|
82
|
+
static recordObservation(options: {
|
|
83
|
+
targetDir: string;
|
|
84
|
+
poolDir?: string;
|
|
85
|
+
agentId?: string;
|
|
86
|
+
topic: string;
|
|
87
|
+
finding: string;
|
|
88
|
+
reproducible_fix?: string;
|
|
89
|
+
associated_files?: string[];
|
|
90
|
+
}): AgentObservation;
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves all recorded observations across all agent sessions or for a specific agent.
|
|
93
|
+
*/
|
|
94
|
+
static listObservations(options: {
|
|
95
|
+
targetDir: string;
|
|
96
|
+
poolDir?: string;
|
|
97
|
+
agentId?: string;
|
|
98
|
+
}): AgentObservation[];
|
|
99
|
+
/**
|
|
100
|
+
* Retrieves an agent's isolated session scratchpad markdown content.
|
|
101
|
+
*/
|
|
102
|
+
static getScratchpad(options: {
|
|
103
|
+
targetDir: string;
|
|
104
|
+
poolDir?: string;
|
|
105
|
+
agentId?: string;
|
|
106
|
+
}): string;
|
|
107
|
+
/**
|
|
108
|
+
* Updates an agent's isolated session scratchpad markdown content.
|
|
109
|
+
*/
|
|
110
|
+
static updateScratchpad(options: {
|
|
111
|
+
targetDir: string;
|
|
112
|
+
poolDir?: string;
|
|
113
|
+
agentId?: string;
|
|
114
|
+
content: string;
|
|
115
|
+
append?: boolean;
|
|
116
|
+
}): string;
|
|
117
|
+
/**
|
|
118
|
+
* Stages a proposed knowledge unit or rule update into .akb/staged/ before consolidation.
|
|
119
|
+
*/
|
|
120
|
+
static stageProposal(proposal: StagedKnowledgeUnitProposal, options: {
|
|
121
|
+
targetDir: string;
|
|
122
|
+
poolDir?: string;
|
|
123
|
+
}): StagedKnowledgeUnitProposal;
|
|
124
|
+
/**
|
|
125
|
+
* Lists all currently staged knowledge proposals.
|
|
126
|
+
*/
|
|
127
|
+
static listStagedProposals(options: {
|
|
128
|
+
targetDir: string;
|
|
129
|
+
poolDir?: string;
|
|
130
|
+
}): StagedKnowledgeUnitProposal[];
|
|
78
131
|
}
|
package/dist/catalog_store.js
CHANGED
|
@@ -372,4 +372,135 @@ export class CatalogStore {
|
|
|
372
372
|
validation: validationResult
|
|
373
373
|
};
|
|
374
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Records a task-level observation into an isolated agent session log (.akb/sessions/<agent_id>/observations.jsonl).
|
|
377
|
+
*/
|
|
378
|
+
static recordObservation(options) {
|
|
379
|
+
const targetDir = path.resolve(options.targetDir);
|
|
380
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
381
|
+
const agentId = (options.agentId || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
382
|
+
const sessionDir = path.join(poolConfig.poolDir, '.akb', 'sessions', agentId);
|
|
383
|
+
if (!fs.existsSync(sessionDir)) {
|
|
384
|
+
fs.mkdirSync(sessionDir, { recursive: true });
|
|
385
|
+
}
|
|
386
|
+
const obs = {
|
|
387
|
+
id: `obs-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`,
|
|
388
|
+
timestamp: new Date().toISOString(),
|
|
389
|
+
agentId,
|
|
390
|
+
topic: options.topic,
|
|
391
|
+
finding: options.finding,
|
|
392
|
+
reproducible_fix: options.reproducible_fix,
|
|
393
|
+
associated_files: options.associated_files || [],
|
|
394
|
+
status: 'recorded'
|
|
395
|
+
};
|
|
396
|
+
const obsFile = path.join(sessionDir, 'observations.jsonl');
|
|
397
|
+
const line = JSON.stringify(obs) + '\n';
|
|
398
|
+
fs.appendFileSync(obsFile, line, 'utf-8');
|
|
399
|
+
return obs;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Retrieves all recorded observations across all agent sessions or for a specific agent.
|
|
403
|
+
*/
|
|
404
|
+
static listObservations(options) {
|
|
405
|
+
const targetDir = path.resolve(options.targetDir);
|
|
406
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
407
|
+
const sessionsBase = path.join(poolConfig.poolDir, '.akb', 'sessions');
|
|
408
|
+
if (!fs.existsSync(sessionsBase)) {
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
const results = [];
|
|
412
|
+
const agentDirs = options.agentId
|
|
413
|
+
? [path.join(sessionsBase, options.agentId.replace(/[^a-zA-Z0-9_-]/g, '_'))]
|
|
414
|
+
: fs.readdirSync(sessionsBase).map(d => path.join(sessionsBase, d));
|
|
415
|
+
for (const d of agentDirs) {
|
|
416
|
+
const obsFile = path.join(d, 'observations.jsonl');
|
|
417
|
+
if (fs.existsSync(obsFile)) {
|
|
418
|
+
try {
|
|
419
|
+
const content = fs.readFileSync(obsFile, 'utf-8');
|
|
420
|
+
const lines = content.split('\n').filter(l => l.trim().length > 0);
|
|
421
|
+
for (const l of lines) {
|
|
422
|
+
try {
|
|
423
|
+
results.push(JSON.parse(l));
|
|
424
|
+
}
|
|
425
|
+
catch { }
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch { }
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return results;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Retrieves an agent's isolated session scratchpad markdown content.
|
|
435
|
+
*/
|
|
436
|
+
static getScratchpad(options) {
|
|
437
|
+
const targetDir = path.resolve(options.targetDir);
|
|
438
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
439
|
+
const agentId = (options.agentId || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
440
|
+
const padFile = path.join(poolConfig.poolDir, '.akb', 'sessions', agentId, 'scratchpad.md');
|
|
441
|
+
if (fs.existsSync(padFile)) {
|
|
442
|
+
try {
|
|
443
|
+
return fs.readFileSync(padFile, 'utf-8');
|
|
444
|
+
}
|
|
445
|
+
catch { }
|
|
446
|
+
}
|
|
447
|
+
return '';
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Updates an agent's isolated session scratchpad markdown content.
|
|
451
|
+
*/
|
|
452
|
+
static updateScratchpad(options) {
|
|
453
|
+
const targetDir = path.resolve(options.targetDir);
|
|
454
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
455
|
+
const agentId = (options.agentId || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
456
|
+
const sessionDir = path.join(poolConfig.poolDir, '.akb', 'sessions', agentId);
|
|
457
|
+
if (!fs.existsSync(sessionDir)) {
|
|
458
|
+
fs.mkdirSync(sessionDir, { recursive: true });
|
|
459
|
+
}
|
|
460
|
+
const padFile = path.join(sessionDir, 'scratchpad.md');
|
|
461
|
+
const existing = fs.existsSync(padFile) ? fs.readFileSync(padFile, 'utf-8') : '';
|
|
462
|
+
const newContent = options.append
|
|
463
|
+
? existing + (existing.endsWith('\n') ? '' : '\n') + options.content + '\n'
|
|
464
|
+
: options.content;
|
|
465
|
+
atomicWriteFile(padFile, newContent);
|
|
466
|
+
return newContent;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Stages a proposed knowledge unit or rule update into .akb/staged/ before consolidation.
|
|
470
|
+
*/
|
|
471
|
+
static stageProposal(proposal, options) {
|
|
472
|
+
const targetDir = path.resolve(options.targetDir);
|
|
473
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
474
|
+
const stagedDir = path.join(poolConfig.poolDir, '.akb', 'staged');
|
|
475
|
+
if (!fs.existsSync(stagedDir)) {
|
|
476
|
+
fs.mkdirSync(stagedDir, { recursive: true });
|
|
477
|
+
}
|
|
478
|
+
const file = path.join(stagedDir, `${proposal.id}.yaml`);
|
|
479
|
+
atomicWriteFile(file, YAML.stringify(proposal));
|
|
480
|
+
return proposal;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Lists all currently staged knowledge proposals.
|
|
484
|
+
*/
|
|
485
|
+
static listStagedProposals(options) {
|
|
486
|
+
const targetDir = path.resolve(options.targetDir);
|
|
487
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
|
|
488
|
+
const stagedDir = path.join(poolConfig.poolDir, '.akb', 'staged');
|
|
489
|
+
if (!fs.existsSync(stagedDir)) {
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
const files = fs.readdirSync(stagedDir).filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
|
|
493
|
+
const proposals = [];
|
|
494
|
+
for (const f of files) {
|
|
495
|
+
try {
|
|
496
|
+
const content = fs.readFileSync(path.join(stagedDir, f), 'utf-8');
|
|
497
|
+
const parsed = YAML.parse(content);
|
|
498
|
+
if (parsed && parsed.id) {
|
|
499
|
+
proposals.push(parsed);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
catch { }
|
|
503
|
+
}
|
|
504
|
+
return proposals;
|
|
505
|
+
}
|
|
375
506
|
}
|