@hivelore/core 0.30.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/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/index.d.ts +2752 -0
- package/dist/index.js +5586 -0
- package/dist/index.js.map +1 -0
- package/grammars/NOTICE.md +18 -0
- package/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/grammars/tree-sitter-go.wasm +0 -0
- package/grammars/tree-sitter-java.wasm +0 -0
- package/grammars/tree-sitter-javascript.wasm +0 -0
- package/grammars/tree-sitter-php.wasm +0 -0
- package/grammars/tree-sitter-python.wasm +0 -0
- package/grammars/tree-sitter-ruby.wasm +0 -0
- package/grammars/tree-sitter-rust.wasm +0 -0
- package/grammars/tree-sitter-tsx.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hivelore contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/Doucs91/hivelore">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/Doucs91/hivelore/main/packages/vscode/media/logo.svg" alt="Hivelore logo" width="96" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# @hivelore/core
|
|
8
|
+
|
|
9
|
+
> Internal library — policy, memory, anchor, and enforcement primitives for Hivelore.
|
|
10
|
+
|
|
11
|
+
This package is consumed by `@hivelore/cli` and `@hivelore/mcp`. You do **not** need to install it directly unless you are building a custom Hivelore integration or extending the tool.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## What this package provides
|
|
16
|
+
|
|
17
|
+
### Enforcement primitives
|
|
18
|
+
|
|
19
|
+
Core owns the durable types and local runtime markers used by Hivelore policy gates:
|
|
20
|
+
|
|
21
|
+
- `.ai/haive.config.json` config loading/merging
|
|
22
|
+
- strict enforcement settings (`requireBriefingFirst`, session recap, memory verification, stale-decision blocking)
|
|
23
|
+
- briefing markers under `.ai/.runtime/enforcement/briefings/`
|
|
24
|
+
- anchor verification for stale decisions and gotchas
|
|
25
|
+
- path resolution for project, memory, runtime, and module directories
|
|
26
|
+
|
|
27
|
+
### Memory schema (Zod)
|
|
28
|
+
|
|
29
|
+
A single source of truth for the memory frontmatter format:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { MemoryFrontmatterSchema, MemoryTypeSchema, MemoryScopeSchema } from "@hivelore/core";
|
|
33
|
+
|
|
34
|
+
// Types
|
|
35
|
+
type MemoryType = "convention" | "decision" | "gotcha" | "architecture" | "glossary" | "attempt";
|
|
36
|
+
type MemoryScope = "personal" | "team" | "module";
|
|
37
|
+
type MemoryStatus = "draft" | "proposed" | "validated" | "stale" | "rejected" | "deprecated";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each memory file is a Markdown file with YAML frontmatter:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
---
|
|
44
|
+
id: 2025-01-15-gotcha-flyway-strict
|
|
45
|
+
scope: team
|
|
46
|
+
type: gotcha
|
|
47
|
+
status: validated
|
|
48
|
+
anchor:
|
|
49
|
+
paths:
|
|
50
|
+
- src/main/resources/db/migration
|
|
51
|
+
symbols: []
|
|
52
|
+
tags: [flyway, database, migration]
|
|
53
|
+
domain: database
|
|
54
|
+
author: dev@example.com
|
|
55
|
+
created_at: "2025-01-15T10:30:00.000Z"
|
|
56
|
+
verified_at: "2025-01-20T08:00:00.000Z"
|
|
57
|
+
related_ids:
|
|
58
|
+
- 2025-01-15-attempt-modify-existing-migration
|
|
59
|
+
expires_when: null
|
|
60
|
+
stale_reason: null
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
# Flyway strict mode — never modify existing migrations
|
|
64
|
+
|
|
65
|
+
...
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Parser / Serializer
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { parseMemory, serializeMemory, buildFrontmatter, newMemoryId } from "@hivelore/core";
|
|
72
|
+
|
|
73
|
+
// Parse a memory file
|
|
74
|
+
const memory = parseMemory(rawMarkdown);
|
|
75
|
+
|
|
76
|
+
// Serialize back to disk
|
|
77
|
+
const markdown = serializeMemory(memory);
|
|
78
|
+
|
|
79
|
+
// Build a new frontmatter object
|
|
80
|
+
const frontmatter = buildFrontmatter({
|
|
81
|
+
type: "gotcha",
|
|
82
|
+
slug: "flyway-strict",
|
|
83
|
+
scope: "team",
|
|
84
|
+
paths: ["src/main/resources/db/migration"],
|
|
85
|
+
tags: ["flyway"],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Generate a canonical ID
|
|
89
|
+
const id = newMemoryId("gotcha", "flyway-strict"); // "2025-01-15-gotcha-flyway-strict"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Anchor verification
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { verifyAnchor } from "@hivelore/core";
|
|
96
|
+
|
|
97
|
+
const result = await verifyAnchor(memory, { projectRoot: "/path/to/project" });
|
|
98
|
+
// result.stale — true if anchor paths or symbols no longer exist
|
|
99
|
+
// result.reason — human-readable explanation
|
|
100
|
+
// result.possibleRenames — files with the same basename found elsewhere (rename detection)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Literal search
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { tokenizeQuery, literalMatchesAllTokens, literalMatchesAnyToken } from "@hivelore/core";
|
|
107
|
+
|
|
108
|
+
const tokens = tokenizeQuery("flyway migration strict");
|
|
109
|
+
const matches = memories.filter(({ memory }) => literalMatchesAllTokens(memory, tokens));
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Token budgeting
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { allocateBudget, estimateTokens, truncateToTokens } from "@hivelore/core";
|
|
116
|
+
|
|
117
|
+
const slices = allocateBudget(
|
|
118
|
+
[
|
|
119
|
+
{ key: "context", text: projectContext, weight: 3, mode: "head" },
|
|
120
|
+
{ key: "memories", text: memoriesText, weight: 4, mode: "head" },
|
|
121
|
+
],
|
|
122
|
+
8000, // max tokens
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Usage / confidence tracking
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { loadUsageIndex, trackReads, deriveConfidence, isDecaying, DECAY_DAYS } from "@hivelore/core";
|
|
130
|
+
|
|
131
|
+
const index = await loadUsageIndex(paths);
|
|
132
|
+
const usage = getUsage(index, memoryId);
|
|
133
|
+
const confidence = deriveConfidence(frontmatter, usage);
|
|
134
|
+
// confidence: "authoritative" | "trusted" | "provisional" | "low" | "stale"
|
|
135
|
+
|
|
136
|
+
const decaying = isDecaying(usage, frontmatter.created_at); // not read in >90 days
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Path helpers
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { findProjectRoot, resolveHaivePaths, memoryFilePath } from "@hivelore/core";
|
|
143
|
+
|
|
144
|
+
const root = findProjectRoot(); // Walks up from cwd looking for .ai/ or .git/
|
|
145
|
+
const paths = resolveHaivePaths(root);
|
|
146
|
+
// paths.memoriesDir, paths.teamDir, paths.personalDir, paths.moduleDir, paths.projectContext, ...
|
|
147
|
+
|
|
148
|
+
const file = memoryFilePath(paths, "team", "2025-01-15-gotcha-flyway", undefined);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Memory file format
|
|
154
|
+
|
|
155
|
+
Memories are plain Markdown files stored in `.ai/memories/<scope>/` and committed to git:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
.ai/
|
|
159
|
+
└── memories/
|
|
160
|
+
├── personal/ # Local only — not committed
|
|
161
|
+
├── team/ # Committed — shared across the team
|
|
162
|
+
└── module/
|
|
163
|
+
└── payments/ # Scoped to a specific module
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The frontmatter schema:
|
|
167
|
+
|
|
168
|
+
| Field | Type | Description |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `id` | string | Canonical ID: `YYYY-MM-DD-<type>-<slug>` |
|
|
171
|
+
| `scope` | enum | `personal` · `team` · `module` |
|
|
172
|
+
| `type` | enum | `convention` · `decision` · `gotcha` · `architecture` · `glossary` · `attempt` |
|
|
173
|
+
| `status` | enum | `draft` · `proposed` · `validated` · `stale` · `rejected` · `deprecated` |
|
|
174
|
+
| `anchor.paths` | string[] | File paths this memory is anchored to (staleness detection) |
|
|
175
|
+
| `anchor.symbols` | string[] | Symbol names this memory is anchored to |
|
|
176
|
+
| `anchor.commit` | string? | Git commit SHA at time of creation |
|
|
177
|
+
| `tags` | string[] | Free-form tags |
|
|
178
|
+
| `domain` | string? | Business domain (e.g. `payments`) |
|
|
179
|
+
| `related_ids` | string[] | IDs of related memories (auto-expanded in `get_briefing`) |
|
|
180
|
+
| `created_at` | ISO date | Creation timestamp |
|
|
181
|
+
| `verified_at` | ISO date? | Last anchor verification timestamp |
|
|
182
|
+
| `stale_reason` | string? | Why the memory was marked stale |
|
|
183
|
+
| `expires_when` | string? | Condition under which this memory should be deprecated |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT
|