@boxxy/closeout 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/build-close-out-parser.d.ts +2 -0
- package/dist/dedupe-open-items.d.ts +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/missing-criteria.d.ts +2 -0
- package/dist/normalise-title.d.ts +1 -0
- package/package.json +38 -4
- package/src/build-close-out-parser.ts +115 -0
- package/src/dedupe-open-items.ts +47 -0
- package/src/index.ts +4 -0
- package/src/missing-criteria.ts +15 -0
- package/src/normalise-title.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 the boxxy authors
|
|
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
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>@boxxy/closeout</h1>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@boxxy/closeout"><img src="https://img.shields.io/npm/v/@boxxy/closeout" alt="npm version"></a>
|
|
6
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<a href="../../docs/design/boxxy/README.md">Documentation</a>
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
boxxy's close-out parser. It checks the close-out an agent sends at the end of a build attempt, and
|
|
15
|
+
splits the work the agent found into new items to file and matches of items already open.
|
|
16
|
+
|
|
17
|
+
The package does no I/O: the caller passes in the item, the attempt's evidence rows and the open
|
|
18
|
+
items.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Install the package from [npm](https://www.npmjs.com/package/@boxxy/closeout) with Bun:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bun add @boxxy/closeout
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The package runs on [Bun](https://bun.sh) 1.3 or newer.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- `buildCloseOutParser`, which returns the parsed close-out, or every problem with it in one pass
|
|
33
|
+
([the build close-out](../../docs/design/boxxy/slice-1.md#the-build-close-out)).
|
|
34
|
+
- `missingCriteria`, which lists the item's criteria that the close-out cites no evidence for.
|
|
35
|
+
- `dedupeOpenItems` and `normaliseTitle`, which match each open item the agent reports to an open
|
|
36
|
+
item with the same title.
|
|
37
|
+
|
|
38
|
+
## Documentation
|
|
39
|
+
|
|
40
|
+
The [close-outs design](../../docs/design/boxxy/close-outs.md) says what a close-out holds and why,
|
|
41
|
+
and [`06-closeouts.ts`](../../docs/design/boxxy/sketches/06-closeouts.ts) gives the shapes.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normaliseTitle(title: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boxxy/closeout",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "boxxy's close-out parser: checks the close-out an agent sends at the end of an attempt",
|
|
5
|
+
"homepage": "https://github.com/zgeoff/boxxy/tree/main/modules/closeout#readme",
|
|
6
|
+
"bugs": "https://github.com/zgeoff/boxxy/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/zgeoff/boxxy.git",
|
|
11
|
+
"directory": "modules/closeout"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"!src/**/*.test.ts",
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./src/index.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && tsrs -p tsconfig.build.json",
|
|
30
|
+
"typecheck": "tsrs --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@boxxy/model": "0.1.1",
|
|
34
|
+
"tiny-invariant": "1.3.3"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.3",
|
|
38
|
+
"node": ">=24"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BuildCloseOut,
|
|
3
|
+
CloseOutContext,
|
|
4
|
+
CloseOutParse,
|
|
5
|
+
CloseOutParser,
|
|
6
|
+
CloseOutProblem,
|
|
7
|
+
} from '@boxxy/model';
|
|
8
|
+
import { buildCloseOutSchema, formatKeyPath } from '@boxxy/model';
|
|
9
|
+
import invariant from 'tiny-invariant';
|
|
10
|
+
import { missingCriteria } from './missing-criteria.ts';
|
|
11
|
+
|
|
12
|
+
export const buildCloseOutParser: CloseOutParser<BuildCloseOut> = { parse: parseBuildCloseOut };
|
|
13
|
+
|
|
14
|
+
function parseBuildCloseOut(raw: unknown, ctx: CloseOutContext): CloseOutParse<BuildCloseOut> {
|
|
15
|
+
const split = splitFriction(raw);
|
|
16
|
+
const parsed = buildCloseOutSchema.safeParse(split.candidate);
|
|
17
|
+
|
|
18
|
+
if (!parsed.success) {
|
|
19
|
+
return {
|
|
20
|
+
kind: 'invalid',
|
|
21
|
+
problems: parsed.error.issues.map((issue) => buildSchemaProblem(issue, split.keptRawIndexes)),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const problems = collectProblems(parsed.data, ctx);
|
|
26
|
+
|
|
27
|
+
return problems.length === 0
|
|
28
|
+
? { kind: 'valid', closeOut: parsed.data }
|
|
29
|
+
: { kind: 'invalid', problems };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface FrictionSplit {
|
|
33
|
+
readonly candidate: unknown;
|
|
34
|
+
readonly keptRawIndexes: readonly number[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function splitFriction(raw: unknown): FrictionSplit {
|
|
38
|
+
if (!isRecord(raw)) {
|
|
39
|
+
return { candidate: raw, keptRawIndexes: [] };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const entries: readonly unknown[] = Array.isArray(raw['friction']) ? raw['friction'] : [];
|
|
43
|
+
const keptRawIndexes = entries.flatMap((entry, index) => (isUntargeted(entry) ? [] : [index]));
|
|
44
|
+
|
|
45
|
+
const friction = Array.isArray(raw['friction'])
|
|
46
|
+
? keptRawIndexes.map((index) => entries[index])
|
|
47
|
+
: raw['friction'];
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
candidate: { ...raw, friction, frictionDropped: entries.length - keptRawIndexes.length },
|
|
51
|
+
keptRawIndexes,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
56
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isUntargeted(entry: unknown): boolean {
|
|
60
|
+
return isRecord(entry) && (entry['target'] === undefined || entry['target'] === null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface SchemaIssue {
|
|
64
|
+
readonly path: readonly PropertyKey[];
|
|
65
|
+
readonly message: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function buildSchemaProblem(
|
|
69
|
+
issue: SchemaIssue,
|
|
70
|
+
keptRawIndexes: readonly number[],
|
|
71
|
+
): CloseOutProblem {
|
|
72
|
+
return {
|
|
73
|
+
kind: 'schema',
|
|
74
|
+
path: formatKeyPath(toRawPath(issue.path, keptRawIndexes)),
|
|
75
|
+
message: issue.message,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function toRawPath(path: readonly PropertyKey[], keptRawIndexes: readonly number[]): PropertyKey[] {
|
|
80
|
+
const [field, index, ...rest] = path;
|
|
81
|
+
|
|
82
|
+
if (field !== 'friction' || typeof index !== 'number') {
|
|
83
|
+
return [...path];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const rawIndex = keptRawIndexes[index];
|
|
87
|
+
|
|
88
|
+
invariant(rawIndex !== undefined, 'a friction issue points at an entry the parser kept');
|
|
89
|
+
|
|
90
|
+
return [field, rawIndex, ...rest];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function collectProblems(closeOut: BuildCloseOut, ctx: CloseOutContext): CloseOutProblem[] {
|
|
94
|
+
const acceptance = new Set(ctx.item.acceptance.map((criterion) => criterion.id));
|
|
95
|
+
const own = new Set(ctx.evidence.map((row) => row.factId));
|
|
96
|
+
|
|
97
|
+
const cited = closeOut.criteria;
|
|
98
|
+
|
|
99
|
+
const unknownCriteria = new Set(
|
|
100
|
+
cited.map((entry) => entry.criterion).filter((id) => !acceptance.has(id)),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const foreignEvidence = new Set(
|
|
104
|
+
cited.map((entry) => entry.evidence).filter((id) => !own.has(id)),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const missing =
|
|
108
|
+
closeOut.result.kind === 'built' ? missingCriteria(ctx.item, ctx.evidence, cited) : [];
|
|
109
|
+
|
|
110
|
+
return [
|
|
111
|
+
...[...unknownCriteria].map((criterion) => ({ kind: 'unknown-criterion' as const, criterion })),
|
|
112
|
+
...[...foreignEvidence].map((evidence) => ({ kind: 'foreign-evidence' as const, evidence })),
|
|
113
|
+
...(missing.length > 0 ? [{ kind: 'built-without-evidence' as const, criteria: missing }] : []),
|
|
114
|
+
];
|
|
115
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ItemId, ItemView, OpenItem } from '@boxxy/model';
|
|
2
|
+
import { normaliseTitle } from './normalise-title.ts';
|
|
3
|
+
|
|
4
|
+
export function dedupeOpenItems(
|
|
5
|
+
entries: readonly OpenItem[],
|
|
6
|
+
open: readonly ItemView[],
|
|
7
|
+
): { readonly file: readonly OpenItem[]; readonly matched: readonly ItemId[] } {
|
|
8
|
+
const openByTitle = collectOpenByTitle(open);
|
|
9
|
+
const matched = entries.flatMap((entry) => openByTitle.get(normaliseTitle(entry.title)) ?? []);
|
|
10
|
+
|
|
11
|
+
return { file: collectNewEntries(entries, openByTitle), matched: [...new Set(matched)] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function collectOpenByTitle(open: readonly ItemView[]): Map<string, ItemId> {
|
|
15
|
+
const openByTitle = new Map<string, ItemId>();
|
|
16
|
+
|
|
17
|
+
for (const item of open) {
|
|
18
|
+
const title = normaliseTitle(item.title);
|
|
19
|
+
|
|
20
|
+
if (!openByTitle.has(title)) {
|
|
21
|
+
openByTitle.set(title, item.id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return openByTitle;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function collectNewEntries(
|
|
29
|
+
entries: readonly OpenItem[],
|
|
30
|
+
openByTitle: ReadonlyMap<string, ItemId>,
|
|
31
|
+
): OpenItem[] {
|
|
32
|
+
const seen = new Set<string>();
|
|
33
|
+
|
|
34
|
+
const file: OpenItem[] = [];
|
|
35
|
+
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const title = normaliseTitle(entry.title);
|
|
38
|
+
|
|
39
|
+
if (!openByTitle.has(title) && !seen.has(title)) {
|
|
40
|
+
file.push(entry);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
seen.add(title);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return file;
|
|
47
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BuildCloseOut, CriterionId, EvidenceRow, ItemView } from '@boxxy/model';
|
|
2
|
+
|
|
3
|
+
export function missingCriteria(
|
|
4
|
+
item: ItemView,
|
|
5
|
+
evidence: readonly EvidenceRow[],
|
|
6
|
+
cited: BuildCloseOut['criteria'],
|
|
7
|
+
): readonly CriterionId[] {
|
|
8
|
+
const known = new Set(evidence.map((row) => row.factId));
|
|
9
|
+
|
|
10
|
+
const met = new Set(
|
|
11
|
+
cited.filter((entry) => known.has(entry.evidence)).map((entry) => entry.criterion),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return item.acceptance.map((criterion) => criterion.id).filter((id) => !met.has(id));
|
|
15
|
+
}
|