@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.
Files changed (64) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +42 -0
  4. package/dist/acceptance.d.ts +7 -0
  5. package/dist/affected.d.ts +7 -0
  6. package/dist/cognition/handbooks.d.ts +3 -0
  7. package/dist/cognition/index.d.ts +34 -0
  8. package/dist/cognition/templates.d.ts +3 -0
  9. package/dist/cognitionDiscovery.d.ts +9 -0
  10. package/dist/cognitionDocumentFacts.d.ts +6 -0
  11. package/dist/cognitionRoutes.d.ts +10 -0
  12. package/dist/cognitionTypes.d.ts +100 -0
  13. package/dist/directoryEntrySourceFact.d.ts +8 -0
  14. package/dist/gitignore.d.ts +28 -0
  15. package/dist/hash.d.ts +13 -0
  16. package/dist/identity.d.ts +76 -0
  17. package/dist/interfaces.d.ts +174 -0
  18. package/dist/internal.d.ts +57 -0
  19. package/dist/internal.js +14229 -0
  20. package/dist/layout.d.ts +3 -0
  21. package/dist/locks.d.ts +44 -0
  22. package/dist/logger.d.ts +17 -0
  23. package/dist/maintenance.d.ts +7 -0
  24. package/dist/maintenancePresentation.d.ts +16 -0
  25. package/dist/mapping.d.ts +98 -0
  26. package/dist/operationTypes.d.ts +45 -0
  27. package/dist/operations.d.ts +228 -0
  28. package/dist/path-utils.d.ts +26 -0
  29. package/dist/pathHints.d.ts +31 -0
  30. package/dist/project/buildSnapshot.d.ts +10 -0
  31. package/dist/project/discover.d.ts +32 -0
  32. package/dist/project/index.d.ts +8 -0
  33. package/dist/project/init.d.ts +22 -0
  34. package/dist/project/project.d.ts +44 -0
  35. package/dist/project/projectContext.d.ts +4 -0
  36. package/dist/project/workspace.d.ts +5 -0
  37. package/dist/projection.d.ts +34 -0
  38. package/dist/public.d.ts +50 -0
  39. package/dist/public.js +13733 -0
  40. package/dist/registry/inMemoryRegistryProvider.d.ts +18 -0
  41. package/dist/registry/index.d.ts +104 -0
  42. package/dist/registry/reconcile.d.ts +82 -0
  43. package/dist/registry/sourceRelocation.d.ts +11 -0
  44. package/dist/registryTypes.d.ts +52 -0
  45. package/dist/routesProjection.d.ts +65 -0
  46. package/dist/snapshot/index.d.ts +3 -0
  47. package/dist/snapshot/mappingIndex.d.ts +2 -0
  48. package/dist/snapshot/tree.d.ts +15 -0
  49. package/dist/snapshotTypes.d.ts +133 -0
  50. package/dist/sourceStructureIgnore.d.ts +4 -0
  51. package/dist/status/evidence.d.ts +44 -0
  52. package/dist/status/index.d.ts +89 -0
  53. package/dist/status/lookupCognition.d.ts +23 -0
  54. package/dist/status/statusAgentPresentation.d.ts +37 -0
  55. package/dist/status/statusPresentation.d.ts +43 -0
  56. package/dist/status/statusTriage.d.ts +50 -0
  57. package/dist/status/statusTypes.d.ts +240 -0
  58. package/dist/systemPrompt.d.ts +24 -0
  59. package/dist/time.d.ts +2 -0
  60. package/dist/types.d.ts +5 -0
  61. package/dist/uri-utils.d.ts +35 -0
  62. package/dist/watchHost.d.ts +44 -0
  63. package/dist/watchPipeline.d.ts +31 -0
  64. package/package.json +48 -0
@@ -0,0 +1,3 @@
1
+ import type { FileSystem } from './interfaces';
2
+ import type { CoggitWorkspaceRoot, MisplacedCognitionEntry, PathKeyRecord } from './types';
3
+ export declare function detectMisplacedCognitionEntries(root: CoggitWorkspaceRoot, fs: FileSystem, entries: Record<string, PathKeyRecord>): Promise<MisplacedCognitionEntry[]>;
@@ -0,0 +1,44 @@
1
+ import type { UriComponents } from './interfaces';
2
+ export interface ProjectLockContext {
3
+ readonly owner: 'vscode' | 'mcp' | 'cli' | 'daemon' | string;
4
+ readonly operation: string;
5
+ readonly projectLabel?: string;
6
+ }
7
+ /**
8
+ * Host-neutral coordinator for serializing protected project write sessions.
9
+ *
10
+ * Implementations are NOT reentrant: calling `withWriteLock` from within `fn`
11
+ * on the same project root will block until the outer lock is released, causing
12
+ * a deadlock or bounded-timeout error. Callers must not nest lock acquisitions.
13
+ */
14
+ export interface ProjectLockManager {
15
+ withWriteLock<T>(projectRoot: UriComponents, context: ProjectLockContext, fn: () => Promise<T>): Promise<T>;
16
+ }
17
+ export declare class ProjectLockError extends Error {
18
+ readonly code: string;
19
+ readonly context?: ProjectLockContext | undefined;
20
+ constructor(message: string, code: string, context?: ProjectLockContext | undefined);
21
+ }
22
+ export declare const noOpProjectLockManager: ProjectLockManager;
23
+ /** A held watch lease. Renew keeps the lease from going stale; release ends it. */
24
+ export interface WatchLeaseHandle {
25
+ renew(): Promise<void>;
26
+ release(): Promise<void>;
27
+ }
28
+ /**
29
+ * Host-neutral coordinator for single-writer watcher leases.
30
+ *
31
+ * Unlike `ProjectLockManager`, acquisition never blocks: a caller either
32
+ * becomes the sole holder immediately or backs off to reconcile-on-read.
33
+ */
34
+ export interface WatchLeaseManager {
35
+ /**
36
+ * Non-blocking try-acquire. Returns null when a live holder exists (the
37
+ * caller declines watching and falls back to reconcile-on-read). Never waits.
38
+ */
39
+ tryAcquireWatchLease(projectRoot: UriComponents, context: ProjectLockContext): Promise<WatchLeaseHandle | null>;
40
+ }
41
+ export declare class WatchLeaseError extends ProjectLockError {
42
+ constructor(message: string, code: string, context?: ProjectLockContext);
43
+ }
44
+ export declare const noOpWatchLeaseManager: WatchLeaseManager;
@@ -0,0 +1,17 @@
1
+ export type CoggitLogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export interface CoggitLogEvent {
3
+ level: CoggitLogLevel;
4
+ category: string;
5
+ message: string;
6
+ data?: Record<string, unknown>;
7
+ }
8
+ export interface CoggitLogger {
9
+ log(event: CoggitLogEvent): void;
10
+ }
11
+ export declare const nullCoggitLogger: CoggitLogger;
12
+ export declare function logEvent(logger: CoggitLogger | undefined, level: CoggitLogLevel, category: string, message: string, data?: Record<string, unknown>): void;
13
+ export declare function debugLog(logger: CoggitLogger | undefined, category: string, message: string, data?: Record<string, unknown>): void;
14
+ export declare function infoLog(logger: CoggitLogger | undefined, category: string, message: string, data?: Record<string, unknown>): void;
15
+ export declare function warnLog(logger: CoggitLogger | undefined, category: string, message: string, data?: Record<string, unknown>): void;
16
+ export declare function errorLog(logger: CoggitLogger | undefined, category: string, message: string, data?: Record<string, unknown>): void;
17
+ export declare function createEnvCoggitLogger(prefix?: string): CoggitLogger;
@@ -0,0 +1,7 @@
1
+ import type { FileSystem } from './interfaces';
2
+ import { type CognitionDiscovery } from './cognitionDiscovery';
3
+ import type { CoggitWorkspaceRoot, OrphanedCognitionEntry, PathKeyRecord, StrayCognitionEntry, UnboundCognitionEntry } from './types';
4
+ export { detectMisplacedCognitionEntries } from './layout';
5
+ export declare function detectOrphanedCognitionEntries(root: CoggitWorkspaceRoot, fs: FileSystem, entries: Record<string, PathKeyRecord>): Promise<OrphanedCognitionEntry[]>;
6
+ export declare function detectStrayCognitionEntries(root: CoggitWorkspaceRoot, fs: FileSystem, entries: Record<string, PathKeyRecord>, discovery?: CognitionDiscovery): Promise<StrayCognitionEntry[]>;
7
+ export declare function detectUnboundCognitionEntries(root: CoggitWorkspaceRoot, fs: FileSystem, entries: Record<string, PathKeyRecord>, discovery?: CognitionDiscovery): Promise<UnboundCognitionEntry[]>;
@@ -0,0 +1,16 @@
1
+ import type { MaintenanceDiagnostic } from './types';
2
+ export type MaintenancePresentationFormat = 'text' | 'markdown';
3
+ export type MaintenanceIssueCode = 'tracked-source-missing' | 'cognition-path-out-of-sync' | 'unregistered-cognition' | 'unbound-cognition' | 'missing-source-candidate';
4
+ export interface MaintenancePresentationItem {
5
+ kind: MaintenanceDiagnostic['kind'];
6
+ issueCode: MaintenanceIssueCode;
7
+ severity: 'warning';
8
+ path: string;
9
+ message: string;
10
+ hint: string;
11
+ }
12
+ export interface MaintenancePresentationView {
13
+ items: MaintenancePresentationItem[];
14
+ }
15
+ export declare function projectMaintenancePresentation(diagnostics: readonly MaintenanceDiagnostic[]): MaintenancePresentationView;
16
+ export declare function renderMaintenancePresentation(view: MaintenancePresentationView, format?: MaintenancePresentationFormat): string;
@@ -0,0 +1,98 @@
1
+ import type { UriComponents } from './interfaces';
2
+ import type { CoggitConfig, CoggitWorkspaceRoot } from './types';
3
+ /**
4
+ * Path and URI mapping helpers.
5
+ *
6
+ * String helpers are kept for pure path tests and file-scheme callers. URI helpers
7
+ * are the production API for workspace roots and cognition targets so remote, WSL,
8
+ * and dev-container schemes are preserved end-to-end.
9
+ */
10
+ /**
11
+ * Derive the project root path from a config.yaml path.
12
+ * Convention: .coggit/config.yaml → project root is the parent of .coggit/.
13
+ */
14
+ export declare function getProjectRootPath(configPath: string): string;
15
+ /**
16
+ * Resolve sourceRoot / cognitionRoot from a config URI without converting through
17
+ * fsPath → path.resolve → Uri.file. This preserves the original URI scheme.
18
+ */
19
+ export declare function resolveConfigRoots(configUri: UriComponents, config: CoggitConfig): {
20
+ projectRootUri: UriComponents;
21
+ sourceRootUri: UriComponents;
22
+ cognitionRootUri: UriComponents;
23
+ };
24
+ /**
25
+ * Resolve sourceRoot / cognitionRoot as file-system paths.
26
+ * Prefer resolveConfigRoots() in VS Code-facing code.
27
+ */
28
+ export declare function resolveConfigRootPaths(configPath: string, config: CoggitConfig): {
29
+ projectRoot: string;
30
+ sourceRoot: string;
31
+ cognitionRoot: string;
32
+ };
33
+ export declare function resolvePath(basePath: string, targetPath: string): string;
34
+ /**
35
+ * sourcePath relative to sourceRoot, normalized to / separators.
36
+ */
37
+ export declare function toRelativePath(sourceRootPath: string, sourcePath: string): string;
38
+ export declare function toRelativeUriPath(rootUri: UriComponents, uri: UriComponents): string;
39
+ /**
40
+ * Normalize an operation `sourcePath` input to a source identity.
41
+ *
42
+ * The operation-DTO input surface is project-root-relative; this is the single
43
+ * place that strips the configured `sourceRoot` prefix back to the
44
+ * source-root-relative identity used for tree matching. Non-prefixed paths pass
45
+ * through unchanged as the legacy source-root-relative fallback.
46
+ */
47
+ export declare function normalizeSourcePathInput(sourcePath: string, context?: {
48
+ sourceRoot?: string;
49
+ projectRootUri?: UriComponents;
50
+ sourceRootUri?: UriComponents;
51
+ }): string;
52
+ /**
53
+ * The single source↔cognition pairing convention. Written once here and reused
54
+ * by key derivation (`identity.ts`), URI mapping (below), and reverse inference.
55
+ *
56
+ * - Leaf: `sourceIdentity + ".md"`
57
+ * - Skeleton: `sourceIdentity + "/README.md"` (root `.` → `README.md`)
58
+ */
59
+ export type CognitionIdentityKind = 'leaf' | 'folder';
60
+ export declare function sourceIdentityToCognitionIdentity(sourceIdentity: string, kind: CognitionIdentityKind): string;
61
+ /**
62
+ * Reverse of {@link sourceIdentityToCognitionIdentity}. Returns `undefined` for
63
+ * free-form cognition documents (e.g. `CODE_MAP.md`) that have no source-pairing
64
+ * convention.
65
+ */
66
+ export declare function cognitionIdentityToSourceIdentity(cognitionIdentity: string): {
67
+ sourceIdentity: string;
68
+ kind: CognitionIdentityKind;
69
+ } | undefined;
70
+ /**
71
+ * source file → cognition markdown file path.
72
+ * Example: src/foo/bar.ts → src_cognition/foo/bar.ts.md
73
+ */
74
+ export declare function toCognitionFilePath(sourceRootPath: string, cognitionRootPath: string, sourceFilePath: string): string;
75
+ export declare function toCognitionFileUri(sourceRootUri: UriComponents, cognitionRootUri: UriComponents, sourceFileUri: UriComponents): UriComponents;
76
+ /**
77
+ * source folder → cognition README path.
78
+ * Example: src/foo → src_cognition/foo/README.md
79
+ */
80
+ export declare function toCognitionFolderReadmePath(sourceRootPath: string, cognitionRootPath: string, folderPath: string): string;
81
+ export declare function toCognitionFolderReadmeUri(sourceRootUri: UriComponents, cognitionRootUri: UriComponents, folderUri: UriComponents): UriComponents;
82
+ export declare function inferSourceUriFromCognitionUri(cognitionUri: UriComponents, sourceRootUri: UriComponents, cognitionRootUri: UriComponents): UriComponents | undefined;
83
+ export declare function inferSourceUriCandidatesFromCognitionUri(cognitionUri: UriComponents, sourceRootUri: UriComponents, cognitionRootUri: UriComponents): UriComponents[];
84
+ /**
85
+ * Convert a source-root-relative identity to a project-root-relative path by
86
+ * prepending the configured `sourceRoot` name (skipped when the root is `.`).
87
+ */
88
+ export declare function sourceIdentityToProjectRelative(root: CoggitWorkspaceRoot, sourceIdentity: string): string;
89
+ export declare function cognitionIdentityToProjectRelative(root: CoggitWorkspaceRoot, cognitionIdentity: string): string;
90
+ /**
91
+ * Convert a project-root-relative path back to a source identity by stripping
92
+ * the configured `sourceRoot` name. Non-prefixed paths pass through unchanged
93
+ * (the legacy source-root-relative fallback).
94
+ */
95
+ export declare function projectRelativeToSourceIdentity(root: CoggitWorkspaceRoot, projectRelative: string): string;
96
+ export declare function getParentDir(filePath: string): string;
97
+ export declare function isWithin(parentPath: string, childPath: string): boolean;
98
+ export declare function basename(filePath: string): string;
@@ -0,0 +1,45 @@
1
+ export type SnapshotOperationScope = 'tracked' | 'untracked' | 'issues' | 'all';
2
+ export interface CoggitProjectContext {
3
+ label: string;
4
+ configUri: string;
5
+ /**
6
+ * The consumer anchor: every project-root-relative path on the operation-DTO
7
+ * surface resolves against this URI. `sourceRootUri` / `cognitionRootUri`
8
+ * are internal and intentionally absent.
9
+ */
10
+ projectRootUri: string;
11
+ /** Project-root-relative source root path, e.g. "codebase" - mirrors config.yaml source_root. */
12
+ sourceRoot: string;
13
+ /** Project-root-relative cognition root path, e.g. "codebase_cognition" - mirrors config.yaml cognition_root. */
14
+ cognitionRoot: string;
15
+ sourcePathRule: string;
16
+ }
17
+ /**
18
+ * Surface-neutral operation vocabulary.
19
+ *
20
+ * Boundary rule for core hints: `suggestedActions` and any other next-step
21
+ * guidance emitted by core may only reference these operation ids and opaque
22
+ * asset ids (e.g. `handbookId`) — never adapter tool names, CLI command
23
+ * names, or resource URIs. Each adapter owns the mapping from an operation id
24
+ * to its own surface addressing (MCP maps to its `coggit_*` tools, the CLI
25
+ * maps to subcommands, and so on).
26
+ */
27
+ export declare const CORE_OPERATION_IDS: readonly ["snapshot", "status", "add", "resolve", "routes"];
28
+ export type CoreOperationId = typeof CORE_OPERATION_IDS[number];
29
+ export interface CoggitOperationAction {
30
+ code: string;
31
+ label: string;
32
+ operation?: CoreOperationId;
33
+ /**
34
+ * Read-before-edit asset reference for authoring steps (e.g. the stale
35
+ * sync step). Same opaque id as the top-level `StatusOperationResult
36
+ * .handbookId`; adapters map it to their skill/resource address exactly as
37
+ * they map the top-level field. An action carrying `handbookId` is
38
+ * structured (adapter-mappable) even without an `operation`.
39
+ */
40
+ handbookId?: 'leaf' | 'skeleton';
41
+ /** Project-root-relative source path (the same coordinate as operation `sourcePath` inputs). */
42
+ sourcePath?: string;
43
+ scope?: SnapshotOperationScope;
44
+ maxDepth?: number;
45
+ }
@@ -0,0 +1,228 @@
1
+ import type { AddCognitionKind, CognitionKind } from './cognition';
2
+ import type { CoggitProject } from './interfaces';
3
+ import type { CoggitSnapshot, CoggitTreeNode, CoggitNodeKind, CoggitOperationAction, CoggitProjectContext, LocatedStatusIssue, NodeStatusInspection, ObservedStatus, SnapshotOperationScope, StaleAction, StatusIssue, StatusIssueVisibility, CognitionRoutes, CognitionRoutesEntry, CognitionDocumentDiagnostic } from './types';
4
+ export type { CoggitOperationAction, CoggitProjectContext, CoreOperationId, SnapshotOperationScope, } from './types';
5
+ export { CORE_OPERATION_IDS } from './operationTypes';
6
+ export interface CoggitHandbookCatalogEntry {
7
+ id: 'all' | CognitionKind;
8
+ nodeKind: CoggitNodeKind | null;
9
+ title: string;
10
+ kind: 'all' | CognitionKind;
11
+ }
12
+ export interface CoggitOperationIssue {
13
+ relativePath: string;
14
+ severity: 'info' | 'warning' | 'error';
15
+ code: StatusIssue['diagnostic']['code'] | 'path-not-found' | 'add-failed' | 'invalid-kind';
16
+ message: string;
17
+ actions: CoggitOperationAction[];
18
+ }
19
+ export interface SnapshotOperationResult {
20
+ scope: SnapshotOperationScope;
21
+ projectCount: number;
22
+ trackedCount: number;
23
+ untrackedCount: number;
24
+ issueCount: number;
25
+ nextScopes: SnapshotOperationScope[];
26
+ maxDepth: number | null;
27
+ truncated: boolean;
28
+ omittedChildrenCount: number;
29
+ suggestedActions: CoggitOperationAction[];
30
+ projects: CoggitProjectContext[];
31
+ sourcePath: string | null;
32
+ found: boolean;
33
+ snapshot: CoggitSnapshot | null;
34
+ node: CoggitTreeNode | null;
35
+ /** Fuzzy source-path hints when the source path matched no node. Empty when found. */
36
+ pathHints: string[];
37
+ /** Present only when the source path matched no node. */
38
+ pathMissMessage?: string;
39
+ /** Present only when a miss produced fuzzy hints. */
40
+ pathHintMessage?: string;
41
+ }
42
+ export interface StatusOperationResult {
43
+ found: boolean;
44
+ /** Project-root-relative source path: the matched node's relative path on a
45
+ * hit, or the requested input on a miss. */
46
+ sourcePath: string;
47
+ /** Absolute source URI key string; `null` on a miss. */
48
+ sourceUri: string | null;
49
+ nodeKind: CoggitNodeKind | null;
50
+ /** `null` on a miss. */
51
+ project: CoggitProjectContext | null;
52
+ /**
53
+ * Expected paired cognition path, project-root-relative. `null` on a miss
54
+ * or when the node has no expected cognition URI. This is the *expected*
55
+ * target path, not an existence check — same semantics and null encoding as
56
+ * `LocatedStatusIssue.cognitionPath`.
57
+ */
58
+ cognitionPath: string | null;
59
+ /** Absolute cognition URI key string; `null` on a miss or when the node has
60
+ * no expected cognition URI. */
61
+ cognitionUri: string | null;
62
+ /**
63
+ * Whole-node observed status: the worst of `ownStatus` and `descendantStatus`
64
+ * by `fresh` < `stale` < `conflict`. `null` means "no cognition" (neither the
65
+ * node nor any tracked descendant has an observed status).
66
+ */
67
+ status: ObservedStatus | null;
68
+ /**
69
+ * This node's own observed status, before descendant aggregation; `null`
70
+ * means "no own cognition".
71
+ */
72
+ ownStatus: ObservedStatus | null;
73
+ /**
74
+ * Worst observed status over descendants with an observed status (the
75
+ * tracked node-status subset) by `fresh` < `stale` < `conflict`. `null` means
76
+ * no descendant in that subset has an observed status (untracked descendants
77
+ * are skipped) — not "no cognition".
78
+ */
79
+ descendantStatus: ObservedStatus | null;
80
+ staleAction: StaleAction | null;
81
+ issueCount: number;
82
+ ownIssueCount: number;
83
+ descendantIssueCount: number;
84
+ issues: CoggitOperationIssue[];
85
+ suggestedActions: CoggitOperationAction[];
86
+ handbookId: 'leaf' | 'skeleton' | null;
87
+ /** `null` on a miss; the matched tree node on a hit. */
88
+ node: CoggitTreeNode | null;
89
+ /** Fuzzy source-path hints when the source path matched no node. Empty when found. */
90
+ pathHints: string[];
91
+ /** Present only when the source path matched no node. */
92
+ pathMissMessage?: string;
93
+ /** Present only when a miss produced fuzzy hints. */
94
+ pathHintMessage?: string;
95
+ /** Canonical status inspection when the node was found.
96
+ * undefined when found is false. */
97
+ inspection?: NodeStatusInspection | undefined;
98
+ }
99
+ export declare const ADD_OPERATION_ERROR_CODES: readonly ["no-projects", "path-not-found", "invalid-kind", "mapping-conflict", "filesystem-failure", "unknown"];
100
+ export type AddOperationErrorCode = typeof ADD_OPERATION_ERROR_CODES[number];
101
+ export interface AddOperationError {
102
+ code: AddOperationErrorCode;
103
+ message: string;
104
+ }
105
+ export interface AddOperationResult {
106
+ success: boolean;
107
+ /** Whether the add materialized a new cognition file; `null` on failure. */
108
+ created: boolean | null;
109
+ /** Created cognition kind on success; `null` on failure. */
110
+ kind: CognitionKind | null;
111
+ /** Project-root-relative source path. */
112
+ sourcePath: string;
113
+ /** Absolute source URI key string; `null` on failure. */
114
+ sourceUri: string | null;
115
+ /** Expected paired cognition path, project-root-relative; `null` on
116
+ * failure (no path materialized). */
117
+ cognitionPath: string | null;
118
+ /** Absolute cognition URI key string; `null` on failure. */
119
+ cognitionUri: string | null;
120
+ /** `null` on a miss or `no-projects`. */
121
+ project: CoggitProjectContext | null;
122
+ handbookId: 'leaf' | 'skeleton' | null;
123
+ suggestedActions: CoggitOperationAction[];
124
+ /** `null` on success; typed failure details on failure. */
125
+ error: AddOperationError | null;
126
+ /** Fuzzy source-path hints when the source path matched no node. Empty when found. */
127
+ pathHints: string[];
128
+ /** Present only when the source path matched no node. */
129
+ pathMissMessage?: string;
130
+ /** Present only when a miss produced fuzzy hints. */
131
+ pathHintMessage?: string;
132
+ }
133
+ /**
134
+ * Resolve failure codes.
135
+ *
136
+ * - `content-changed`: the source/cognition pair changed during the resolve
137
+ * acceptance window. The guard compares the accepted-pair identity captured
138
+ * before and after the accept write — the registry `sourceKey` plus the
139
+ * `source` and `cognition` content identities (SHA-256 content hashes, not
140
+ * mtimes) — covering both the source and cognition sides.
141
+ * - `registry-changed`: the registry revision changed during the accept write;
142
+ * the acceptance was not committed.
143
+ * - `registry-unavailable`: no registry could be loaded.
144
+ * - `path-not-found`: the source path matched no node.
145
+ * - `no-projects`: no CogGit project is open.
146
+ * - `unknown`: any other failure.
147
+ */
148
+ export declare const RESOLVE_ERROR_CODES: readonly ["no-projects", "path-not-found", "registry-unavailable", "registry-changed", "content-changed", "unknown"];
149
+ export type ResolveErrorCode = typeof RESOLVE_ERROR_CODES[number];
150
+ export interface ResolveOperationError {
151
+ code: ResolveErrorCode;
152
+ message: string;
153
+ }
154
+ export interface ResolveOperationResult {
155
+ success: boolean;
156
+ /** Project-root-relative source path. */
157
+ sourcePath: string;
158
+ /** Absolute source URI key string; `null` when the node could not be re-read. */
159
+ sourceUri: string | null;
160
+ /** Expected paired cognition path, project-root-relative; `null` when the
161
+ * node could not be re-read after acceptance. */
162
+ cognitionPath: string | null;
163
+ /** Absolute cognition URI key string; `null` when the node could not be re-read. */
164
+ cognitionUri: string | null;
165
+ /** `null` on a miss or `no-projects`. */
166
+ project: CoggitProjectContext | null;
167
+ /** Registry key written on success; `null` on failure. */
168
+ sourceKey: string | null;
169
+ /** Acceptance timestamp written on success; `null` on failure. */
170
+ verificationTimeMs: number | null;
171
+ suggestedActions: CoggitOperationAction[];
172
+ /** `null` on success; typed failure details on failure. */
173
+ error: ResolveOperationError | null;
174
+ /** Fuzzy source-path hints when the source path matched no node. Empty when found. */
175
+ pathHints: string[];
176
+ /** Present only when the source path matched no node. */
177
+ pathMissMessage?: string;
178
+ /** Present only when a miss produced fuzzy hints. */
179
+ pathHintMessage?: string;
180
+ }
181
+ export interface RoutesOperationResult {
182
+ project: CoggitProjectContext;
183
+ generatedAt: number;
184
+ entryCount: number;
185
+ entries: CognitionRoutesEntry[];
186
+ diagnostics: CognitionDocumentDiagnostic[];
187
+ routes: CognitionRoutes;
188
+ }
189
+ export declare function projectContext(project: CoggitProject): CoggitProjectContext;
190
+ export declare function handbookCatalog(): CoggitHandbookCatalogEntry[];
191
+ export declare function handbookIdForNodeKind(kind: CoggitNodeKind): 'leaf' | 'skeleton';
192
+ export declare function handbookIdForCognitionKind(kind: CognitionKind): 'leaf' | 'skeleton';
193
+ export declare function findProjectNode(projects: readonly CoggitProject[], sourcePath: string): Promise<{
194
+ project: CoggitProject;
195
+ node: CoggitTreeNode;
196
+ } | undefined>;
197
+ /** Expand a raw input path into candidate source-root-relative paths to try, per project. */
198
+ export type SourcePathCandidatesExpander = (project: CoggitProject, sourcePath: string) => readonly string[];
199
+ export interface SnapshotOperationOptions {
200
+ sourcePath?: string;
201
+ scope?: SnapshotOperationScope;
202
+ maxDepth?: number;
203
+ sourcePathCandidates?: SourcePathCandidatesExpander;
204
+ }
205
+ export declare function snapshotOperation(projects: readonly CoggitProject[], options?: SnapshotOperationOptions): Promise<SnapshotOperationResult>;
206
+ export interface StatusOperationOptions {
207
+ sourcePathCandidates?: SourcePathCandidatesExpander;
208
+ issueVisibility?: StatusIssueVisibility;
209
+ /**
210
+ * Optional pre-built combined snapshot (from `buildSnapshotFromProjects`).
211
+ * When provided, `statusOperation` resolves `sourcePath` against it instead
212
+ * of rebuilding the tree per project. The caller owns snapshot freshness:
213
+ * pass a snapshot built in the same turn as the mutation that precedes it;
214
+ * do not reuse a snapshot across writes (reconcile-on-read semantics).
215
+ */
216
+ snapshot?: CoggitSnapshot;
217
+ }
218
+ export declare function statusOperation(projects: readonly CoggitProject[], sourcePath: string, options?: StatusOperationOptions): Promise<StatusOperationResult>;
219
+ export declare function addOperation(projects: readonly CoggitProject[], sourcePath: string, options?: {
220
+ kind?: AddCognitionKind;
221
+ overwrite?: boolean;
222
+ sourcePathCandidates?: SourcePathCandidatesExpander;
223
+ }): Promise<AddOperationResult>;
224
+ export declare function resolveOperation(projects: readonly CoggitProject[], sourcePath: string, options?: {
225
+ sourcePathCandidates?: SourcePathCandidatesExpander;
226
+ }): Promise<ResolveOperationResult>;
227
+ export declare function routesOperation(project: CoggitProject, options?: Parameters<CoggitProject['buildCognitionRoutes']>[0]): Promise<RoutesOperationResult>;
228
+ export declare function operationIssue(located: LocatedStatusIssue): CoggitOperationIssue;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Pure-JS path utilities — no Node.js dependency.
3
+ * Replaces `node:path` in core for cross-platform compatibility.
4
+ *
5
+ * Implements only the subset of `node:path` used by core/mapping.ts.
6
+ */
7
+ export declare function isAbsolute(p: string): boolean;
8
+ export declare function dirname(p: string): string;
9
+ export declare function basename(p: string): string;
10
+ export declare function normalize(p: string): string;
11
+ export declare function resolve(...segments: string[]): string;
12
+ export declare function relative(from: string, to: string): string;
13
+ export declare function join(...segments: string[]): string;
14
+ export declare const posix: {
15
+ isAbsolute(p: string): boolean;
16
+ parse(p: string): {
17
+ dir: string;
18
+ name: string;
19
+ ext: string;
20
+ };
21
+ join(...segments: string[]): string;
22
+ normalize(p: string): string;
23
+ };
24
+ export declare const win32: {
25
+ isAbsolute(p: string): boolean;
26
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Fuzzy source-path hint suggestions, shared by routes, status, and snapshot.
3
+ *
4
+ * When a source path matches nothing, segment-suffix matching suggests the
5
+ * closest existing source paths. A miss like `src/core/watchPipeline.ts` can
6
+ * suggest the source-root-relative path `coggit/src/core/watchPipeline.ts`
7
+ * because their trailing segments match.
8
+ *
9
+ * Hints are suggestions for caller re-decision, never automatic rewrites:
10
+ * the caller chooses whether to re-run against a suggested path.
11
+ */
12
+ /**
13
+ * Collect up to five candidate paths whose trailing segments match the
14
+ * source path. Returns an empty array when nothing matches.
15
+ */
16
+ export declare function suggestPathHints(candidatePaths: Iterable<string>, sourcePath: string): string[];
17
+ /** Canonical bare sentence (no path) for a source path that matched no node. */
18
+ export declare const PATH_MISS_MESSAGE = "Path not found in any CogGit project.";
19
+ /** Canonical lead-in for the fuzzy-hint suggestion line. */
20
+ export declare const PATH_HINT_MESSAGE = "You may mean one of these source-root-relative source paths.";
21
+ /** Full miss line including the source path, e.g. `Path not found in any CogGit project: src/main.ts`. */
22
+ export declare function pathMissMessage(sourcePath: string): string;
23
+ /** Render the backtick-wrapped hint list: `` `a`, `b` ``. */
24
+ export declare function pathHintsTryText(pathHints: readonly string[]): string;
25
+ /** Render the full miss line plus optional hint suggestion lines. */
26
+ export declare function renderPathMissText(result: {
27
+ sourcePath: string | null;
28
+ pathMissMessage?: string;
29
+ pathHintMessage?: string;
30
+ pathHints: readonly string[];
31
+ }): string;
@@ -0,0 +1,10 @@
1
+ import type { CoggitSnapshot } from '../types';
2
+ import type { ConfigProvider, FileSystem } from '../interfaces';
3
+ /**
4
+ * One-shot reconcile-on-read snapshot for a bare fs+config consumer.
5
+ *
6
+ * This is the minimal public entry point for a runtime that owns its own
7
+ * `FileSystem` and `ConfigProvider` adapters but does not need the full
8
+ * `CoggitProject` facade lifecycle.
9
+ */
10
+ export declare function buildSnapshot(fs: FileSystem, config: ConfigProvider): Promise<CoggitSnapshot>;
@@ -0,0 +1,32 @@
1
+ import type { FileSystem, UriComponents } from '../interfaces';
2
+ /**
3
+ * Result of a successful `findProjectRoot` call.
4
+ *
5
+ * `configUri` points to the `.coggit/config.yaml` that was found.
6
+ * `projectRootUri` is the directory containing the `.coggit/` folder
7
+ * (i.e. `dirname(dirname(configUri.path))`).
8
+ *
9
+ * Callers that need `sourceRootUri`/`cognitionRootUri` should parse
10
+ * the YAML at `configUri` and resolve relative paths from `projectRootUri`.
11
+ */
12
+ export interface ProjectRoot {
13
+ configUri: UriComponents;
14
+ projectRootUri: UriComponents;
15
+ }
16
+ /**
17
+ * Walk up from `startUri` to find the nearest enclosing `.coggit/config.yaml`.
18
+ *
19
+ * Analogous to Git's `rev-parse --git-dir` — a lightweight path-anchoring
20
+ * primitive that discovers which coggit project a file or directory belongs to.
21
+ *
22
+ * Core-layer function: depends only on `FileSystem` and `UriComponents`.
23
+ * No host runtime (VS Code / Node) dependency.
24
+ *
25
+ * @param startUri The URI to start from (file or directory).
26
+ * @param fs The FileSystem abstraction for existence checks.
27
+ * @param options Optional `{ maxWalkDepth }` to limit the upward walk.
28
+ * @returns The `ProjectRoot` if found, or `undefined` if the walk exhausted.
29
+ */
30
+ export declare function findProjectRoot(startUri: UriComponents, fs: FileSystem, options?: {
31
+ maxWalkDepth?: number;
32
+ }): Promise<ProjectRoot | undefined>;
@@ -0,0 +1,8 @@
1
+ export { ResolveAcceptanceError, RuntimeAcceptanceEvidence, createCoggitServices, discoverCoggitProjects, openCoggitProject, buildSnapshotFromProjects, parentUri, resolveNodeInSnapshot, } from './project';
2
+ export type { CoggitProjectDiscoveryOptions, RegistryInitFailurePolicy, } from './project';
3
+ export { projectContextFromRoot, projectContext } from './projectContext';
4
+ export { findProjectRoot } from './discover';
5
+ export type { ProjectRoot } from './discover';
6
+ export { discoverWorkspaceRoots, readWorkspaceRoot } from './workspace';
7
+ export { initProject } from './init';
8
+ export { buildSnapshot } from './buildSnapshot';
@@ -0,0 +1,22 @@
1
+ import type { FileSystem, UriComponents } from '../interfaces';
2
+ /**
3
+ * Initialize a coggit project at the given project root.
4
+ *
5
+ * Creates `.coggit/config.yaml`, the cognition root directory, and ensures
6
+ * `.gitignore` has the right coggit entries so cache files don't leak in
7
+ * and users are reminded not to gitignore `.coggit/` itself.
8
+ *
9
+ * Core-layer function: takes a `FileSystem` abstraction and `UriComponents`,
10
+ * making it portable across VS Code, CLI, and tests. Callers are responsible
11
+ * for converting string paths to `UriComponents` before calling this function.
12
+ *
13
+ * @param fs The filesystem abstraction to use for all I/O.
14
+ * @param projectRoot URI of the project root (the directory that will contain
15
+ * the `.coggit/` folder).
16
+ * @param overrides Optional `{ sourceRoot, cognitionRoot }` to override the
17
+ * defaults (`"src"` / `"src_cognition"`).
18
+ */
19
+ export declare function initProject(fs: FileSystem, projectRoot: UriComponents, overrides?: {
20
+ sourceRoot?: string;
21
+ cognitionRoot?: string;
22
+ }): Promise<void>;
@@ -0,0 +1,44 @@
1
+ import type { CoggitProject, CoggitServices, SourcePathResolution, UriComponents } from '../interfaces';
2
+ import type { CoggitLogger } from '../logger';
3
+ import type { AcceptedPair, CoggitSnapshot, CoggitWorkspaceRoot } from '../types';
4
+ /**
5
+ * Raised by `markResolved` when the acceptance operation fails after the source
6
+ * path has already resolved to a node. Carries the canonical source-root-relative
7
+ * node path (`node.relativePath`) so callers can echo a canonical path on
8
+ * post-resolution failures instead of the raw caller input.
9
+ */
10
+ export declare class ResolveAcceptanceError extends Error {
11
+ readonly canonicalSourcePath: string;
12
+ constructor(message: string, canonicalSourcePath: string, cause?: unknown);
13
+ }
14
+ export type RegistryInitFailurePolicy = 'degrade' | 'throw';
15
+ export interface CoggitProjectDiscoveryOptions {
16
+ /** How project-open registry reconciliation failures are surfaced. */
17
+ readonly registryInitFailure?: RegistryInitFailurePolicy;
18
+ /** Host-local ordering evidence reused across project runtime rebuilds. */
19
+ readonly runtimeEvidence?: (root: CoggitWorkspaceRoot) => RuntimeAcceptanceEvidence;
20
+ }
21
+ export declare class RuntimeAcceptanceEvidence {
22
+ private readonly records;
23
+ private fallbackGeneration;
24
+ normalizeGeneration(generation: number | undefined): number;
25
+ beginSource(key: string, generation: number): void;
26
+ completeSource(key: string, generation: number, identity: AcceptedPair['source']): boolean;
27
+ recordCognition(key: string, generation: number): void;
28
+ hasSourceBeforeCognition(key: string, pair: AcceptedPair): boolean;
29
+ clear(key: string): void;
30
+ }
31
+ export declare function createCoggitServices(services: CoggitServices): CoggitServices;
32
+ export declare function createCoggitServices(fs: CoggitServices['fs'], config: CoggitServices['config'], registry?: CoggitServices['registry'], logger?: CoggitLogger, locks?: CoggitServices['locks']): CoggitServices;
33
+ export declare function discoverCoggitProjects(services: CoggitServices, options?: CoggitProjectDiscoveryOptions): Promise<CoggitProject[]>;
34
+ export declare function openCoggitProject(services: CoggitServices, root: CoggitWorkspaceRoot, options?: CoggitProjectDiscoveryOptions): Promise<CoggitProject>;
35
+ export declare function buildSnapshotFromProjects(projects: readonly CoggitProject[]): Promise<CoggitSnapshot>;
36
+ /**
37
+ * Resolve a source path against an already-built snapshot, scoped to one
38
+ * project root. Shared by `resolveProjectNode` (which builds the snapshot
39
+ * first) and `statusOperation`'s snapshot-reuse path (which receives a
40
+ * pre-built combined snapshot from `buildSnapshotFromProjects`).
41
+ */
42
+ export declare function resolveNodeInSnapshot(snapshot: CoggitSnapshot, root: CoggitWorkspaceRoot, sourcePath: string): SourcePathResolution;
43
+ /** Return the parent URI (directory) of a given URI. */
44
+ export declare function parentUri(uri: UriComponents): UriComponents;
@@ -0,0 +1,4 @@
1
+ import type { CoggitProject } from '../interfaces';
2
+ import type { CoggitProjectContext, CoggitWorkspaceRoot } from '../types';
3
+ export declare function projectContextFromRoot(root: CoggitWorkspaceRoot): CoggitProjectContext;
4
+ export declare function projectContext(project: CoggitProject): CoggitProjectContext;