@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,37 @@
1
+ import type { NodeStatusInspection } from './statusTypes';
2
+ export type StatusAgentActionRole = 'recommended' | 'optional-on-demand' | 'diagnostic';
3
+ export type StatusAgentSeverityLevel = 'INFO' | 'WARN' | 'ERROR';
4
+ export interface StatusAgentIssueLegendEntry {
5
+ level: StatusAgentSeverityLevel;
6
+ tag: string;
7
+ description: string;
8
+ /** Label-only remediation action codes for this issue tag, rendered as `hint=`. */
9
+ hints: string[];
10
+ }
11
+ export interface StatusAgentActionLegendEntry {
12
+ tag: string;
13
+ role: StatusAgentActionRole;
14
+ description: string;
15
+ }
16
+ export interface StatusAgentIssueRow {
17
+ level: StatusAgentSeverityLevel;
18
+ issueTags: string[];
19
+ sourcePath: string;
20
+ actionTags: string[];
21
+ optionalActionTags: string[];
22
+ }
23
+ export interface StatusAgentPresentation {
24
+ sourcePath: string;
25
+ cognitionPath: string | null;
26
+ cognitionPresence: NodeStatusInspection['cognitionPresence'];
27
+ status: NodeStatusInspection['status'];
28
+ ownIssueCount: number;
29
+ descendantIssueCount: number;
30
+ ownIssues: StatusAgentIssueRow[];
31
+ descendantIssues: StatusAgentIssueRow[];
32
+ issueLegend: StatusAgentIssueLegendEntry[];
33
+ actionLegend: StatusAgentActionLegendEntry[];
34
+ }
35
+ export declare function projectStatusAgentPresentation(inspection: NodeStatusInspection): StatusAgentPresentation;
36
+ export declare function renderStatusAgentPresentation(view: StatusAgentPresentation): string;
37
+ export declare function renderStatusAgentInspectionText(inspection: NodeStatusInspection): string;
@@ -0,0 +1,43 @@
1
+ import type { CognitionCoveragePresence, LocatedStatusIssue, NodeStatusInspection, ObservedStatus } from './statusTypes';
2
+ export type StatusPresentationFormat = 'text' | 'markdown';
3
+ export interface StatusPresentationIssue {
4
+ sourcePath: string;
5
+ cognitionPath: string | null;
6
+ severity: 'info' | 'warning' | 'error';
7
+ message: string;
8
+ suggestedActions: string[];
9
+ }
10
+ export interface StatusPresentationView {
11
+ sourcePath: string;
12
+ cognitionPath: string | null;
13
+ cognitionPresence: CognitionCoveragePresence;
14
+ status: ObservedStatus | null;
15
+ ownStatus: ObservedStatus | null;
16
+ descendantStatus: ObservedStatus | null;
17
+ ownIssues: StatusPresentationIssue[];
18
+ descendantIssues: StatusPresentationIssue[];
19
+ }
20
+ /** Map located issues into the serializable presentation issue shape. Shared
21
+ * by the single-node presentation view and the subtree triage projection so
22
+ * both keep the same null encoding and field conventions. */
23
+ export declare function mapStatusPresentationIssues(issues: readonly LocatedStatusIssue[]): StatusPresentationIssue[];
24
+ export declare function projectStatusPresentation(inspection: NodeStatusInspection): StatusPresentationView;
25
+ /** Adapter-ready structured view for a status miss: the requested source path
26
+ * plus recovery guidance (`pathHints`, miss/hint messages). Complements
27
+ * `StatusPresentationView` (the inspection-backed HIT view). */
28
+ export interface StatusMissPresentation {
29
+ sourcePath: string;
30
+ pathHints: string[];
31
+ pathMissMessage?: string;
32
+ pathHintMessage?: string;
33
+ }
34
+ /** Project a status miss into an adapter-ready structured view. A miss has no
35
+ * inspection, so this carries the lookup identity and recovery guidance without
36
+ * requiring each adapter to assemble its own fallback shape. */
37
+ export declare function projectStatusMissPresentation(result: {
38
+ sourcePath: string;
39
+ pathHints: readonly string[];
40
+ pathMissMessage?: string;
41
+ pathHintMessage?: string;
42
+ }): StatusMissPresentation;
43
+ export declare function renderStatusPresentation(view: StatusPresentationView, format?: StatusPresentationFormat): string;
@@ -0,0 +1,50 @@
1
+ import type { CoggitOperationAction } from '../operationTypes';
2
+ import type { CoggitNodeKind } from '../snapshotTypes';
3
+ import type { NodeStatusInspection } from './statusTypes';
4
+ import { type StatusPresentationIssue } from './statusPresentation';
5
+ /**
6
+ * Adapter-ready subtree triage view for a status hit: one entry per
7
+ * issue-bearing node in the inspected node's projected issue set, grouping
8
+ * that node's issues with its node-scoped next-step actions. Lets an adapter
9
+ * answer "which descendants need attention, with what action and handbook
10
+ * guidance" from one folder/root status call, without per-descendant
11
+ * re-inspection.
12
+ */
13
+ export interface StatusTriageView {
14
+ /** Project-root-relative path of the inspected node. */
15
+ sourcePath: string;
16
+ /** Total projected issue count over the inspected node and its subtree. */
17
+ issueCount: number;
18
+ entries: StatusTriageEntry[];
19
+ }
20
+ export interface StatusTriageEntry {
21
+ sourcePath: string;
22
+ /** Expected paired cognition path; same expected-path semantics and null
23
+ * encoding as `StatusPresentationView.cognitionPath`. */
24
+ cognitionPath: string | null;
25
+ nodeKind: CoggitNodeKind;
26
+ relation: 'own' | 'descendant';
27
+ issues: StatusPresentationIssue[];
28
+ /**
29
+ * Node-scoped workflow actions. Facts-only (`[]`) for the own entry: the
30
+ * inspected node's next steps remain exclusively in the top-level
31
+ * `suggestedActions` channel. Handbook guidance rides the action-level
32
+ * `handbookId` (ISSUE 20260819-2200); no parallel entry-level handbook
33
+ * representation exists.
34
+ */
35
+ suggestedActions: CoggitOperationAction[];
36
+ }
37
+ /**
38
+ * Project an inspection's synthesized triage facts into the adapter-ready
39
+ * subtree triage view. Pure projection: the node-signal synthesis of
40
+ * descendant-scoped actions happens in `status/` during inspection (which is
41
+ * why this consumes the inspection, whose `triage` entries carry the matched
42
+ * tree nodes' synthesized actions, rather than re-deriving actions from
43
+ * `subtreeIssues`).
44
+ *
45
+ * This is a workflow/triage contract adjacent to the presentation, not a
46
+ * `StatusPresentationView` scope variant: the presentation stays the
47
+ * single-node fact projection, and adapters must not reintroduce `own` or
48
+ * `subtree` presentation variants through it.
49
+ */
50
+ export declare function projectStatusTriage(inspection: NodeStatusInspection): StatusTriageView;
@@ -0,0 +1,240 @@
1
+ import type { UriComponents } from '../interfaces';
2
+ import type { CoggitOperationAction } from '../operationTypes';
3
+ import type { CoggitNodeKind } from '../snapshotTypes';
4
+ import type { AcceptedPair } from '../registryTypes';
5
+ export type ObservedStatus = 'fresh' | 'stale' | 'conflict';
6
+ export type SourceFactKind = 'file-content' | 'directory-entry';
7
+ export interface EvidenceDiagnostic {
8
+ code: 'missing-cognition' | 'template-cognition' | 'outdated-cognition' | 'folder-structure-changed' | 'missing-coverage' | 'broken-links' | 'metadata-broken' | 'source-deleted' | 'conflicting-evidence' | 'folder-structure-outdated';
9
+ severity: 'info' | 'warning' | 'error';
10
+ message: string;
11
+ relatedPaths?: string[];
12
+ }
13
+ export interface StatusAction {
14
+ label: string;
15
+ }
16
+ export interface StatusIssue {
17
+ diagnostic: EvidenceDiagnostic;
18
+ actions: StatusAction[];
19
+ }
20
+ export type CognitionCoveragePresence = 'present' | 'missing' | 'not-applicable';
21
+ export interface CoverageSignals {
22
+ ownCognition: CognitionCoveragePresence;
23
+ isMaterializable: boolean;
24
+ missingMaterializableCount: number;
25
+ coveredCount: number;
26
+ }
27
+ export type MaintenanceRecommendation = 'none' | 'optional' | 'recommended' | 'urgent';
28
+ export type StaleAction = 'align-cognition-first';
29
+ export interface NodeStatusResult {
30
+ observedStatus?: ObservedStatus;
31
+ ownObservedStatus?: ObservedStatus;
32
+ descendantObservedStatus?: ObservedStatus;
33
+ staleAction?: StaleAction;
34
+ /** Own-node issues only. Subtree diagnostics are queried with collectSubtreeIssues(). */
35
+ issues?: StatusIssue[];
36
+ coverage?: CoverageSignals;
37
+ computedAt?: number;
38
+ }
39
+ export interface LocatedStatusIssue {
40
+ nodeId: string;
41
+ nodeKind: CoggitNodeKind;
42
+ sourceUri: UriComponents;
43
+ /** Expected paired cognition URI. Optional: absent for nodes with no
44
+ * expected cognition URI (e.g. the `error` node kind built by
45
+ * `createErrorNode`); mirrors `CoggitTreeNode.cognitionUri`. */
46
+ cognitionUri?: UriComponents;
47
+ /**
48
+ * Expected paired cognition path, project-root-relative. Non-null for any
49
+ * real node (derived from the node's `cognitionUri`); `null` only for nodes
50
+ * with no `cognitionUri`. This is the *expected* target path — it does not
51
+ * assert that the document exists. Null is encoded as `null` (not
52
+ * `undefined`) to match `StatusOperationResult.cognitionPath`: the two
53
+ * fields share one meaning, so they share one null encoding.
54
+ */
55
+ cognitionPath: string | null;
56
+ /** Project-root-relative source path of the issue-bearing node. */
57
+ relativePath: string;
58
+ hasPairedCognition?: boolean;
59
+ issue: StatusIssue;
60
+ }
61
+ export interface SubtreeIssueQueryResult {
62
+ ownIssues: LocatedStatusIssue[];
63
+ descendantIssues: LocatedStatusIssue[];
64
+ totalIssues: number;
65
+ }
66
+ export type StatusIssueVisibility = 'maintained' | 'all';
67
+ export type ReasonKind = 'outdated-mtime' | 'source-changed' | 'unverified' | 'broken-links' | 'missing-coverage' | 'missing-metadata' | 'corrupted-metadata' | 'dep-mismatch' | 'semantic-edge-changed' | 'acceptance-order-unknown' | 'symbol-changed' | 'structural-edge-changed' | 'source-deleted' | 'source-renamed';
68
+ export interface Reason {
69
+ kind: ReasonKind;
70
+ severity: 'info' | 'warning' | 'error';
71
+ message: string;
72
+ relatedPaths?: string[];
73
+ }
74
+ export interface SourceFactIdentity {
75
+ kind: SourceFactKind;
76
+ currentHash: string;
77
+ }
78
+ export interface TextMetrics {
79
+ charLength: number;
80
+ lineCount: number;
81
+ nonEmptyLineCount: number;
82
+ }
83
+ export interface SourceChangeMetrics {
84
+ basis: 'unavailable' | 'git-diff' | 'snapshot';
85
+ changedLines: number | null;
86
+ changeRatio: number | null;
87
+ }
88
+ export interface StaleDegreeResult {
89
+ availability: 'available' | 'unavailable' | 'not-applicable';
90
+ score: number | null;
91
+ recommendation: MaintenanceRecommendation | null;
92
+ confidence: 'none' | 'low' | 'medium' | 'high';
93
+ reason: string;
94
+ }
95
+ export interface Evidence {
96
+ sourceMtimeMs: number;
97
+ sourceBlobHash: string;
98
+ cognitionMtimeMs: number | null;
99
+ verificationTimeMs?: number | null;
100
+ sourceFactIdentity: SourceFactIdentity;
101
+ acceptedPair?: AcceptedPair | null;
102
+ cognitionBlobHash?: string | null;
103
+ cognitionChangedSinceAccepted?: boolean;
104
+ sourceChangedSinceAccepted?: boolean;
105
+ sourceMetrics: TextMetrics;
106
+ cognitionMetrics: TextMetrics | null;
107
+ changeMetrics: SourceChangeMetrics;
108
+ changedSymbols: string[];
109
+ brokenLinks: LinkCheckResult[];
110
+ gitCommitsSinceVerified: number;
111
+ /** Whether cognition exists but still has only template-like content. */
112
+ cognitionContentIsTemplate: boolean;
113
+ /** Orphan detection: cognition exists while source no longer exists. */
114
+ sourceDeleted: boolean;
115
+ }
116
+ export interface StatusResult {
117
+ observedStatus?: ObservedStatus;
118
+ ownObservedStatus?: ObservedStatus;
119
+ staleAction?: StaleAction;
120
+ issues: StatusIssue[];
121
+ coverage: CoverageSignals;
122
+ reasons: Reason[];
123
+ evidence: Evidence;
124
+ computedAt: number;
125
+ }
126
+ /**
127
+ * Per-node triage fact synthesized during inspection: one entry per
128
+ * issue-bearing node in the projected issue set, grouping that node's issues
129
+ * with its node-scoped workflow actions. This is the subtree-maintenance
130
+ * counterpart to the single-node `suggestedActions` channel; the
131
+ * [[statusTriage.ts]] projection maps these facts into the adapter-ready
132
+ * `StatusTriageView`.
133
+ */
134
+ export interface NodeStatusTriageEntry {
135
+ /** Project-root-relative path of the issue-bearing node. */
136
+ sourcePath: string;
137
+ /**
138
+ * Expected paired cognition path, project-root-relative; same expected-path
139
+ * semantics and null encoding as `NodeStatusInspection.cognitionPath`.
140
+ */
141
+ cognitionPath: string | null;
142
+ nodeKind: CoggitNodeKind;
143
+ /** Whether this entry is the inspected node itself or a descendant. */
144
+ relation: 'own' | 'descendant';
145
+ /** This node's issues under the selected issue visibility. */
146
+ issues: LocatedStatusIssue[];
147
+ /**
148
+ * Node-scoped workflow actions synthesized from this node's own
149
+ * status/coverage signals. Structured-only (carries `operation` or
150
+ * `handbookId`): label-only issue guidance stays in the entry's
151
+ * `issues[].issue.actions` and is never echoed here, so consumers never
152
+ * re-judge which actions are workflow. The own entry is facts-only and
153
+ * always `[]`: the inspected node's next steps remain exclusively in the
154
+ * top-level `suggestedActions` channel, so no action appears in two
155
+ * channels. Error nodes carry no synthesized actions.
156
+ */
157
+ actions: CoggitOperationAction[];
158
+ }
159
+ export interface NodeStatusInspection {
160
+ /** Project-root-relative source path of the inspected node. */
161
+ sourcePath: string;
162
+ /**
163
+ * Expected paired cognition path, project-root-relative; `null` only when
164
+ * the node has no expected cognition URI. This is the *expected* target
165
+ * path, not an existence check — pair it with `cognitionPresence`.
166
+ */
167
+ cognitionPath: string | null;
168
+ cognitionPresence: CognitionCoveragePresence;
169
+ nodeKind: CoggitNodeKind;
170
+ /**
171
+ * Whole-node observed status: the worst of `ownStatus` and `descendantStatus`
172
+ * by `fresh` < `stale` < `conflict`. `null` means "no cognition" (neither the
173
+ * node nor any tracked descendant has an observed status).
174
+ */
175
+ status: ObservedStatus | null;
176
+ /**
177
+ * This node's own observed status, before descendant aggregation; `null`
178
+ * means "no own cognition".
179
+ */
180
+ ownStatus: ObservedStatus | null;
181
+ /**
182
+ * Worst observed status over descendants with an observed status (the
183
+ * tracked node-status subset) by `fresh` < `stale` < `conflict`. `null` means
184
+ * no descendant in that subset has an observed status (untracked descendants
185
+ * are skipped) — not "no cognition".
186
+ */
187
+ descendantStatus: ObservedStatus | null;
188
+ issueSummary: {
189
+ total: number;
190
+ own: number;
191
+ descendant: number;
192
+ };
193
+ /** Always present with `own`/`descendant` arrays; `[]` means "none". */
194
+ subtreeIssues: {
195
+ own: LocatedStatusIssue[];
196
+ descendant: LocatedStatusIssue[];
197
+ };
198
+ suggestedActions: CoggitOperationAction[];
199
+ /**
200
+ * One entry per issue-bearing node in the projected issue set: the own
201
+ * entry first (when the inspected node has issues), then descendant entries
202
+ * in subtree collection order. Descendant entries carry node-scoped actions
203
+ * synthesized from node signals; adapters render subtree workflow from these
204
+ * entries, not from `suggestedActions`.
205
+ */
206
+ triage: NodeStatusTriageEntry[];
207
+ handbookId: 'leaf' | 'skeleton' | null;
208
+ }
209
+ export interface SourceFileInfo {
210
+ uri: string;
211
+ mtimeMs: number;
212
+ content: string;
213
+ blobHash: string;
214
+ sourceFactKind?: SourceFactKind;
215
+ publicSymbols: string[];
216
+ dependencies: string[];
217
+ }
218
+ export interface CognitionFileInfo {
219
+ uri: string;
220
+ mtimeMs: number | null;
221
+ content: string | null;
222
+ verificationTimeMs?: number | null;
223
+ acceptedPair?: AcceptedPair | null;
224
+ links: Array<{
225
+ text: string;
226
+ target: string;
227
+ }>;
228
+ brokenLinks: LinkCheckResult[];
229
+ }
230
+ export interface LinkCheckResult {
231
+ text: string;
232
+ target: string;
233
+ reason: 'not-found' | 'external' | 'cyclic' | 'invalid-format';
234
+ sourceLine: number;
235
+ }
236
+ export interface StatusContext {
237
+ symbolIndex: Map<string, string[]>;
238
+ linkIndex: Map<string, LinkCheckResult[]>;
239
+ depGraph: Map<string, string[]>;
240
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Surface-neutral system prompt assets for CogGit hosts.
3
+ *
4
+ * A "system prompt" is the short guidance a host injects so an agent knows
5
+ * CogGit exists and how to approach it. Forms range from a short hint
6
+ * (minimal) to fuller operational instructions. Every form is surface-neutral:
7
+ * it names CogGit as the project, references CLI-baseline commands only, and
8
+ * never hard-codes a specific surface's tool names, resource URIs, or
9
+ * addressing (`coggit_*`, `coggit://`). Hosts that need surface-specific
10
+ * wording re-address these forms themselves (see the TODO below).
11
+ */
12
+ export type CoggitSystemPromptKind = 'minimal';
13
+ export interface CoggitSystemPrompt {
14
+ kind: CoggitSystemPromptKind;
15
+ version: 'system-prompt-v1';
16
+ content: string;
17
+ }
18
+ /**
19
+ * The minimal form: the essential identity of CogGit — the mirrored cognition
20
+ * layer and what it records — plus the keep-it-current directive, without
21
+ * prescribing a workflow.
22
+ */
23
+ export declare const MINIMAL_SYSTEM_PROMPT: CoggitSystemPrompt;
24
+ export declare function getCoggitSystemPrompt(kind?: CoggitSystemPromptKind): CoggitSystemPrompt;
package/dist/time.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function formatTimestamp(value: number | null, noneLabel: string): string;
2
+ export declare function latestAcceptedTime(cognitionMtimeMs: number | null, verificationTimeMs: number | null): number | null;
@@ -0,0 +1,5 @@
1
+ export type { ObservedStatus, SourceFactKind, EvidenceDiagnostic, StatusAction, StatusIssue, CognitionCoveragePresence, CoverageSignals, MaintenanceRecommendation, StaleAction, NodeStatusResult, LocatedStatusIssue, StatusIssueVisibility, SubtreeIssueQueryResult, ReasonKind, Reason, SourceFactIdentity, TextMetrics, SourceChangeMetrics, StaleDegreeResult, Evidence, StatusResult, NodeStatusInspection, NodeStatusTriageEntry, SourceFileInfo, CognitionFileInfo, LinkCheckResult, StatusContext, } from './status/statusTypes';
2
+ export type { SnapshotOperationScope, CoggitProjectContext, CoggitOperationAction, CoreOperationId, } from './operationTypes';
3
+ export type { CognitionDocumentKind, CognitionFrontmatterMetadata, CognitionFrontmatter, CognitionHeading, CognitionDocumentMetrics, CognitionDocumentDiagnostic, CognitionDocumentFacts, CognitionMetadataQuality, CognitionContextStaleRisk, CognitionRoutes, CognitionRoutesEntry, CognitionContextIdentity, CognitionContextDocumentSummary, CognitionContextQuality, CognitionContextStatus, RoutesProjectionNode, } from './cognitionTypes';
4
+ export type { AcceptedPair, PathKeyRecord, RegistryFile, RegistryProvider, } from './registryTypes';
5
+ export type { MisplacedCognitionEntry, OrphanedCognitionEntry, StrayCognitionEntry, UnboundCognitionEntry, MaintenanceDiagnostic, CognitionDiscoveryEntry, SourceCandidateState, CoggitNodeKind, MappingIndex, AffectedResult, CoggitWorkspaceRoot, CoggitTreeNode, CoggitSnapshot, TreeProjectionNode, CoggitConfig, } from './snapshotTypes';
@@ -0,0 +1,35 @@
1
+ import type { UriComponents, UriKey } from './interfaces';
2
+ /** Produce a canonical URI key string from UriComponents */
3
+ export declare function uriKey(components: UriComponents): UriKey;
4
+ /** Compute relative path from root to child, comparing scheme/authority/path */
5
+ export declare function uriRelativePath(root: UriComponents, child: UriComponents): string | undefined;
6
+ export declare function isEqualOrChildUri(parent: UriComponents, child: UriComponents): boolean;
7
+ /**
8
+ * Join path segments onto a base URI, preserving scheme and authority.
9
+ * This is a path-level operation (unlike vscode.Uri.joinPath which is URI-aware).
10
+ */
11
+ export declare function joinUriPath(base: UriComponents, ...segments: string[]): UriComponents;
12
+ export declare function uriBasename(uri: UriComponents): string;
13
+ export declare function formatUri(uri: UriComponents): string;
14
+ /**
15
+ * Extract a clean, runtime-independent path string from UriComponents.
16
+ *
17
+ * For `file://` URIs the scheme prefix is stripped so callers get an
18
+ * absolute path they can use directly or wrap in a runtime-specific URI.
19
+ * Non-file URIs return the full URI key unchanged so no information is lost.
20
+ *
21
+ * This is the boundary transform at the MCP DTO layer — core internals keep
22
+ * working with UriComponents; MCP-facing projections use this to decouple
23
+ * the wire format from the `file://` scheme.
24
+ */
25
+ export declare function uriToExternalPath(uri: UriComponents): string;
26
+ /**
27
+ * Convert a URI key string (e.g. `"file:///d:/project"`) to a clean external
28
+ * path suitable for MCP DTOs and CLI output.
29
+ *
30
+ * Inverse of `uriKey()` when the input was produced from a `file://` UriComponents.
31
+ * Non-file URIs are returned as-is (no scheme stripping).
32
+ */
33
+ export declare function externalPathFromString(uriKeyStr: string): string;
34
+ /** Parse a URI key string back into UriComponents. */
35
+ export declare function parseUriKey(uriKeyStr: string): UriComponents;
@@ -0,0 +1,44 @@
1
+ import type { CoggitProject, UriComponents } from './interfaces';
2
+ import type { AffectedResult, CoggitSnapshot } from './types';
3
+ import { type NormalizedWatchEvent, type WatchBatchRefreshMode, type WatchEventDomain, type WatchFileChangeKind, type WatcherEventApplyResult } from './watchPipeline';
4
+ export interface WatchObservation {
5
+ readonly domain: WatchEventDomain;
6
+ readonly uri: UriComponents;
7
+ readonly kind: WatchFileChangeKind;
8
+ readonly observedAtMs?: number;
9
+ }
10
+ export type WatchObservationHandler = (observation: WatchObservation) => Promise<WatchHostObservationResult>;
11
+ export interface WatchObserverSubscription {
12
+ dispose(): void;
13
+ }
14
+ export interface WatchObserver {
15
+ subscribe(handler: WatchObservationHandler): WatchObserverSubscription;
16
+ }
17
+ export interface WatchHostOptions {
18
+ readonly projects: readonly CoggitProject[];
19
+ readonly snapshotProvider: () => CoggitSnapshot | Promise<CoggitSnapshot>;
20
+ readonly observer?: WatchObserver;
21
+ readonly now?: () => number;
22
+ }
23
+ export interface WatchHost {
24
+ start(): void;
25
+ stop(): void;
26
+ observe(observation: WatchObservation): Promise<WatchHostObservationResult>;
27
+ }
28
+ export interface WatchHostRefreshIntent {
29
+ readonly mode: WatchBatchRefreshMode;
30
+ readonly reason: 'affected-pairs' | 'known-root-unmapped' | 'outside-known-roots' | 'empty-batch' | 'structural-event' | 'config-event';
31
+ readonly changedPaths: readonly string[];
32
+ readonly affected?: AffectedResult;
33
+ }
34
+ export interface WatchHostObservationResult {
35
+ readonly observation: WatchObservation;
36
+ readonly generation: number;
37
+ readonly delivered: true;
38
+ readonly matchedRootIds: readonly string[];
39
+ readonly matchedProjectCount: number;
40
+ readonly normalizedEvent?: NormalizedWatchEvent;
41
+ readonly applyResult?: WatcherEventApplyResult;
42
+ readonly refresh: WatchHostRefreshIntent;
43
+ }
44
+ export declare function createWatchHost(options: WatchHostOptions): WatchHost;
@@ -0,0 +1,31 @@
1
+ import type { CoggitProject, UriComponents } from './interfaces';
2
+ import type { AffectedResult, CoggitSnapshot } from './types';
3
+ export type WatchFileChangeKind = 'change' | 'create' | 'delete';
4
+ export type WatchEventDomain = 'source' | 'cognition' | 'config';
5
+ export type WatchRefreshMode = 'full' | 'partial';
6
+ export type WatchBatchRefreshMode = WatchRefreshMode | 'none';
7
+ export interface NormalizedWatchEvent {
8
+ readonly domain: WatchEventDomain;
9
+ readonly uri: UriComponents;
10
+ readonly kind: WatchFileChangeKind;
11
+ readonly generation: number;
12
+ readonly observedAtMs?: number;
13
+ }
14
+ export interface WatcherEventApplyResult {
15
+ readonly domain: WatchEventDomain;
16
+ readonly kind: WatchFileChangeKind;
17
+ readonly generation: number;
18
+ readonly projectCount: number;
19
+ readonly sourceObservationCount: number;
20
+ readonly directoryObservationCount: number;
21
+ readonly passiveAcceptanceCount: number;
22
+ }
23
+ export interface WatchRefreshRoute {
24
+ readonly mode: WatchBatchRefreshMode;
25
+ readonly reason: 'affected-pairs' | 'known-root-unmapped' | 'outside-known-roots' | 'empty-batch';
26
+ readonly changedPaths: readonly string[];
27
+ readonly affected: AffectedResult;
28
+ }
29
+ export declare function selectWatchRefreshMode(kind: WatchFileChangeKind, hasMappingIndex: boolean): WatchRefreshMode;
30
+ export declare function planWatchRefresh(snapshot: CoggitSnapshot, changedUris: readonly UriComponents[]): WatchRefreshRoute;
31
+ export declare function applyWatchEventToProjects(projects: readonly CoggitProject[], event: NormalizedWatchEvent): Promise<WatcherEventApplyResult>;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@coggit/core",
3
+ "version": "0.2.0",
4
+ "description": "CogGit core kernel: source/cognition freshness semantics, registry, snapshot, status, and operations.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/CatheadOwl/coggit.git",
9
+ "directory": "packages/core"
10
+ },
11
+ "main": "./dist/public.js",
12
+ "types": "./dist/public.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/public.d.ts",
16
+ "default": "./dist/public.js"
17
+ },
18
+ "./internal": {
19
+ "types": "./dist/internal.d.ts",
20
+ "default": "./dist/internal.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "CHANGELOG.md",
27
+ "LICENSE"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "devDependencies": {
33
+ "@types/mocha": "^10.0.10",
34
+ "@types/node": "24.x",
35
+ "esbuild": "^0.28.1",
36
+ "typescript": "^6.0.3",
37
+ "yaml": "^2.8.1"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "scripts": {
43
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
44
+ "build": "pnpm run clean && tsc -p tsconfig.build.json && node build.js",
45
+ "check-types": "tsc -b",
46
+ "watch": "node build.js --watch"
47
+ }
48
+ }