@nuanst-one/ngitdb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/dist/action.cjs +49 -0
- package/dist/action.d.ts +38 -0
- package/dist/errors.d.ts +38 -0
- package/dist/gitdb.d.ts +11 -0
- package/dist/github-backend.d.ts +36 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/ownership.d.ts +2 -0
- package/dist/patch.d.ts +2 -0
- package/dist/resource-path.d.ts +10 -0
- package/dist/types.d.ts +78 -0
- package/docs/wiki/prompt-recipes.md +188 -0
- package/package.json +52 -0
- package/plugins/ngitdb/.codex-plugin/plugin.json +37 -0
- package/plugins/ngitdb/skills/ngitdb-integrator/SKILL.md +35 -0
- package/plugins/ngitdb/skills/ngitdb-integrator/agents/openai.yaml +4 -0
- package/plugins/ngitdb/skills/ngitdb-integrator/references/api.md +93 -0
- package/plugins/ngitdb/skills/ngitdb-integrator/references/migration-patterns.md +44 -0
- package/plugins/ngitdb/skills/ngitdb-integrator/references/testing.md +12 -0
- package/plugins/ngitdb/skills/ngitdb-reviewer/SKILL.md +34 -0
- package/plugins/ngitdb/skills/ngitdb-reviewer/agents/openai.yaml +4 -0
- package/plugins/ngitdb/skills/ngitdb-reviewer/references/checklist.md +17 -0
- package/plugins/ngitdb/skills/ngitdb-reviewer/references/risk-patterns.md +35 -0
- package/plugins/ngitdb/skills/ngitdb-starter/SKILL.md +35 -0
- package/plugins/ngitdb/skills/ngitdb-starter/agents/openai.yaml +4 -0
- package/plugins/ngitdb/skills/ngitdb-starter/references/resource-model.md +36 -0
- package/plugins/ngitdb/skills/ngitdb-starter/references/safety-model.md +40 -0
- package/plugins/ngitdb/skills/ngitdb-starter/references/testing.md +13 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# API
|
|
2
|
+
|
|
3
|
+
Use:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createGitDB } from "ngitdb";
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Core workflow:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const db = createGitDB(config);
|
|
13
|
+
|
|
14
|
+
await db.startSession("acme-gmbh");
|
|
15
|
+
|
|
16
|
+
await db.patch("companies/acme-gmbh", {
|
|
17
|
+
"machine.summary": "Updated summary",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await db.commit("Update company enrichment");
|
|
21
|
+
|
|
22
|
+
const pullRequest = await db.createPullRequest({
|
|
23
|
+
title: "Update company enrichment",
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Resource config:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
const config = {
|
|
31
|
+
repositoryRoot: process.cwd(),
|
|
32
|
+
baseBranch: "main",
|
|
33
|
+
resourceRoot: "data",
|
|
34
|
+
resources: {
|
|
35
|
+
companies: {
|
|
36
|
+
fileName: "company.json",
|
|
37
|
+
ownership: {
|
|
38
|
+
legalName: "human-owned",
|
|
39
|
+
machine: "machine-owned",
|
|
40
|
+
},
|
|
41
|
+
validate: validateCompany,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
GitHub Action workflow for Python/non-TypeScript producers:
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
permissions:
|
|
51
|
+
contents: write
|
|
52
|
+
pull-requests: write
|
|
53
|
+
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/checkout@v4
|
|
56
|
+
- run: python scripts/build_ngitdb_batch.py --output tmp/ngitdb.batch.json
|
|
57
|
+
- uses: nuanst-gmbh/nGitDB@v0
|
|
58
|
+
with:
|
|
59
|
+
batch-file: tmp/ngitdb.batch.json
|
|
60
|
+
session-key: company-enrichment
|
|
61
|
+
commit-message: Update generated company data
|
|
62
|
+
pr-title: Update generated company data
|
|
63
|
+
resource-config: |
|
|
64
|
+
{
|
|
65
|
+
"baseBranch": "main",
|
|
66
|
+
"resources": {
|
|
67
|
+
"companies": {
|
|
68
|
+
"fileName": "company.json",
|
|
69
|
+
"ownership": {
|
|
70
|
+
"legalName": "human-owned",
|
|
71
|
+
"machine": "machine-owned"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Batch file:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"resources": [
|
|
83
|
+
{
|
|
84
|
+
"resourcePath": "companies/acme-gmbh",
|
|
85
|
+
"patch": {
|
|
86
|
+
"machine.summary": "Updated summary"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Action `resource-config` is JSON and cannot include validator functions.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Migration Patterns
|
|
2
|
+
|
|
3
|
+
Replace this pattern:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
const file = JSON.parse(await readFile(filePath, "utf8"));
|
|
7
|
+
file.machine.summary = summary;
|
|
8
|
+
await writeFile(filePath, JSON.stringify(file, null, 2));
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
with:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
await db.startSession(sessionKey);
|
|
15
|
+
await db.patch(resourcePath, {
|
|
16
|
+
"machine.summary": summary,
|
|
17
|
+
});
|
|
18
|
+
await db.commit(message);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
When the old code updates many fields, split them by ownership:
|
|
22
|
+
|
|
23
|
+
- Move machine-safe generated fields into one `db.patch(...)`.
|
|
24
|
+
- Leave human-owned fields out of automated workflows.
|
|
25
|
+
- Add tests that prove human-owned fields are rejected.
|
|
26
|
+
|
|
27
|
+
If the existing file layout does not match `data/<collection>/<id>/<fileName>`, prefer configuring `resourceRoot` and `fileName` before moving files.
|
|
28
|
+
|
|
29
|
+
For Python or non-TypeScript workflows, replace direct JSON writes with a batch file for the nGitDB GitHub Action:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"resources": [
|
|
34
|
+
{
|
|
35
|
+
"resourcePath": "companies/acme-gmbh",
|
|
36
|
+
"patch": {
|
|
37
|
+
"machine.summary": "Updated summary"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then call `nuanst-gmbh/nGitDB@v0` after the generator step. Keep the batch limited to machine-owned fields.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
For retrofit work, add tests around the migrated path:
|
|
4
|
+
|
|
5
|
+
- existing resource can still be read
|
|
6
|
+
- migrated machine-owned patch writes the expected staged document
|
|
7
|
+
- default source file is not changed by session commit artifacts
|
|
8
|
+
- human-owned field patch is rejected
|
|
9
|
+
- invalid staged state is rejected on commit
|
|
10
|
+
- workflow returns pull request draft metadata
|
|
11
|
+
|
|
12
|
+
Keep tests close to the existing test style. Avoid adding a new test framework.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ngitdb-reviewer
|
|
3
|
+
description: Review an existing nGitDB integration for safety, correctness, and test coverage. Use when users ask for a review, audit, risk assessment, or critique of code that uses nGitDB, db.patch, ownership maps, validators, sessions, commits, or pull request draft workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# nGitDB Reviewer
|
|
7
|
+
|
|
8
|
+
Use this skill in code-review mode. Findings should lead, ordered by severity, with file and line references.
|
|
9
|
+
|
|
10
|
+
## Review Flow
|
|
11
|
+
|
|
12
|
+
1. Locate `createGitDB(...)` configuration and all `db.read`, `db.startSession`, `db.patch`, `db.commit`, and `db.createPullRequest` calls.
|
|
13
|
+
2. Trace each write workflow from user or machine input to patch document.
|
|
14
|
+
3. Check ownership maps against the actual JSON shape.
|
|
15
|
+
4. Check validators and when they run.
|
|
16
|
+
5. Check tests for ownership, validation, and session misuse.
|
|
17
|
+
6. For GitHub Action integrations, check batch schema, workflow permissions, resource-config ownership, and whether Python emits only machine-owned patches.
|
|
18
|
+
7. Report concrete risks before summaries.
|
|
19
|
+
|
|
20
|
+
## High-Severity Patterns
|
|
21
|
+
|
|
22
|
+
- Direct full-file JSON writes replacing nGitDB patch workflow.
|
|
23
|
+
- Machine workflows patching human-owned fields.
|
|
24
|
+
- Missing ownership on write-enabled resources.
|
|
25
|
+
- Validators missing for write-enabled resources.
|
|
26
|
+
- `commit(...)` or `createPullRequest(...)` called without a controlled session flow.
|
|
27
|
+
- GitHub Action workflows missing `contents: write` or `pull-requests: write`.
|
|
28
|
+
- Batch files that contain full documents, raw file paths, or human-owned fields.
|
|
29
|
+
- JSON Action config that assumes function validators will run.
|
|
30
|
+
|
|
31
|
+
## References
|
|
32
|
+
|
|
33
|
+
- Read `references/checklist.md` for the full review checklist.
|
|
34
|
+
- Read `references/risk-patterns.md` for common unsafe patterns.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Review Checklist
|
|
2
|
+
|
|
3
|
+
Check:
|
|
4
|
+
|
|
5
|
+
- Resource paths use `<collection>/<id>`.
|
|
6
|
+
- Resource definitions exist for every write-enabled collection.
|
|
7
|
+
- Ownership maps are present for resources modified by automation.
|
|
8
|
+
- Human-owned fields include identity, legal, source, approval, and manually curated fields.
|
|
9
|
+
- Machine-owned fields are limited to generated or derived data.
|
|
10
|
+
- Patch documents only target machine-owned fields.
|
|
11
|
+
- Validators return actionable issue strings.
|
|
12
|
+
- Commits cannot happen with invalid staged documents.
|
|
13
|
+
- Pull request draft metadata has clear title and body when useful.
|
|
14
|
+
- Tests cover read, patch, ownership rejection, validation failure, session misuse, and pull request draft creation.
|
|
15
|
+
- GitHub Action workflows grant `contents: write` and `pull-requests: write`.
|
|
16
|
+
- GitHub Action batches use `resources: [{ resourcePath, patch }]`, not full-file replacement.
|
|
17
|
+
- GitHub Action `resource-config` includes ownership and does not rely on validator functions.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Risk Patterns
|
|
2
|
+
|
|
3
|
+
Unsafe full-file replacement:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
await writeFile(filePath, JSON.stringify(nextDocument, null, 2));
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Uncontrolled machine ownership:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
ownership: {
|
|
13
|
+
"*": "machine-owned",
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Vague validation:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
return ["invalid"];
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Patch outside explicit workflow:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
await db.patch(resourcePath, patch);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
without a preceding controlled `startSession(...)`.
|
|
30
|
+
|
|
31
|
+
Weak review metadata:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
await db.createPullRequest({ title: "Update" });
|
|
35
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ngitdb-starter
|
|
3
|
+
description: Set up nGitDB from the beginning in a new TypeScript project or a project without an established JSON resource model. Use when users ask to start with nGitDB, create a Git-backed JSON data layout, define initial resource collections, ownership rules, validators, example workflows, or tests for a greenfield nGitDB setup.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# nGitDB Starter
|
|
7
|
+
|
|
8
|
+
Use this skill to create a conservative greenfield nGitDB setup.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Inspect the project structure, package manager, TypeScript config, and test framework.
|
|
13
|
+
2. Propose a minimal resource model before adding code when the domain is unclear.
|
|
14
|
+
3. Create JSON resources under `data/<collection>/<id>/<fileName>` unless the project already has a stronger convention.
|
|
15
|
+
4. Configure `createGitDB(...)` with explicit `resources`.
|
|
16
|
+
5. Define ownership before writing workflow code.
|
|
17
|
+
6. Add validators for every write-enabled resource.
|
|
18
|
+
7. Add one end-to-end workflow using `startSession -> patch -> commit -> createPullRequest`.
|
|
19
|
+
8. Add tests for read, patch success, ownership rejection, validation failure, and session misuse.
|
|
20
|
+
9. If data is produced outside Node, prefer the nGitDB GitHub Action: generate a batch file with `resources: [{ resourcePath, patch }]`, then use `nuanst-gmbh/nGitDB@v0`.
|
|
21
|
+
|
|
22
|
+
## Guardrails
|
|
23
|
+
|
|
24
|
+
- Use `db.patch(...)` for writes. Do not add direct full-file JSON replacement APIs.
|
|
25
|
+
- Keep human-authored identity, legal, approval, and canonical source fields `human-owned`.
|
|
26
|
+
- Put machine enrichment, extraction, scoring, generated summaries, and metadata under machine-owned fields.
|
|
27
|
+
- Keep resource paths in `<collection>/<id>` format.
|
|
28
|
+
- Keep initial data and tests small.
|
|
29
|
+
- For GitHub Action config, remember JSON `resource-config` supports ownership but not function validators.
|
|
30
|
+
|
|
31
|
+
## References
|
|
32
|
+
|
|
33
|
+
- Read `references/resource-model.md` when designing the initial files.
|
|
34
|
+
- Read `references/safety-model.md` when defining ownership and validators.
|
|
35
|
+
- Read `references/testing.md` before adding tests.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Resource Model
|
|
2
|
+
|
|
3
|
+
Use this default layout:
|
|
4
|
+
|
|
5
|
+
```txt
|
|
6
|
+
data/<collection>/<id>/<fileName>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
|
|
11
|
+
```txt
|
|
12
|
+
data/companies/acme-gmbh/company.json
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use resource paths in code:
|
|
16
|
+
|
|
17
|
+
```txt
|
|
18
|
+
companies/acme-gmbh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Start with one collection unless the user explicitly needs more. Prefer plural collection names and stable lowercase identifiers.
|
|
22
|
+
|
|
23
|
+
Minimal resource definition:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
resources: {
|
|
27
|
+
companies: {
|
|
28
|
+
fileName: "company.json",
|
|
29
|
+
ownership: {
|
|
30
|
+
legalName: "human-owned",
|
|
31
|
+
machine: "machine-owned",
|
|
32
|
+
},
|
|
33
|
+
validate: validateCompany,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Safety Model
|
|
2
|
+
|
|
3
|
+
Default ownership policy:
|
|
4
|
+
|
|
5
|
+
- Human-owned: canonical identity, legal names, approval status, manually curated source fields.
|
|
6
|
+
- Machine-owned: generated summaries, enrichment timestamps, extraction output, analysis, scores.
|
|
7
|
+
|
|
8
|
+
Prefer this document shape:
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
{
|
|
12
|
+
"legalName": "ACME GmbH",
|
|
13
|
+
"machine": {
|
|
14
|
+
"summary": "Legacy summary",
|
|
15
|
+
"lastEnrichedAt": "2026-04-20"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Validation must return specific issue strings:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const validateCompany = (document: JsonObject): readonly string[] => {
|
|
24
|
+
const issues: string[] = [];
|
|
25
|
+
|
|
26
|
+
if (typeof document.legalName !== "string" || document.legalName.length === 0) {
|
|
27
|
+
issues.push("legalName must be a non-empty string");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
document.machine === null ||
|
|
32
|
+
typeof document.machine !== "object" ||
|
|
33
|
+
Array.isArray(document.machine)
|
|
34
|
+
) {
|
|
35
|
+
issues.push("machine must be an object");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return issues;
|
|
39
|
+
};
|
|
40
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
Add focused tests for:
|
|
4
|
+
|
|
5
|
+
- reading a resource by resource path
|
|
6
|
+
- deterministic session branch naming when `currentDate` is set
|
|
7
|
+
- rejecting `patch(...)` outside a session
|
|
8
|
+
- allowing patches to machine-owned fields
|
|
9
|
+
- rejecting patches to human-owned fields
|
|
10
|
+
- rejecting invalid staged documents during `commit(...)`
|
|
11
|
+
- creating pull request draft metadata after commit
|
|
12
|
+
|
|
13
|
+
Use temporary repositories or fixtures. Avoid tests that depend on a real remote GitHub repository.
|