@coggit/core 0.2.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/acceptance.d.ts +7 -0
- package/dist/affected.d.ts +7 -0
- package/dist/cognition/handbooks.d.ts +3 -0
- package/dist/cognition/index.d.ts +34 -0
- package/dist/cognition/templates.d.ts +3 -0
- package/dist/cognitionDiscovery.d.ts +9 -0
- package/dist/cognitionDocumentFacts.d.ts +6 -0
- package/dist/cognitionRoutes.d.ts +10 -0
- package/dist/cognitionTypes.d.ts +100 -0
- package/dist/directoryEntrySourceFact.d.ts +8 -0
- package/dist/gitignore.d.ts +28 -0
- package/dist/hash.d.ts +13 -0
- package/dist/identity.d.ts +76 -0
- package/dist/interfaces.d.ts +174 -0
- package/dist/internal.d.ts +57 -0
- package/dist/internal.js +14229 -0
- package/dist/layout.d.ts +3 -0
- package/dist/locks.d.ts +44 -0
- package/dist/logger.d.ts +17 -0
- package/dist/maintenance.d.ts +7 -0
- package/dist/maintenancePresentation.d.ts +16 -0
- package/dist/mapping.d.ts +98 -0
- package/dist/operationTypes.d.ts +45 -0
- package/dist/operations.d.ts +228 -0
- package/dist/path-utils.d.ts +26 -0
- package/dist/pathHints.d.ts +31 -0
- package/dist/project/buildSnapshot.d.ts +10 -0
- package/dist/project/discover.d.ts +32 -0
- package/dist/project/index.d.ts +8 -0
- package/dist/project/init.d.ts +22 -0
- package/dist/project/project.d.ts +44 -0
- package/dist/project/projectContext.d.ts +4 -0
- package/dist/project/workspace.d.ts +5 -0
- package/dist/projection.d.ts +34 -0
- package/dist/public.d.ts +50 -0
- package/dist/public.js +13733 -0
- package/dist/registry/inMemoryRegistryProvider.d.ts +18 -0
- package/dist/registry/index.d.ts +104 -0
- package/dist/registry/reconcile.d.ts +82 -0
- package/dist/registry/sourceRelocation.d.ts +11 -0
- package/dist/registryTypes.d.ts +52 -0
- package/dist/routesProjection.d.ts +65 -0
- package/dist/snapshot/index.d.ts +3 -0
- package/dist/snapshot/mappingIndex.d.ts +2 -0
- package/dist/snapshot/tree.d.ts +15 -0
- package/dist/snapshotTypes.d.ts +133 -0
- package/dist/sourceStructureIgnore.d.ts +4 -0
- package/dist/status/evidence.d.ts +44 -0
- package/dist/status/index.d.ts +89 -0
- package/dist/status/lookupCognition.d.ts +23 -0
- package/dist/status/statusAgentPresentation.d.ts +37 -0
- package/dist/status/statusPresentation.d.ts +43 -0
- package/dist/status/statusTriage.d.ts +50 -0
- package/dist/status/statusTypes.d.ts +240 -0
- package/dist/systemPrompt.d.ts +24 -0
- package/dist/time.d.ts +2 -0
- package/dist/types.d.ts +5 -0
- package/dist/uri-utils.d.ts +35 -0
- package/dist/watchHost.d.ts +44 -0
- package/dist/watchPipeline.d.ts +31 -0
- package/package.json +48 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RegistryProvider, RegistryFile } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory registry provider for testing.
|
|
4
|
+
*
|
|
5
|
+
* Stores data as a deep-cloned JSON object so each load/save round-trip
|
|
6
|
+
* produces independent copies (no shared references).
|
|
7
|
+
*
|
|
8
|
+
* This is a pure core test double (no host runtime dependency), so it lives in
|
|
9
|
+
* the core package next to the `RegistryProvider` port it implements rather than
|
|
10
|
+
* in a runtime adapter.
|
|
11
|
+
*/
|
|
12
|
+
export declare class InMemoryRegistryProvider implements RegistryProvider {
|
|
13
|
+
private data;
|
|
14
|
+
load(): Promise<RegistryFile | null>;
|
|
15
|
+
save(file: RegistryFile): Promise<void>;
|
|
16
|
+
/** Test helper: simulate corrupt data to exercise recovery paths. */
|
|
17
|
+
corrupt(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { AcceptedPair, PathKeyRecord, RegistryFile, RegistryProvider } from '../types';
|
|
2
|
+
import { type CoggitLogger } from '../logger';
|
|
3
|
+
export declare const REGISTRY_SCHEMA_VERSION = 6;
|
|
4
|
+
export declare const REGISTRY_MAINTENANCE_NOTICE = "This file is auto-maintained CogGit metadata. Ignore routine changes; it is committed so metadata can be located across hosts. Direct reads may be stale; use CogGit commands or MCP tools for authoritative freshness.";
|
|
5
|
+
export interface RegistryCreateOptions {
|
|
6
|
+
logger?: CoggitLogger;
|
|
7
|
+
}
|
|
8
|
+
/** Opaque revision of the complete registry file loaded by a Registry instance. */
|
|
9
|
+
export type RegistryRevision = string;
|
|
10
|
+
/**
|
|
11
|
+
* Raised when a Registry instance tries to flush a file based on an obsolete
|
|
12
|
+
* loaded revision. Callers must discard the instance, reload, and recompute.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RegistryRevisionMismatchError extends Error {
|
|
15
|
+
readonly expectedRevision: RegistryRevision;
|
|
16
|
+
readonly actualRevision: RegistryRevision;
|
|
17
|
+
constructor(expectedRevision: RegistryRevision, actualRevision: RegistryRevision);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* In-memory metadata store backed by a provider (VSCode filesystem or in-memory).
|
|
21
|
+
*
|
|
22
|
+
* Manages CRUD over registry entries, dirty tracking, and atomic flush.
|
|
23
|
+
* Core modules must NOT import this class directly -- only reference the
|
|
24
|
+
* `RegistryProvider` interface from types.ts.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Registry {
|
|
27
|
+
private file;
|
|
28
|
+
private dirty;
|
|
29
|
+
private provider;
|
|
30
|
+
private logger;
|
|
31
|
+
private revision;
|
|
32
|
+
private constructor();
|
|
33
|
+
/**
|
|
34
|
+
* Create a Registry instance backed by the given provider.
|
|
35
|
+
*
|
|
36
|
+
* - If the provider has stored data, it is loaded and validated.
|
|
37
|
+
* - Schema version mismatch triggers a clean rebuild (not a crash).
|
|
38
|
+
* - If no stored data exists, an empty registry is created.
|
|
39
|
+
*/
|
|
40
|
+
static create(provider: RegistryProvider, options?: RegistryCreateOptions): Promise<Registry>;
|
|
41
|
+
/** Get a single entry by key, or undefined if not found. */
|
|
42
|
+
getEntry(key: string): PathKeyRecord | undefined;
|
|
43
|
+
/** Check whether an entry exists for the given key. */
|
|
44
|
+
hasEntry(key: string): boolean;
|
|
45
|
+
/** Get a shallow clone of all entries (prevents external mutation of the internal map). */
|
|
46
|
+
getAllEntries(): Record<string, PathKeyRecord>;
|
|
47
|
+
/** Find all entries that reference the given source path. */
|
|
48
|
+
getEntriesBySourcePath(sourcePath: string): PathKeyRecord[];
|
|
49
|
+
/** Find all path-keyed records that reference the given source path. */
|
|
50
|
+
getRecordsBySourcePath(sourcePath: string): Array<{
|
|
51
|
+
key: string;
|
|
52
|
+
record: PathKeyRecord;
|
|
53
|
+
}>;
|
|
54
|
+
/** Find all registry keys that reference the given source path. */
|
|
55
|
+
getKeysBySourcePath(sourcePath: string): string[];
|
|
56
|
+
/** Get all registry keys. */
|
|
57
|
+
getKeys(): string[];
|
|
58
|
+
/** Read the complete accepted source/cognition relationship. */
|
|
59
|
+
getAcceptedPair(key: string): AcceptedPair | null;
|
|
60
|
+
/** @deprecated Legacy in-memory accessor; v5 freshness uses getAcceptedPair. */
|
|
61
|
+
getFreshnessTimes(key: string): {
|
|
62
|
+
sourceFactMtimeMs: number | null;
|
|
63
|
+
cognitionMtimeMs: number | null;
|
|
64
|
+
verificationTimeMs: number | null;
|
|
65
|
+
sourceFactHash: string | null;
|
|
66
|
+
};
|
|
67
|
+
/** Add or overwrite an entry at the given key. Marks the registry dirty. */
|
|
68
|
+
setEntry(key: string, entry: PathKeyRecord, source?: string): void;
|
|
69
|
+
/** Remove an entry by key. Marks the registry dirty. No-op if the key does not exist. */
|
|
70
|
+
deleteEntry(key: string, source?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Move an entry from oldKey to newKey, preserving all entry fields.
|
|
73
|
+
*
|
|
74
|
+
* Sets dirty once (not delete+set as two separate operations).
|
|
75
|
+
*
|
|
76
|
+
* @returns true if the rename succeeded, false if oldKey did not exist.
|
|
77
|
+
*/
|
|
78
|
+
renameKey(oldKey: string, newKey: string, source?: string): boolean;
|
|
79
|
+
/** Replace the complete accepted relationship atomically in memory. */
|
|
80
|
+
recordAcceptance(key: string, pair: AcceptedPair): void;
|
|
81
|
+
/** @deprecated Legacy observation API; not used by v5 runtime. */
|
|
82
|
+
recordSourceFactTime(key: string, mtimeMs: number, sourceFactHash?: string | null): void;
|
|
83
|
+
/** @deprecated Legacy observation API; not used by v5 runtime. */
|
|
84
|
+
recordCognitionTime(key: string, mtimeMs: number, contentHash?: string | null, contentLength?: number | null): void;
|
|
85
|
+
/** @deprecated Legacy verification API; use recordAcceptance. */
|
|
86
|
+
recordExplicitVerification(key: string, verificationTimeMs?: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Flush in-memory state to the provider.
|
|
89
|
+
*
|
|
90
|
+
* No-op if the registry has not been modified since the last flush.
|
|
91
|
+
*/
|
|
92
|
+
flush(): Promise<void>;
|
|
93
|
+
/** Convenience: record an acceptance and flush immediately. */
|
|
94
|
+
flushAcceptance(key: string, pair: AcceptedPair): Promise<void>;
|
|
95
|
+
private traceSetEntry;
|
|
96
|
+
private traceRegistryMutation;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Compute a deterministic witness for the complete loaded file.
|
|
100
|
+
*
|
|
101
|
+
* This is intentionally not persisted and is not a freshness identity. It is
|
|
102
|
+
* only used to reject stale full-file writes within the local commit boundary.
|
|
103
|
+
*/
|
|
104
|
+
export declare function computeRegistryRevision(file: RegistryFile | null): RegistryRevision;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 3: Reconcile engine.
|
|
3
|
+
*
|
|
4
|
+
* Compares the on-disk cognition directory tree against the registry to produce
|
|
5
|
+
* a diff of operations (add, delete). Called at startup and after any
|
|
6
|
+
* major structural change.
|
|
7
|
+
*
|
|
8
|
+
* ## Algorithm
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* Input:
|
|
12
|
+
* A = walk cognition dir → {key → {path, mtimeMs, contentHash, contentLength}}
|
|
13
|
+
* B = registry entries → {key → entry}
|
|
14
|
+
*
|
|
15
|
+
* 1. deleted = keys(B) - keys(A)
|
|
16
|
+
* 2. added = keys(A) - keys(B)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import type { FileSystem, UriComponents } from '../interfaces';
|
|
20
|
+
import { Registry } from './index';
|
|
21
|
+
/**
|
|
22
|
+
* Scan-specific info for a cognition file found on disk.
|
|
23
|
+
*
|
|
24
|
+
* NOT the same as `CognitionFileInfo` from types.ts — this type is purpose-built
|
|
25
|
+
* for directory scanning and carries content-hash data for scan diagnostics.
|
|
26
|
+
*/
|
|
27
|
+
export interface CognitionFileScanInfo {
|
|
28
|
+
/** Relative path from cognition root to the `.md` file */
|
|
29
|
+
path: string;
|
|
30
|
+
/** Last modification time in milliseconds */
|
|
31
|
+
mtimeMs: number;
|
|
32
|
+
/** SHA256 hex hash of file content */
|
|
33
|
+
contentHash: string;
|
|
34
|
+
/** Content length in characters */
|
|
35
|
+
contentLength: number;
|
|
36
|
+
}
|
|
37
|
+
/** Result of scanning the cognition directory: registry key → scan info. */
|
|
38
|
+
export type CognitionDirScan = Map<string, CognitionFileScanInfo>;
|
|
39
|
+
/**
|
|
40
|
+
* Result of a reconcile run.
|
|
41
|
+
*
|
|
42
|
+
* Describes every registry key's disposition after comparing on-disk cognition
|
|
43
|
+
* files against the stored registry.
|
|
44
|
+
*/
|
|
45
|
+
export interface ReconcileDiff {
|
|
46
|
+
/** Keys added to the registry (new cognition files with no prior entry). */
|
|
47
|
+
added: string[];
|
|
48
|
+
/** Keys removed from the registry (cognition file deleted). */
|
|
49
|
+
deleted: string[];
|
|
50
|
+
/** Summary counters. */
|
|
51
|
+
stats: {
|
|
52
|
+
totalScanned: number;
|
|
53
|
+
totalRegistryEntries: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Walk the cognition directory tree recursively and collect structured info for
|
|
58
|
+
* every source-paired cognition file.
|
|
59
|
+
*
|
|
60
|
+
* - Computes registry keys via `cognitionPathToKey`
|
|
61
|
+
* - Skips free-form markdown, non-`.md` files, and unreadable entries
|
|
62
|
+
* - Reads file content and computes a SHA256 content hash via `computeBlobHash`
|
|
63
|
+
*
|
|
64
|
+
* @param fs Platform filesystem abstraction
|
|
65
|
+
* @param cognitionRootUri URI of the cognition root directory
|
|
66
|
+
* @returns Map of registry key → cognition file scan info
|
|
67
|
+
*/
|
|
68
|
+
export declare function scanCognitionDirectory(fs: FileSystem, cognitionRootUri: UriComponents): Promise<CognitionDirScan>;
|
|
69
|
+
/**
|
|
70
|
+
* Full reconcile algorithm — the main entry point for Phase 3.
|
|
71
|
+
*
|
|
72
|
+
* 1. Compute `deleted` and `added` key sets
|
|
73
|
+
* 2. Apply operations to the registry:
|
|
74
|
+
* - `delete(key)` — cognition file no longer exists
|
|
75
|
+
* - `add(key, info)` — new cognition file discovered
|
|
76
|
+
* 3. Return a `ReconcileDiff` summarising the structural outcome
|
|
77
|
+
*
|
|
78
|
+
* @param registry The in-memory registry (will be mutated and marked dirty)
|
|
79
|
+
* @param scanResult On-disk cognition file scan from `scanCognitionDirectory`
|
|
80
|
+
* @returns Diff describing what changed
|
|
81
|
+
*/
|
|
82
|
+
export declare function reconcileRegistry(registry: Registry, scanResult: CognitionDirScan): Promise<ReconcileDiff>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Registry } from './index';
|
|
2
|
+
export type RegistrySourceRelocation = {
|
|
3
|
+
kind: 'exact';
|
|
4
|
+
fromSourcePath: string;
|
|
5
|
+
toSourcePath: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'prefix';
|
|
8
|
+
fromSourcePath: string;
|
|
9
|
+
toSourcePath: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function applyRegistrySourceRelocations(registry: Registry, relocations: readonly RegistrySourceRelocation[], source?: string): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ContentIdentity } from './hash';
|
|
2
|
+
export interface AcceptedPair {
|
|
3
|
+
source: ContentIdentity;
|
|
4
|
+
cognition: ContentIdentity;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A single cognition-keyed record in .coggit/registry.json.
|
|
8
|
+
*
|
|
9
|
+
* Path anchors are specified in the registry path contract spec.
|
|
10
|
+
*/
|
|
11
|
+
export interface PathKeyRecord {
|
|
12
|
+
/**
|
|
13
|
+
* Bound source file or folder path, relative to the CogGit project root
|
|
14
|
+
* (the directory containing .coggit/). This is registry storage, aligned
|
|
15
|
+
* with the project-root-relative coordinate used by tool-facing operation
|
|
16
|
+
* DTOs.
|
|
17
|
+
*/
|
|
18
|
+
sourcePath: string | null;
|
|
19
|
+
/** Cognition type, matching config template definition. */
|
|
20
|
+
type: 'leaf' | 'folder';
|
|
21
|
+
/** ISO datetime of entry creation. @deprecated Removed from schema v6; retained only for old in-memory callers. */
|
|
22
|
+
createdAt?: string | null;
|
|
23
|
+
/** Accepted source/cognition provenance relationship. */
|
|
24
|
+
accepted?: AcceptedPair | null;
|
|
25
|
+
/** @deprecated Removed from schema v5; retained only for old in-memory callers. */
|
|
26
|
+
sourceFactMtimeMs?: number | null;
|
|
27
|
+
/** @deprecated Removed from schema v5; retained only for old in-memory callers. */
|
|
28
|
+
cognitionMtimeMs?: number | null;
|
|
29
|
+
/** @deprecated Removed from schema v5; retained only for old in-memory callers. */
|
|
30
|
+
verificationTimeMs?: number | null;
|
|
31
|
+
/** @deprecated Removed from schema v5; retained only for old in-memory callers. */
|
|
32
|
+
sourceFactHash?: string | null;
|
|
33
|
+
/** @deprecated Removed from schema v6; retained only for legacy in-memory compatibility. */
|
|
34
|
+
cognitionBlobHash?: string | null;
|
|
35
|
+
/** @deprecated Removed from schema v6; retained only for legacy in-memory compatibility. */
|
|
36
|
+
cognitionLength?: number | null;
|
|
37
|
+
}
|
|
38
|
+
/** The on-disk registry file shape. */
|
|
39
|
+
export interface RegistryFile {
|
|
40
|
+
schemaVersion: number;
|
|
41
|
+
/** Human-facing note for agents and contributors inspecting this generated metadata. */
|
|
42
|
+
maintenanceNotice?: string;
|
|
43
|
+
/** Map from cognition registry key to persisted source/cognition metadata. */
|
|
44
|
+
entries: Record<string, PathKeyRecord>;
|
|
45
|
+
}
|
|
46
|
+
/** Optional provider that core can use to read/write registry data. */
|
|
47
|
+
export interface RegistryProvider {
|
|
48
|
+
/** Load the full registry file. Returns null if no file exists or recovery failed. */
|
|
49
|
+
load(): Promise<RegistryFile | null>;
|
|
50
|
+
/** Atomically save the full registry file. */
|
|
51
|
+
save(file: RegistryFile): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CognitionRoutesEntry, RoutesProjectionNode } from './types.js';
|
|
2
|
+
import type { UriComponents } from './interfaces.js';
|
|
3
|
+
export declare const DEFAULT_ROUTES_DEPTH = 2;
|
|
4
|
+
export interface RouteProjectionLine {
|
|
5
|
+
path: string;
|
|
6
|
+
cognition?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
truncated?: boolean;
|
|
9
|
+
omittedChildrenCount?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface RoutesSourcePathContext {
|
|
12
|
+
sourceRoot?: string;
|
|
13
|
+
projectRootUri?: UriComponents;
|
|
14
|
+
sourceRootUri?: UriComponents;
|
|
15
|
+
}
|
|
16
|
+
export interface RoutesSourcePathSelection {
|
|
17
|
+
normalizedSourcePath?: string;
|
|
18
|
+
nodes: RoutesProjectionNode[];
|
|
19
|
+
missed: boolean;
|
|
20
|
+
pathHints: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare function projectRoutesEntries(entries: readonly CognitionRoutesEntry[]): RoutesProjectionNode[];
|
|
23
|
+
export declare function flattenRoutesProjection(nodes: readonly RoutesProjectionNode[]): RouteProjectionLine[];
|
|
24
|
+
export declare function routeProjectionLineText(route: RouteProjectionLine): string;
|
|
25
|
+
export declare function selectRoutesBySourcePath(tree: readonly RoutesProjectionNode[], sourcePath?: string, _context?: RoutesSourcePathContext): RoutesSourcePathSelection;
|
|
26
|
+
export declare function suggestRoutePathHints(tree: readonly RoutesProjectionNode[], sourcePath: string, _sourceRoot?: string): string[];
|
|
27
|
+
export declare function applyRoutesFilters(tree: readonly RoutesProjectionNode[], sourcePath?: string, _sourceRoot?: string): RoutesProjectionNode[];
|
|
28
|
+
export type RoutesPresentationFormat = 'flat' | 'tree';
|
|
29
|
+
export interface RoutesPresentationContent {
|
|
30
|
+
project: {
|
|
31
|
+
sourceRoot: string;
|
|
32
|
+
cognitionRoot: string;
|
|
33
|
+
};
|
|
34
|
+
depth: number;
|
|
35
|
+
format: RoutesPresentationFormat;
|
|
36
|
+
sourcePath?: string;
|
|
37
|
+
pathMissMessage?: string;
|
|
38
|
+
pathHintMessage?: string;
|
|
39
|
+
pathHints?: string[];
|
|
40
|
+
routes?: string[];
|
|
41
|
+
tree?: RoutesProjectionNode[];
|
|
42
|
+
}
|
|
43
|
+
export interface AssembleRoutesContentOptions {
|
|
44
|
+
sourcePath?: string;
|
|
45
|
+
depth?: number;
|
|
46
|
+
format?: RoutesPresentationFormat;
|
|
47
|
+
projectRootUri?: UriComponents;
|
|
48
|
+
sourceRootUri?: UriComponents;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Consumer-agnostic routes presentation pipeline:
|
|
52
|
+
* entries → tree → sourcePath selection → depth truncation → content assembly.
|
|
53
|
+
*/
|
|
54
|
+
export declare function assembleRoutesContent(input: {
|
|
55
|
+
entries: readonly CognitionRoutesEntry[];
|
|
56
|
+
project: {
|
|
57
|
+
sourceRoot: string;
|
|
58
|
+
cognitionRoot: string;
|
|
59
|
+
};
|
|
60
|
+
}, options?: AssembleRoutesContentOptions): RoutesPresentationContent;
|
|
61
|
+
/** Structured output shape: RoutesPresentationContent minus the presentation-only `format` field. */
|
|
62
|
+
export type RoutesStructuredOutput = Omit<RoutesPresentationContent, 'format'>;
|
|
63
|
+
/** Strip presentation-only fields, yielding the consumer-facing structured payload. */
|
|
64
|
+
export declare function toRoutesStructuredOutput(content: RoutesPresentationContent): RoutesStructuredOutput;
|
|
65
|
+
export declare function countRouteNodes(nodes: readonly RoutesProjectionNode[]): number;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { BuildProjectSnapshotOptions } from './tree';
|
|
2
|
+
export { buildProjectSnapshot, buildRootNode, buildDirectoryChildren, buildFolderNode, buildFileNode, computeFolderFingerprint, folderSourceKey, } from './tree';
|
|
3
|
+
export { buildMappingIndex } from './mappingIndex';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CoggitSnapshot, CoggitTreeNode, CoggitWorkspaceRoot } from '../types';
|
|
2
|
+
import type { AcceptanceStore, FileSystem, FreshnessEvidenceStore, UriComponents } from '../interfaces';
|
|
3
|
+
import { loadGitignoreRules } from '../gitignore';
|
|
4
|
+
export interface BuildProjectSnapshotOptions {
|
|
5
|
+
acceptance?: AcceptanceStore | null;
|
|
6
|
+
/** @deprecated v3 test adapter; ignored by the v5 acceptance model. */
|
|
7
|
+
freshnessEvidence?: FreshnessEvidenceStore | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function computeFolderFingerprint(children: CoggitTreeNode[]): string;
|
|
10
|
+
export declare function folderSourceKey(relativePath: string): string;
|
|
11
|
+
export declare function buildProjectSnapshot(root: CoggitWorkspaceRoot, fs: FileSystem, options?: BuildProjectSnapshotOptions): Promise<CoggitSnapshot>;
|
|
12
|
+
export declare function buildRootNode(root: CoggitWorkspaceRoot, fs: FileSystem, options?: BuildProjectSnapshotOptions): Promise<CoggitTreeNode>;
|
|
13
|
+
export declare function buildDirectoryChildren(parent: CoggitTreeNode, directoryUri: UriComponents, sourceRootUri: UriComponents, inheritedIgnoreRules: Parameters<typeof loadGitignoreRules>[2], fs: FileSystem, options?: BuildProjectSnapshotOptions): Promise<CoggitTreeNode[]>;
|
|
14
|
+
export declare function buildFolderNode(parent: CoggitTreeNode, folderUri: UriComponents, sourceRootUri: UriComponents, inheritedIgnoreRules: Parameters<typeof loadGitignoreRules>[2], fs: FileSystem, options?: BuildProjectSnapshotOptions): Promise<CoggitTreeNode>;
|
|
15
|
+
export declare function buildFileNode(parent: CoggitTreeNode, fileUri: UriComponents, sourceRootUri: UriComponents, fs: FileSystem, options?: BuildProjectSnapshotOptions): Promise<CoggitTreeNode>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { UriComponents, UriKey, WorkspaceFolderInfo } from './interfaces';
|
|
2
|
+
import type { NodeStatusResult, ObservedStatus } from './status/statusTypes';
|
|
3
|
+
export type SourceCandidateState = 'some-exist' | 'all-missing' | 'ambiguous' | 'unchecked';
|
|
4
|
+
export interface CognitionDiscoveryEntry {
|
|
5
|
+
registryKey: string;
|
|
6
|
+
type: 'leaf' | 'folder';
|
|
7
|
+
cognitionPath: string;
|
|
8
|
+
cognitionUri: UriComponents;
|
|
9
|
+
sourceCandidateUris: UriComponents[];
|
|
10
|
+
sourceCandidateState?: SourceCandidateState;
|
|
11
|
+
}
|
|
12
|
+
export interface MisplacedCognitionEntry {
|
|
13
|
+
registryKey: string;
|
|
14
|
+
type: 'leaf' | 'folder';
|
|
15
|
+
sourcePath: string;
|
|
16
|
+
sourceUri: UriComponents;
|
|
17
|
+
actualCognitionPath: string;
|
|
18
|
+
actualCognitionUri: UriComponents;
|
|
19
|
+
expectedCognitionPath: string;
|
|
20
|
+
expectedCognitionUri: UriComponents;
|
|
21
|
+
}
|
|
22
|
+
export interface OrphanedCognitionEntry {
|
|
23
|
+
registryKey: string;
|
|
24
|
+
type: 'leaf' | 'folder';
|
|
25
|
+
sourcePath: string;
|
|
26
|
+
sourceUri: UriComponents;
|
|
27
|
+
cognitionPath: string;
|
|
28
|
+
cognitionUri: UriComponents;
|
|
29
|
+
}
|
|
30
|
+
export interface StrayCognitionEntry extends CognitionDiscoveryEntry {
|
|
31
|
+
}
|
|
32
|
+
export interface UnboundCognitionEntry extends CognitionDiscoveryEntry {
|
|
33
|
+
}
|
|
34
|
+
export type MaintenanceDiagnostic = {
|
|
35
|
+
kind: 'orphaned';
|
|
36
|
+
entry: OrphanedCognitionEntry;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'misplaced';
|
|
39
|
+
entry: MisplacedCognitionEntry;
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'stray';
|
|
42
|
+
entry: StrayCognitionEntry;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'unbound';
|
|
45
|
+
entry: UnboundCognitionEntry;
|
|
46
|
+
};
|
|
47
|
+
export type CoggitNodeKind = 'root' | 'folder' | 'file' | 'error';
|
|
48
|
+
export interface MappingIndex {
|
|
49
|
+
/** Canonical URI identity key. */
|
|
50
|
+
sourceToCognition: Map<UriKey, UriKey[]>;
|
|
51
|
+
/** Canonical URI identity key. */
|
|
52
|
+
cognitionToSource: Map<UriKey, UriKey>;
|
|
53
|
+
structuralEdges: Array<{
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
kind: 'parent' | 'child' | 'sibling';
|
|
57
|
+
}>;
|
|
58
|
+
semanticEdges: Array<{
|
|
59
|
+
from: string;
|
|
60
|
+
to: string;
|
|
61
|
+
kind: 'link' | 'backlink';
|
|
62
|
+
}>;
|
|
63
|
+
}
|
|
64
|
+
export interface AffectedResult {
|
|
65
|
+
pairs: Array<{
|
|
66
|
+
sourcePath: string;
|
|
67
|
+
cognitionPath: string;
|
|
68
|
+
reason: 'direct' | 'structural' | 'semantic';
|
|
69
|
+
}>;
|
|
70
|
+
stats: {
|
|
71
|
+
direct: number;
|
|
72
|
+
structural: number;
|
|
73
|
+
semantic: number;
|
|
74
|
+
total: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface CoggitWorkspaceRoot {
|
|
78
|
+
id: string;
|
|
79
|
+
label: string;
|
|
80
|
+
workspaceFolder: WorkspaceFolderInfo;
|
|
81
|
+
configUri: UriComponents;
|
|
82
|
+
projectRootUri: UriComponents;
|
|
83
|
+
sourceRootUri: UriComponents;
|
|
84
|
+
cognitionRootUri: UriComponents;
|
|
85
|
+
error?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface CoggitTreeNode {
|
|
88
|
+
id: string;
|
|
89
|
+
kind: CoggitNodeKind;
|
|
90
|
+
label: string;
|
|
91
|
+
resourceUri: UriComponents;
|
|
92
|
+
sourceUri: UriComponents;
|
|
93
|
+
cognitionUri?: UriComponents;
|
|
94
|
+
relativePath: string;
|
|
95
|
+
/** Own cognition/projection status for this node only, before descendant aggregation. */
|
|
96
|
+
ownStatus?: NodeStatusResult;
|
|
97
|
+
/** Aggregated status for this node plus descendants. */
|
|
98
|
+
status?: NodeStatusResult;
|
|
99
|
+
contextValue: string;
|
|
100
|
+
parent?: CoggitTreeNode;
|
|
101
|
+
children?: CoggitTreeNode[];
|
|
102
|
+
description?: string;
|
|
103
|
+
tooltip?: string;
|
|
104
|
+
root: CoggitWorkspaceRoot;
|
|
105
|
+
representativeMtimeMs?: number;
|
|
106
|
+
}
|
|
107
|
+
export interface CoggitSnapshot {
|
|
108
|
+
roots: CoggitTreeNode[];
|
|
109
|
+
allNodes: CoggitTreeNode[];
|
|
110
|
+
nodeById: Map<string, CoggitTreeNode>;
|
|
111
|
+
nodeBySourceUri: Map<string, CoggitTreeNode>;
|
|
112
|
+
/** Mapping index used for incremental affected-path calculation. */
|
|
113
|
+
mappingIndex?: MappingIndex;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Plain-data projection node. Absent optional fields are omitted keys,
|
|
117
|
+
* never own properties with `undefined` values.
|
|
118
|
+
*/
|
|
119
|
+
export interface TreeProjectionNode {
|
|
120
|
+
path: string;
|
|
121
|
+
label: string;
|
|
122
|
+
kind: CoggitNodeKind;
|
|
123
|
+
cognition?: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
observedStatus?: ObservedStatus | null;
|
|
126
|
+
ownObservedStatus?: ObservedStatus | null;
|
|
127
|
+
tracked?: boolean;
|
|
128
|
+
children?: TreeProjectionNode[];
|
|
129
|
+
}
|
|
130
|
+
export interface CoggitConfig {
|
|
131
|
+
sourceRoot: string;
|
|
132
|
+
cognitionRoot: string;
|
|
133
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const GENERATED_SOURCE_STRUCTURE_DIRECTORY_NAMES: readonly [".cache", ".git", ".mypy_cache", ".next", ".nox", ".nuxt", ".parcel-cache", ".pytest_cache", ".ruff_cache", ".svelte-kit", ".tox", ".turbo", ".vite", ".vscode-test", "__pycache__", "build", "coverage", "dist", "lib", "node_modules", "out", "vendor"];
|
|
2
|
+
export declare function isIgnoredSourceStructureEntry(name: string, isDirectory: boolean): boolean;
|
|
3
|
+
export declare function generatedSourceStructureGlobExcludePatterns(): string[];
|
|
4
|
+
export declare function generatedSourceStructureGlobExclude(): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CognitionFileInfo, CoverageSignals, Evidence, ObservedStatus, Reason, SourceFileInfo, StaleDegreeResult, StatusContext, StatusIssue } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Collects structured evidence between source and cognition.
|
|
4
|
+
* All check functions are pure for easy unit testing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function collectEvidence(source: SourceFileInfo, cognition: CognitionFileInfo | null): Evidence;
|
|
7
|
+
export declare function deriveStaleDegree(evidence: Evidence): StaleDegreeResult;
|
|
8
|
+
/**
|
|
9
|
+
* Determines whether cognition content is only a skeleton template (no substantive analysis).
|
|
10
|
+
* Rule: pure headings, heading + empty lines only, or fewer than 3 effective content lines are treated as template.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isTemplateContent(content: string | null): boolean;
|
|
13
|
+
export declare function checkMtime(source: SourceFileInfo, cognition: CognitionFileInfo | null): Reason[];
|
|
14
|
+
export declare function checkAcceptedPair(source: SourceFileInfo, cognition: CognitionFileInfo | null): Reason[];
|
|
15
|
+
export declare function checkSymbols(source: SourceFileInfo, cognition: CognitionFileInfo | null, symbolIndex: StatusContext['symbolIndex']): Reason[];
|
|
16
|
+
export declare function checkLinks(cognition: CognitionFileInfo | null, linkIndex: StatusContext['linkIndex']): Reason[];
|
|
17
|
+
export declare function checkDeps(source: SourceFileInfo, depGraph: StatusContext['depGraph']): Reason[];
|
|
18
|
+
export declare function checkSourceExistence(source: SourceFileInfo, cognition: CognitionFileInfo | null): Reason[];
|
|
19
|
+
/**
|
|
20
|
+
* Single-source edit-work labels for stale pairs. The status inspection
|
|
21
|
+
* reuses these exact labels on its synthesized handbook-bearing sync action,
|
|
22
|
+
* so the issue action and the next-step action always dedup by label match.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SYNC_COGNITION_ACTION_LABEL = "Sync cognition with source changes";
|
|
25
|
+
export declare const SYNC_FOLDER_README_ACTION_LABEL = "Sync folder README with child structure changes";
|
|
26
|
+
export declare function actionLabelsFromIssues(issues: Iterable<StatusIssue> | undefined): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Synthesizes the final 8-state from reasons.
|
|
29
|
+
* Uses a deterministic decision tree (not a weighted model) — see DECISIONS documentation.
|
|
30
|
+
*/
|
|
31
|
+
export declare function synthesizeStatus(reasons: Reason[], evidence: Evidence): {
|
|
32
|
+
observedStatus: ObservedStatus | undefined;
|
|
33
|
+
ownObservedStatus: ObservedStatus | undefined;
|
|
34
|
+
issues: StatusIssue[];
|
|
35
|
+
coverage: CoverageSignals;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Derives recommended actions based on status and reasons.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deriveActions(synthesized: {
|
|
41
|
+
observedStatus: ObservedStatus | undefined;
|
|
42
|
+
issues: StatusIssue[];
|
|
43
|
+
coverage: CoverageSignals;
|
|
44
|
+
}, _reasons: Reason[]): string[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { CoggitTreeNode, CognitionFileInfo, LocatedStatusIssue, NodeStatusInspection, NodeStatusResult, ObservedStatus, SourceFileInfo, StatusContext, StatusResult, SubtreeIssueQueryResult, SourceFactKind, StatusIssueVisibility } from '../types';
|
|
2
|
+
import type { AcceptedPair } from '../registryTypes';
|
|
3
|
+
export { isTemplateContent } from './evidence';
|
|
4
|
+
export declare function projectStatusResultToNodeStatus(status: StatusResult): NodeStatusResult;
|
|
5
|
+
/**
|
|
6
|
+
* Quick mtime-based observed status check.
|
|
7
|
+
* Returns undefined (no observation possible) when cognition doesn't exist.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeMtimeObservedStatus(sourceMtimeMs: number | undefined, cognitionMtimeMs: number | undefined): ObservedStatus | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Combine observed statuses by severity: `conflict` > `stale` > `fresh`. Returns
|
|
12
|
+
* the worst (highest-priority) observed status, or `undefined` when none are
|
|
13
|
+
* observed. This is the single place that defines the aggregation ordering used
|
|
14
|
+
* by `NodeStatusInspection.status` / `StatusOperationResult.status`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function combineObservedStatus(statuses: Iterable<ObservedStatus | undefined>): ObservedStatus | undefined;
|
|
17
|
+
export interface AggregateNodeStatusInput {
|
|
18
|
+
ownStatus?: NodeStatusResult;
|
|
19
|
+
descendantStatuses?: Iterable<NodeStatusResult | undefined>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Aggregate own and descendant status for a node.
|
|
23
|
+
*
|
|
24
|
+
* - `observedStatus` (whole-node): worst of own + descendant by `fresh` <
|
|
25
|
+
* `stale` < `conflict`.
|
|
26
|
+
* - `descendantObservedStatus`: same worst-of over descendants with an observed
|
|
27
|
+
* status (the tracked node-status subset; untracked descendants are skipped).
|
|
28
|
+
* - `ownObservedStatus`: the node's own status, before descendant aggregation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function aggregateNodeStatus(input: AggregateNodeStatusInput): NodeStatusResult;
|
|
31
|
+
export declare function collectSubtreeIssues(node: CoggitTreeNode): LocatedStatusIssue[];
|
|
32
|
+
export declare function querySubtreeIssues(node: CoggitTreeNode): SubtreeIssueQueryResult;
|
|
33
|
+
export declare function countSubtreeIssues(node: CoggitTreeNode): number;
|
|
34
|
+
export declare function projectStatusIssues(issues: SubtreeIssueQueryResult, visibility?: StatusIssueVisibility): SubtreeIssueQueryResult;
|
|
35
|
+
export interface InspectNodeStatusInput {
|
|
36
|
+
node: CoggitTreeNode;
|
|
37
|
+
sourcePath: string;
|
|
38
|
+
cognitionPath: string | null;
|
|
39
|
+
handbookId: 'leaf' | 'skeleton' | null;
|
|
40
|
+
issueVisibility?: StatusIssueVisibility;
|
|
41
|
+
}
|
|
42
|
+
export declare function inspectNodeStatus(input: InspectNodeStatusInput): NodeStatusInspection;
|
|
43
|
+
/**
|
|
44
|
+
* Full 8-state status determination — synthesized from the evidence chain.
|
|
45
|
+
* Replaces the Python prototype's 4-state StatusValue (ok/risk/unknown/blocked).
|
|
46
|
+
*/
|
|
47
|
+
export declare function computeStatus(source: SourceFileInfo, cognition: CognitionFileInfo | null, context: StatusContext): StatusResult;
|
|
48
|
+
/**
|
|
49
|
+
* Summarizes the most recent representativeMtime among child nodes.
|
|
50
|
+
*/
|
|
51
|
+
export declare function summarizeRepresentativeMtime(children: CoggitTreeNode[]): number | undefined;
|
|
52
|
+
export interface RuntimeStatusInput {
|
|
53
|
+
sourceUri: string;
|
|
54
|
+
sourceContent: string;
|
|
55
|
+
sourceFactKind?: SourceFactKind;
|
|
56
|
+
sourceMtimeMs: number;
|
|
57
|
+
cognitionUri: string | null;
|
|
58
|
+
cognitionContent: string | null;
|
|
59
|
+
cognitionMtimeMs: number | null;
|
|
60
|
+
verificationTimeMs?: number | null;
|
|
61
|
+
acceptedPair?: AcceptedPair | null;
|
|
62
|
+
context?: Partial<StatusContext>;
|
|
63
|
+
}
|
|
64
|
+
export declare function computeRuntimeStatus(input: RuntimeStatusInput): StatusResult;
|
|
65
|
+
/**
|
|
66
|
+
* Lightweight helper for callers that only have raw text and mtimes.
|
|
67
|
+
*
|
|
68
|
+
* This is not the full evidence pipeline: URI, verification metadata,
|
|
69
|
+
* symbols, links, and dependency context are intentionally unavailable here.
|
|
70
|
+
* Runtime code should prefer computeStatus() whenever those facts are known.
|
|
71
|
+
*/
|
|
72
|
+
export declare function computeStatusFromContent(sourceContent: string, cognitionContent: string | null, sourceMtimeMs: number, cognitionMtimeMs: number | null, context?: Partial<StatusContext>): ObservedStatus | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Map an ObservedStatus to a human-readable label.
|
|
75
|
+
*/
|
|
76
|
+
export declare function describeObservedStatus(status: ObservedStatus | undefined): string | undefined;
|
|
77
|
+
export declare const __testing__: {
|
|
78
|
+
computeRuntimeStatus: typeof computeRuntimeStatus;
|
|
79
|
+
computeMtimeObservedStatus: typeof computeMtimeObservedStatus;
|
|
80
|
+
computeStatusFromContent: typeof computeStatusFromContent;
|
|
81
|
+
combineObservedStatus: typeof combineObservedStatus;
|
|
82
|
+
aggregateNodeStatus: typeof aggregateNodeStatus;
|
|
83
|
+
collectSubtreeIssues: typeof collectSubtreeIssues;
|
|
84
|
+
querySubtreeIssues: typeof querySubtreeIssues;
|
|
85
|
+
countSubtreeIssues: typeof countSubtreeIssues;
|
|
86
|
+
projectStatusIssues: typeof projectStatusIssues;
|
|
87
|
+
summarizeRepresentativeMtime: typeof summarizeRepresentativeMtime;
|
|
88
|
+
inspectNodeStatus: typeof inspectNodeStatus;
|
|
89
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StatusOperationResult } from '../operations';
|
|
2
|
+
/**
|
|
3
|
+
* Hit payload for `tryGetCognitionPath`: the existing paired cognition path and
|
|
4
|
+
* whether that cognition is stale.
|
|
5
|
+
*/
|
|
6
|
+
export interface CognitionLookupHit {
|
|
7
|
+
cognitionPath: string;
|
|
8
|
+
stale: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Project a `statusOperation` result down to the lookup question: does this
|
|
12
|
+
* source path have an existing paired cognition file, and where is it?
|
|
13
|
+
*
|
|
14
|
+
* Returns `null` when there is no existing paired cognition — a source miss, a
|
|
15
|
+
* matched node with no cognition yet, and a not-applicable node all collapse to
|
|
16
|
+
* `null`. On a hit, `stale` is `true` only when the node's own cognition is
|
|
17
|
+
* stale; `conflict` and descendant status do not set it.
|
|
18
|
+
*
|
|
19
|
+
* This is a pure projection over `StatusOperationResult`: it re-encodes fields
|
|
20
|
+
* `statusOperation` already computed and performs no path resolution, path
|
|
21
|
+
* mapping, or presence detection of its own.
|
|
22
|
+
*/
|
|
23
|
+
export declare function tryGetCognitionPath(statusResult: StatusOperationResult): CognitionLookupHit | null;
|