@suss/checker-intent 0.0.1
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 +205 -0
- package/README.md +47 -0
- package/dist/index.cjs +403 -0
- package/dist/index.d.cts +85 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +382 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable by
|
|
79
|
+
such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do not
|
|
117
|
+
modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor has
|
|
163
|
+
been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format please. Also add information on
|
|
185
|
+
how to contact you by electronic and paper mail.
|
|
186
|
+
|
|
187
|
+
If the program does not interact with users remotely through a computer
|
|
188
|
+
network, then your name and employer's name (e.g., your institution)
|
|
189
|
+
is sufficient to fill in the "name of copyright owner" field. Feel
|
|
190
|
+
free to omit the "name of employer" line if you are in no way affiliated
|
|
191
|
+
with any institution.
|
|
192
|
+
|
|
193
|
+
Copyright 2026 Nimbus Cloud AI LLC
|
|
194
|
+
|
|
195
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
you may not use this file except in compliance with the License.
|
|
197
|
+
You may obtain a copy of the License at
|
|
198
|
+
|
|
199
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
|
|
201
|
+
Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
See the License for the specific language governing permissions and
|
|
205
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @suss/checker-intent
|
|
2
|
+
|
|
3
|
+
Pair team-authored intent against derived code and report where the code
|
|
4
|
+
fails to satisfy what the team declared.
|
|
5
|
+
|
|
6
|
+
## What this package is
|
|
7
|
+
|
|
8
|
+
The intent half of suss's checking, separate from `@suss/checker` (the
|
|
9
|
+
behavioural peer checker) by design. The inputs differ — `IntentSummary`
|
|
10
|
+
(from `@suss/contract-intent`) on one side, `BehavioralSummary` on the
|
|
11
|
+
other — and so does the output: an `IntentFinding` is one-sided coverage
|
|
12
|
+
("the team declared X; does the code do it?"), not a symmetric
|
|
13
|
+
provider↔consumer mismatch.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { checkIntentAgreement } from "@suss/checker-intent";
|
|
17
|
+
|
|
18
|
+
const findings = checkIntentAgreement(intentSummaries, codeSummaries);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For each boundary intent, it pairs against the code summaries sharing the
|
|
22
|
+
same boundary key and emits:
|
|
23
|
+
|
|
24
|
+
- `unimplementedBoundary` — the intent declares a boundary no code produces.
|
|
25
|
+
- `uncoveredOutcome` — a declared outcome (response / return / throw) the code never produces.
|
|
26
|
+
- `outcomeShapeMismatch` — a matched outcome whose body shape disagrees with intent.
|
|
27
|
+
- `undeclaredOutcome` — code produces a REST status the intent doesn't declare (info; intent under-specifies).
|
|
28
|
+
|
|
29
|
+
v0 checks system intent (`kind: boundary`). PRD outcome intent
|
|
30
|
+
(`kind: prd`) — scenario / link coverage — is a separate pass.
|
|
31
|
+
|
|
32
|
+
## Where it sits in suss
|
|
33
|
+
|
|
34
|
+
Depends on `@suss/intent-ir` (intent shapes + `IntentFinding`),
|
|
35
|
+
`@suss/behavioral-ir` (code summaries), and `@suss/ir-core` for the
|
|
36
|
+
shared comparison primitives (`boundaryKey`, `bodyShapesMatch`) it must
|
|
37
|
+
agree on with the behavioural checker. It does **not** depend on
|
|
38
|
+
`@suss/checker`. The full design is in
|
|
39
|
+
[`docs/internal/proposals/intent-specs.md`](../../docs/internal/proposals/intent-specs.md).
|
|
40
|
+
|
|
41
|
+
## Coverage
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
Apache-2.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
applyIntentSuppressions: () => applyIntentSuppressions,
|
|
24
|
+
checkIntentAgreement: () => checkIntentAgreement
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_behavioral_ir = require("@suss/behavioral-ir");
|
|
28
|
+
var import_ir_core = require("@suss/ir-core");
|
|
29
|
+
function checkIntentAgreement(intents, code) {
|
|
30
|
+
const findings = [];
|
|
31
|
+
const checked = [];
|
|
32
|
+
const unchecked = [];
|
|
33
|
+
const codeByBoundary = indexCodeByBoundary(code);
|
|
34
|
+
const boundaryByName = indexBoundaryIntentsByName(intents);
|
|
35
|
+
for (const intent of intents) {
|
|
36
|
+
if (intent.kind === "prd") {
|
|
37
|
+
const result2 = checkPrdCoverage(intent, boundaryByName);
|
|
38
|
+
findings.push(...withProvenance(result2.findings, intent.source));
|
|
39
|
+
checked.push(result2.checked);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const result = checkBoundaryIntent(intent, codeByBoundary);
|
|
43
|
+
findings.push(...withProvenance(result.findings, intent.source));
|
|
44
|
+
checked.push(...result.checked);
|
|
45
|
+
unchecked.push(...result.unchecked);
|
|
46
|
+
}
|
|
47
|
+
return { findings, checked, unchecked };
|
|
48
|
+
}
|
|
49
|
+
function checkBoundaryIntent(intent, codeByBoundary) {
|
|
50
|
+
const key = (0, import_ir_core.boundaryKey)(intent.boundary);
|
|
51
|
+
if (key === null) {
|
|
52
|
+
return {
|
|
53
|
+
findings: [
|
|
54
|
+
{
|
|
55
|
+
kind: "unkeyableBoundary",
|
|
56
|
+
severity: "warning",
|
|
57
|
+
boundary: unkeyedBoundaryLabel(intent.boundary),
|
|
58
|
+
intent: { name: intent.name },
|
|
59
|
+
message: `Intent "${intent.name}" has a ${intent.boundary.semantics.name} boundary that can't be keyed for pairing (function-call boundaries need package + exportPath); it was not checked against code.`
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
checked: [],
|
|
63
|
+
unchecked: [
|
|
64
|
+
{
|
|
65
|
+
intent: intent.name,
|
|
66
|
+
reason: "unkeyable",
|
|
67
|
+
detail: "boundary can't be keyed for pairing against code"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const impls = codeByBoundary.get(key) ?? [];
|
|
73
|
+
if (impls.length === 0) {
|
|
74
|
+
return {
|
|
75
|
+
findings: [
|
|
76
|
+
{
|
|
77
|
+
kind: "unimplementedBoundary",
|
|
78
|
+
severity: "error",
|
|
79
|
+
boundary: key,
|
|
80
|
+
intent: { name: intent.name },
|
|
81
|
+
message: `Intent "${intent.name}" declares boundary ${key} with ${intent.outcomes.length} outcome(s); no code produces this boundary.`
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
// The comparison ran — finding no implementation IS the result.
|
|
85
|
+
checked: [
|
|
86
|
+
{
|
|
87
|
+
kind: "boundary",
|
|
88
|
+
intent: intent.name,
|
|
89
|
+
boundary: key,
|
|
90
|
+
implementations: []
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
unchecked: []
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const findings = [];
|
|
97
|
+
for (const impl of impls) {
|
|
98
|
+
findings.push(...compareIntentToImpl(intent, impl, key));
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
findings,
|
|
102
|
+
checked: [
|
|
103
|
+
{
|
|
104
|
+
kind: "boundary",
|
|
105
|
+
intent: intent.name,
|
|
106
|
+
boundary: key,
|
|
107
|
+
implementations: impls.map(codeRef)
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
unchecked: []
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function codeRef(impl) {
|
|
114
|
+
return `${impl.location.file}::${impl.identity.name}`;
|
|
115
|
+
}
|
|
116
|
+
function checkPrdCoverage(prd, boundaryByName) {
|
|
117
|
+
const findings = [];
|
|
118
|
+
let resolved = 0;
|
|
119
|
+
let unlinked = 0;
|
|
120
|
+
prd.scenarios.forEach((scenario, index) => {
|
|
121
|
+
const label = scenarioLabel(scenario.title, index);
|
|
122
|
+
if (scenario.link.length === 0) {
|
|
123
|
+
unlinked += 1;
|
|
124
|
+
findings.push({
|
|
125
|
+
kind: "unlinkedScenario",
|
|
126
|
+
severity: "info",
|
|
127
|
+
boundary: prdBoundaryLabel(prd),
|
|
128
|
+
intent: { name: prd.title },
|
|
129
|
+
...scenario.title !== null ? { scenario: { title: scenario.title } } : {},
|
|
130
|
+
message: `Scenario ${label} in PRD "${prd.title}" has no structured link to a system-intent outcome; it reads on its own, but its coverage can't be checked until a link is added.`
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let allResolved = true;
|
|
135
|
+
for (const ref of scenario.link) {
|
|
136
|
+
const finding = resolveScenarioLink(
|
|
137
|
+
prd,
|
|
138
|
+
scenario.title,
|
|
139
|
+
label,
|
|
140
|
+
ref,
|
|
141
|
+
boundaryByName
|
|
142
|
+
);
|
|
143
|
+
if (finding !== null) {
|
|
144
|
+
findings.push(finding);
|
|
145
|
+
allResolved = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (allResolved) {
|
|
149
|
+
resolved += 1;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
findings,
|
|
154
|
+
checked: {
|
|
155
|
+
kind: "prd",
|
|
156
|
+
intent: prd.title,
|
|
157
|
+
scenarios: prd.scenarios.length,
|
|
158
|
+
resolved,
|
|
159
|
+
unlinked
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function resolveScenarioLink(prd, scenarioTitle, label, ref, boundaryByName) {
|
|
164
|
+
const dot = ref.indexOf(".");
|
|
165
|
+
const name = dot >= 0 ? ref.slice(0, dot) : ref;
|
|
166
|
+
const outcomeId = dot >= 0 ? ref.slice(dot + 1) : "";
|
|
167
|
+
const scenarioRef = {
|
|
168
|
+
...scenarioTitle !== null ? { title: scenarioTitle } : {},
|
|
169
|
+
link: ref
|
|
170
|
+
};
|
|
171
|
+
const matches = boundaryByName.get(name) ?? [];
|
|
172
|
+
if (matches.length === 0) {
|
|
173
|
+
return {
|
|
174
|
+
kind: "danglingScenarioLink",
|
|
175
|
+
severity: "warning",
|
|
176
|
+
boundary: prdBoundaryLabel(prd),
|
|
177
|
+
intent: { name: prd.title },
|
|
178
|
+
scenario: scenarioRef,
|
|
179
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but no boundary intent named "${name}" is loaded.`
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (matches.length > 1) {
|
|
183
|
+
return {
|
|
184
|
+
kind: "ambiguousScenarioLink",
|
|
185
|
+
severity: "warning",
|
|
186
|
+
boundary: prdBoundaryLabel(prd),
|
|
187
|
+
intent: { name: prd.title },
|
|
188
|
+
scenario: scenarioRef,
|
|
189
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but ${matches.length} boundary intents are named "${name}"; rename them so the link resolves to one.`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const target = matches[0];
|
|
193
|
+
if (outcomeId === "" || !target.outcomes.some((o) => o.id === outcomeId)) {
|
|
194
|
+
const known = target.outcomes.map((o) => o.id).join(", ");
|
|
195
|
+
return {
|
|
196
|
+
kind: "danglingScenarioLink",
|
|
197
|
+
severity: "warning",
|
|
198
|
+
// The intent resolved even though the outcome didn't — key on its
|
|
199
|
+
// boundary so a narrow .sussignore rule can target this finding.
|
|
200
|
+
boundary: (0, import_ir_core.boundaryKey)(target.boundary) ?? prdBoundaryLabel(prd),
|
|
201
|
+
intent: { name: prd.title },
|
|
202
|
+
scenario: scenarioRef,
|
|
203
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but boundary intent "${name}" declares no outcome "${outcomeId}" (known outcomes: ${known}).`
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
function scenarioLabel(title, index) {
|
|
209
|
+
return title !== null ? `"${title}"` : `#${index + 1}`;
|
|
210
|
+
}
|
|
211
|
+
function prdBoundaryLabel(prd) {
|
|
212
|
+
return `prd:${prd.title}`;
|
|
213
|
+
}
|
|
214
|
+
function indexBoundaryIntentsByName(intents) {
|
|
215
|
+
const byName = /* @__PURE__ */ new Map();
|
|
216
|
+
for (const intent of intents) {
|
|
217
|
+
if (intent.kind !== "boundary") {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const bucket = byName.get(intent.name);
|
|
221
|
+
if (bucket === void 0) {
|
|
222
|
+
byName.set(intent.name, [intent]);
|
|
223
|
+
} else {
|
|
224
|
+
bucket.push(intent);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return byName;
|
|
228
|
+
}
|
|
229
|
+
var SEVERITY_DOWNGRADE = {
|
|
230
|
+
error: "warning",
|
|
231
|
+
warning: "info",
|
|
232
|
+
info: "info"
|
|
233
|
+
};
|
|
234
|
+
function withProvenance(findings, source) {
|
|
235
|
+
if (source !== "inferred") {
|
|
236
|
+
return findings;
|
|
237
|
+
}
|
|
238
|
+
return findings.map((f) => ({
|
|
239
|
+
...f,
|
|
240
|
+
severity: SEVERITY_DOWNGRADE[f.severity]
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
function applyIntentSuppressions(findings, rules, opts = {}) {
|
|
244
|
+
return (0, import_ir_core.applySuppressionsToFindings)(
|
|
245
|
+
findings,
|
|
246
|
+
rules,
|
|
247
|
+
(rule, finding) => {
|
|
248
|
+
if (rule.consumer !== void 0) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return rule.boundary === void 0 || (0, import_ir_core.ruleBoundaryMatchesKey)(rule.boundary, finding.boundary);
|
|
252
|
+
},
|
|
253
|
+
opts
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
function indexCodeByBoundary(code) {
|
|
257
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
258
|
+
for (const summary of code) {
|
|
259
|
+
if (import_behavioral_ir.BOUNDARY_ROLE[summary.kind] !== "provider") {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const binding = summary.identity.boundaryBinding;
|
|
263
|
+
if (binding === null) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const key = (0, import_ir_core.boundaryKey)(binding);
|
|
267
|
+
if (key === null) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const bucket = byKey.get(key);
|
|
271
|
+
if (bucket === void 0) {
|
|
272
|
+
byKey.set(key, [summary]);
|
|
273
|
+
} else {
|
|
274
|
+
bucket.push(summary);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return byKey;
|
|
278
|
+
}
|
|
279
|
+
function compareIntentToImpl(intent, impl, boundary) {
|
|
280
|
+
const findings = [];
|
|
281
|
+
const ref = codeRef(impl);
|
|
282
|
+
const codeOutcomes = impl.transitions.map(toCodeOutcome).filter((o) => o !== null);
|
|
283
|
+
for (const outcome of intent.outcomes) {
|
|
284
|
+
const matches = codeOutcomes.filter((co) => outcomeMatches(outcome, co));
|
|
285
|
+
if (matches.length === 0) {
|
|
286
|
+
findings.push({
|
|
287
|
+
kind: "uncoveredOutcome",
|
|
288
|
+
severity: "error",
|
|
289
|
+
boundary,
|
|
290
|
+
intent: { name: intent.name, outcomeId: outcome.id },
|
|
291
|
+
code: ref,
|
|
292
|
+
message: `Intent "${intent.name}" declares ${describeOutcome(outcome)} at ${boundary}; ${impl.identity.name} has no transition that produces it.`
|
|
293
|
+
});
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const declaredBody = outcome.body;
|
|
297
|
+
if (declaredBody === null) {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const bodied = matches.filter(
|
|
301
|
+
(m) => m.body !== null
|
|
302
|
+
);
|
|
303
|
+
if (bodied.length === 0) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const verdicts = bodied.map((m) => (0, import_ir_core.bodyShapesMatch)(m.body, declaredBody));
|
|
307
|
+
if (verdicts.some((v) => v !== "nomatch")) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
findings.push({
|
|
311
|
+
kind: "outcomeShapeMismatch",
|
|
312
|
+
severity: "error",
|
|
313
|
+
boundary,
|
|
314
|
+
intent: { name: intent.name, outcomeId: outcome.id },
|
|
315
|
+
code: ref,
|
|
316
|
+
message: `Body shape for ${describeOutcome(outcome)} at ${boundary} disagrees with intent "${intent.name}": ${impl.identity.name} produces an incompatible shape.`
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
const declared = new Set(
|
|
320
|
+
intent.outcomes.filter((o) => o.kind === "response" && o.status !== null).map((o) => o.status)
|
|
321
|
+
);
|
|
322
|
+
const undeclaredStatuses = /* @__PURE__ */ new Set();
|
|
323
|
+
for (const co of codeOutcomes) {
|
|
324
|
+
if (co.kind !== "response" || co.status === null || declared.has(co.status)) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
undeclaredStatuses.add(co.status);
|
|
328
|
+
}
|
|
329
|
+
for (const status of undeclaredStatuses) {
|
|
330
|
+
findings.push({
|
|
331
|
+
kind: "undeclaredOutcome",
|
|
332
|
+
severity: "info",
|
|
333
|
+
boundary,
|
|
334
|
+
intent: { name: intent.name },
|
|
335
|
+
code: ref,
|
|
336
|
+
message: `${impl.identity.name} produces status ${status} at ${boundary}; intent "${intent.name}" does not declare it.`
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return findings;
|
|
340
|
+
}
|
|
341
|
+
function toCodeOutcome(t) {
|
|
342
|
+
const output = t.output;
|
|
343
|
+
if (output.type === "response") {
|
|
344
|
+
const status = output.statusCode !== null && output.statusCode.type === "literal" ? Number(output.statusCode.value) : null;
|
|
345
|
+
return {
|
|
346
|
+
kind: "response",
|
|
347
|
+
status: status !== null && Number.isFinite(status) ? status : null,
|
|
348
|
+
body: output.body ?? null,
|
|
349
|
+
errorType: null
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (output.type === "return") {
|
|
353
|
+
return {
|
|
354
|
+
kind: "return",
|
|
355
|
+
status: null,
|
|
356
|
+
body: output.value,
|
|
357
|
+
errorType: null
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (output.type === "throw") {
|
|
361
|
+
return {
|
|
362
|
+
kind: "throw",
|
|
363
|
+
status: null,
|
|
364
|
+
body: null,
|
|
365
|
+
errorType: output.exceptionType
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
function outcomeMatches(intent, code) {
|
|
371
|
+
if (intent.kind !== code.kind) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (intent.kind === "response") {
|
|
375
|
+
return intent.status === code.status;
|
|
376
|
+
}
|
|
377
|
+
if (intent.kind === "throw") {
|
|
378
|
+
return intent.errorType === null || code.errorType === null || intent.errorType === code.errorType;
|
|
379
|
+
}
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
function unkeyedBoundaryLabel(binding) {
|
|
383
|
+
const semantics = binding.semantics;
|
|
384
|
+
if (semantics.name === "function-call") {
|
|
385
|
+
const target = semantics.module ?? semantics.package ?? "?";
|
|
386
|
+
return `fn:${target}::${semantics.exportName ?? "?"}`;
|
|
387
|
+
}
|
|
388
|
+
return semantics.name;
|
|
389
|
+
}
|
|
390
|
+
function describeOutcome(outcome) {
|
|
391
|
+
if (outcome.kind === "response") {
|
|
392
|
+
return `status ${outcome.status}`;
|
|
393
|
+
}
|
|
394
|
+
if (outcome.kind === "throw") {
|
|
395
|
+
return outcome.errorType !== null ? `throw ${outcome.errorType}` : "a thrown error";
|
|
396
|
+
}
|
|
397
|
+
return "a return value";
|
|
398
|
+
}
|
|
399
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
400
|
+
0 && (module.exports = {
|
|
401
|
+
applyIntentSuppressions,
|
|
402
|
+
checkIntentAgreement
|
|
403
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { BehavioralSummary } from '@suss/behavioral-ir';
|
|
2
|
+
import { IntentFinding, IntentSummary } from '@suss/intent-ir';
|
|
3
|
+
export { IntentFinding } from '@suss/intent-ir';
|
|
4
|
+
import { SuppressionRule } from '@suss/ir-core';
|
|
5
|
+
|
|
6
|
+
/** A boundary intent that was paired and compared against code. */
|
|
7
|
+
interface CheckedBoundaryIntent {
|
|
8
|
+
kind: "boundary";
|
|
9
|
+
/** The intent doc's `name`. */
|
|
10
|
+
intent: string;
|
|
11
|
+
/** The boundary key it paired on. */
|
|
12
|
+
boundary: string;
|
|
13
|
+
/** Implementations compared, as `${file}::${name}`. Empty when none. */
|
|
14
|
+
implementations: string[];
|
|
15
|
+
}
|
|
16
|
+
/** A PRD whose scenario links were resolved against the loaded system intents. */
|
|
17
|
+
interface CheckedPrd {
|
|
18
|
+
kind: "prd";
|
|
19
|
+
/** The PRD doc's `title`. */
|
|
20
|
+
intent: string;
|
|
21
|
+
/** Total scenarios walked. */
|
|
22
|
+
scenarios: number;
|
|
23
|
+
/** Scenarios whose every link resolved to a declared outcome (had >=1 link). */
|
|
24
|
+
resolved: number;
|
|
25
|
+
/** Scenarios carrying no structured link (a valid pending state). */
|
|
26
|
+
unlinked: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A declared intent that was compared — either a boundary intent paired
|
|
30
|
+
* against code or a PRD whose scenario links were resolved. Discriminated
|
|
31
|
+
* on `kind` so callers render both without a parallel structure; when a
|
|
32
|
+
* third doc kind (workflow) ships it extends this union.
|
|
33
|
+
*/
|
|
34
|
+
type CheckedIntent = CheckedBoundaryIntent | CheckedPrd;
|
|
35
|
+
/** An intent doc that was loaded but not compared, and why. */
|
|
36
|
+
interface UncheckedIntent {
|
|
37
|
+
/** The intent doc's `name` (boundary) or `title` (prd). */
|
|
38
|
+
intent: string;
|
|
39
|
+
reason: "unkeyable";
|
|
40
|
+
/** Human-readable explanation, render-ready. */
|
|
41
|
+
detail: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The full result of an intent-agreement pass. Mirrors the behavioural
|
|
45
|
+
* checker's shape philosophy (`checkAll` → findings + pairs +
|
|
46
|
+
* unmatched): findings are what to fix; checked / unchecked are the
|
|
47
|
+
* coverage accounting — which declared intent was actually compared.
|
|
48
|
+
* Callers render or gate on this without knowing which doc kinds the
|
|
49
|
+
* checker compared — boundary intents and PRDs both land in `checked`
|
|
50
|
+
* (a discriminated union). `unchecked` is reserved for intent that
|
|
51
|
+
* couldn't be compared at all (an unkeyable boundary), never silently
|
|
52
|
+
* dropped.
|
|
53
|
+
*/
|
|
54
|
+
interface CheckIntentResult {
|
|
55
|
+
findings: IntentFinding[];
|
|
56
|
+
checked: CheckedIntent[];
|
|
57
|
+
unchecked: UncheckedIntent[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compare every loaded intent doc against what's known. Boundary intents
|
|
61
|
+
* pair against the code summaries sharing their boundary key; PRDs resolve
|
|
62
|
+
* each scenario's link against the loaded boundary intents (coverage). An
|
|
63
|
+
* intent that can't be compared (an unkeyable boundary) is reported in
|
|
64
|
+
* `unchecked`, never silently dropped.
|
|
65
|
+
*
|
|
66
|
+
* Findings against `source: "inferred"` intent are downgraded one severity
|
|
67
|
+
* level — the intent describes what the code did when the inference ran, so
|
|
68
|
+
* a divergence is most likely a code change since, not an authoring error.
|
|
69
|
+
* Curation (`"inferred, curated"`) restores full severity.
|
|
70
|
+
*/
|
|
71
|
+
declare function checkIntentAgreement(intents: IntentSummary[], code: BehavioralSummary[]): CheckIntentResult;
|
|
72
|
+
/**
|
|
73
|
+
* Apply .sussignore rules to intent findings, using the shared
|
|
74
|
+
* pipeline from @suss/ir-core (same rule shape and semantics as the
|
|
75
|
+
* behavioural checker's `applySuppressions`). Rule discriminators map
|
|
76
|
+
* as: `kind` → the intent finding kind; `boundary` → the finding's
|
|
77
|
+
* boundary key (exact for `fn:` / `gql:` keys, path-normalized for
|
|
78
|
+
* REST). A rule that specifies `consumer` never matches an intent
|
|
79
|
+
* finding — there is no consumer side.
|
|
80
|
+
*/
|
|
81
|
+
declare function applyIntentSuppressions(findings: IntentFinding[], rules: SuppressionRule[], opts?: {
|
|
82
|
+
keepHidden?: boolean;
|
|
83
|
+
}): IntentFinding[];
|
|
84
|
+
|
|
85
|
+
export { type CheckIntentResult, type CheckedBoundaryIntent, type CheckedIntent, type CheckedPrd, type UncheckedIntent, applyIntentSuppressions, checkIntentAgreement };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { BehavioralSummary } from '@suss/behavioral-ir';
|
|
2
|
+
import { IntentFinding, IntentSummary } from '@suss/intent-ir';
|
|
3
|
+
export { IntentFinding } from '@suss/intent-ir';
|
|
4
|
+
import { SuppressionRule } from '@suss/ir-core';
|
|
5
|
+
|
|
6
|
+
/** A boundary intent that was paired and compared against code. */
|
|
7
|
+
interface CheckedBoundaryIntent {
|
|
8
|
+
kind: "boundary";
|
|
9
|
+
/** The intent doc's `name`. */
|
|
10
|
+
intent: string;
|
|
11
|
+
/** The boundary key it paired on. */
|
|
12
|
+
boundary: string;
|
|
13
|
+
/** Implementations compared, as `${file}::${name}`. Empty when none. */
|
|
14
|
+
implementations: string[];
|
|
15
|
+
}
|
|
16
|
+
/** A PRD whose scenario links were resolved against the loaded system intents. */
|
|
17
|
+
interface CheckedPrd {
|
|
18
|
+
kind: "prd";
|
|
19
|
+
/** The PRD doc's `title`. */
|
|
20
|
+
intent: string;
|
|
21
|
+
/** Total scenarios walked. */
|
|
22
|
+
scenarios: number;
|
|
23
|
+
/** Scenarios whose every link resolved to a declared outcome (had >=1 link). */
|
|
24
|
+
resolved: number;
|
|
25
|
+
/** Scenarios carrying no structured link (a valid pending state). */
|
|
26
|
+
unlinked: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A declared intent that was compared — either a boundary intent paired
|
|
30
|
+
* against code or a PRD whose scenario links were resolved. Discriminated
|
|
31
|
+
* on `kind` so callers render both without a parallel structure; when a
|
|
32
|
+
* third doc kind (workflow) ships it extends this union.
|
|
33
|
+
*/
|
|
34
|
+
type CheckedIntent = CheckedBoundaryIntent | CheckedPrd;
|
|
35
|
+
/** An intent doc that was loaded but not compared, and why. */
|
|
36
|
+
interface UncheckedIntent {
|
|
37
|
+
/** The intent doc's `name` (boundary) or `title` (prd). */
|
|
38
|
+
intent: string;
|
|
39
|
+
reason: "unkeyable";
|
|
40
|
+
/** Human-readable explanation, render-ready. */
|
|
41
|
+
detail: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The full result of an intent-agreement pass. Mirrors the behavioural
|
|
45
|
+
* checker's shape philosophy (`checkAll` → findings + pairs +
|
|
46
|
+
* unmatched): findings are what to fix; checked / unchecked are the
|
|
47
|
+
* coverage accounting — which declared intent was actually compared.
|
|
48
|
+
* Callers render or gate on this without knowing which doc kinds the
|
|
49
|
+
* checker compared — boundary intents and PRDs both land in `checked`
|
|
50
|
+
* (a discriminated union). `unchecked` is reserved for intent that
|
|
51
|
+
* couldn't be compared at all (an unkeyable boundary), never silently
|
|
52
|
+
* dropped.
|
|
53
|
+
*/
|
|
54
|
+
interface CheckIntentResult {
|
|
55
|
+
findings: IntentFinding[];
|
|
56
|
+
checked: CheckedIntent[];
|
|
57
|
+
unchecked: UncheckedIntent[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compare every loaded intent doc against what's known. Boundary intents
|
|
61
|
+
* pair against the code summaries sharing their boundary key; PRDs resolve
|
|
62
|
+
* each scenario's link against the loaded boundary intents (coverage). An
|
|
63
|
+
* intent that can't be compared (an unkeyable boundary) is reported in
|
|
64
|
+
* `unchecked`, never silently dropped.
|
|
65
|
+
*
|
|
66
|
+
* Findings against `source: "inferred"` intent are downgraded one severity
|
|
67
|
+
* level — the intent describes what the code did when the inference ran, so
|
|
68
|
+
* a divergence is most likely a code change since, not an authoring error.
|
|
69
|
+
* Curation (`"inferred, curated"`) restores full severity.
|
|
70
|
+
*/
|
|
71
|
+
declare function checkIntentAgreement(intents: IntentSummary[], code: BehavioralSummary[]): CheckIntentResult;
|
|
72
|
+
/**
|
|
73
|
+
* Apply .sussignore rules to intent findings, using the shared
|
|
74
|
+
* pipeline from @suss/ir-core (same rule shape and semantics as the
|
|
75
|
+
* behavioural checker's `applySuppressions`). Rule discriminators map
|
|
76
|
+
* as: `kind` → the intent finding kind; `boundary` → the finding's
|
|
77
|
+
* boundary key (exact for `fn:` / `gql:` keys, path-normalized for
|
|
78
|
+
* REST). A rule that specifies `consumer` never matches an intent
|
|
79
|
+
* finding — there is no consumer side.
|
|
80
|
+
*/
|
|
81
|
+
declare function applyIntentSuppressions(findings: IntentFinding[], rules: SuppressionRule[], opts?: {
|
|
82
|
+
keepHidden?: boolean;
|
|
83
|
+
}): IntentFinding[];
|
|
84
|
+
|
|
85
|
+
export { type CheckIntentResult, type CheckedBoundaryIntent, type CheckedIntent, type CheckedPrd, type UncheckedIntent, applyIntentSuppressions, checkIntentAgreement };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { BOUNDARY_ROLE } from "@suss/behavioral-ir";
|
|
3
|
+
import {
|
|
4
|
+
applySuppressionsToFindings,
|
|
5
|
+
bodyShapesMatch,
|
|
6
|
+
boundaryKey,
|
|
7
|
+
ruleBoundaryMatchesKey
|
|
8
|
+
} from "@suss/ir-core";
|
|
9
|
+
function checkIntentAgreement(intents, code) {
|
|
10
|
+
const findings = [];
|
|
11
|
+
const checked = [];
|
|
12
|
+
const unchecked = [];
|
|
13
|
+
const codeByBoundary = indexCodeByBoundary(code);
|
|
14
|
+
const boundaryByName = indexBoundaryIntentsByName(intents);
|
|
15
|
+
for (const intent of intents) {
|
|
16
|
+
if (intent.kind === "prd") {
|
|
17
|
+
const result2 = checkPrdCoverage(intent, boundaryByName);
|
|
18
|
+
findings.push(...withProvenance(result2.findings, intent.source));
|
|
19
|
+
checked.push(result2.checked);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const result = checkBoundaryIntent(intent, codeByBoundary);
|
|
23
|
+
findings.push(...withProvenance(result.findings, intent.source));
|
|
24
|
+
checked.push(...result.checked);
|
|
25
|
+
unchecked.push(...result.unchecked);
|
|
26
|
+
}
|
|
27
|
+
return { findings, checked, unchecked };
|
|
28
|
+
}
|
|
29
|
+
function checkBoundaryIntent(intent, codeByBoundary) {
|
|
30
|
+
const key = boundaryKey(intent.boundary);
|
|
31
|
+
if (key === null) {
|
|
32
|
+
return {
|
|
33
|
+
findings: [
|
|
34
|
+
{
|
|
35
|
+
kind: "unkeyableBoundary",
|
|
36
|
+
severity: "warning",
|
|
37
|
+
boundary: unkeyedBoundaryLabel(intent.boundary),
|
|
38
|
+
intent: { name: intent.name },
|
|
39
|
+
message: `Intent "${intent.name}" has a ${intent.boundary.semantics.name} boundary that can't be keyed for pairing (function-call boundaries need package + exportPath); it was not checked against code.`
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
checked: [],
|
|
43
|
+
unchecked: [
|
|
44
|
+
{
|
|
45
|
+
intent: intent.name,
|
|
46
|
+
reason: "unkeyable",
|
|
47
|
+
detail: "boundary can't be keyed for pairing against code"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const impls = codeByBoundary.get(key) ?? [];
|
|
53
|
+
if (impls.length === 0) {
|
|
54
|
+
return {
|
|
55
|
+
findings: [
|
|
56
|
+
{
|
|
57
|
+
kind: "unimplementedBoundary",
|
|
58
|
+
severity: "error",
|
|
59
|
+
boundary: key,
|
|
60
|
+
intent: { name: intent.name },
|
|
61
|
+
message: `Intent "${intent.name}" declares boundary ${key} with ${intent.outcomes.length} outcome(s); no code produces this boundary.`
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
// The comparison ran — finding no implementation IS the result.
|
|
65
|
+
checked: [
|
|
66
|
+
{
|
|
67
|
+
kind: "boundary",
|
|
68
|
+
intent: intent.name,
|
|
69
|
+
boundary: key,
|
|
70
|
+
implementations: []
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
unchecked: []
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const findings = [];
|
|
77
|
+
for (const impl of impls) {
|
|
78
|
+
findings.push(...compareIntentToImpl(intent, impl, key));
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
findings,
|
|
82
|
+
checked: [
|
|
83
|
+
{
|
|
84
|
+
kind: "boundary",
|
|
85
|
+
intent: intent.name,
|
|
86
|
+
boundary: key,
|
|
87
|
+
implementations: impls.map(codeRef)
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
unchecked: []
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function codeRef(impl) {
|
|
94
|
+
return `${impl.location.file}::${impl.identity.name}`;
|
|
95
|
+
}
|
|
96
|
+
function checkPrdCoverage(prd, boundaryByName) {
|
|
97
|
+
const findings = [];
|
|
98
|
+
let resolved = 0;
|
|
99
|
+
let unlinked = 0;
|
|
100
|
+
prd.scenarios.forEach((scenario, index) => {
|
|
101
|
+
const label = scenarioLabel(scenario.title, index);
|
|
102
|
+
if (scenario.link.length === 0) {
|
|
103
|
+
unlinked += 1;
|
|
104
|
+
findings.push({
|
|
105
|
+
kind: "unlinkedScenario",
|
|
106
|
+
severity: "info",
|
|
107
|
+
boundary: prdBoundaryLabel(prd),
|
|
108
|
+
intent: { name: prd.title },
|
|
109
|
+
...scenario.title !== null ? { scenario: { title: scenario.title } } : {},
|
|
110
|
+
message: `Scenario ${label} in PRD "${prd.title}" has no structured link to a system-intent outcome; it reads on its own, but its coverage can't be checked until a link is added.`
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let allResolved = true;
|
|
115
|
+
for (const ref of scenario.link) {
|
|
116
|
+
const finding = resolveScenarioLink(
|
|
117
|
+
prd,
|
|
118
|
+
scenario.title,
|
|
119
|
+
label,
|
|
120
|
+
ref,
|
|
121
|
+
boundaryByName
|
|
122
|
+
);
|
|
123
|
+
if (finding !== null) {
|
|
124
|
+
findings.push(finding);
|
|
125
|
+
allResolved = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (allResolved) {
|
|
129
|
+
resolved += 1;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
findings,
|
|
134
|
+
checked: {
|
|
135
|
+
kind: "prd",
|
|
136
|
+
intent: prd.title,
|
|
137
|
+
scenarios: prd.scenarios.length,
|
|
138
|
+
resolved,
|
|
139
|
+
unlinked
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function resolveScenarioLink(prd, scenarioTitle, label, ref, boundaryByName) {
|
|
144
|
+
const dot = ref.indexOf(".");
|
|
145
|
+
const name = dot >= 0 ? ref.slice(0, dot) : ref;
|
|
146
|
+
const outcomeId = dot >= 0 ? ref.slice(dot + 1) : "";
|
|
147
|
+
const scenarioRef = {
|
|
148
|
+
...scenarioTitle !== null ? { title: scenarioTitle } : {},
|
|
149
|
+
link: ref
|
|
150
|
+
};
|
|
151
|
+
const matches = boundaryByName.get(name) ?? [];
|
|
152
|
+
if (matches.length === 0) {
|
|
153
|
+
return {
|
|
154
|
+
kind: "danglingScenarioLink",
|
|
155
|
+
severity: "warning",
|
|
156
|
+
boundary: prdBoundaryLabel(prd),
|
|
157
|
+
intent: { name: prd.title },
|
|
158
|
+
scenario: scenarioRef,
|
|
159
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but no boundary intent named "${name}" is loaded.`
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (matches.length > 1) {
|
|
163
|
+
return {
|
|
164
|
+
kind: "ambiguousScenarioLink",
|
|
165
|
+
severity: "warning",
|
|
166
|
+
boundary: prdBoundaryLabel(prd),
|
|
167
|
+
intent: { name: prd.title },
|
|
168
|
+
scenario: scenarioRef,
|
|
169
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but ${matches.length} boundary intents are named "${name}"; rename them so the link resolves to one.`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const target = matches[0];
|
|
173
|
+
if (outcomeId === "" || !target.outcomes.some((o) => o.id === outcomeId)) {
|
|
174
|
+
const known = target.outcomes.map((o) => o.id).join(", ");
|
|
175
|
+
return {
|
|
176
|
+
kind: "danglingScenarioLink",
|
|
177
|
+
severity: "warning",
|
|
178
|
+
// The intent resolved even though the outcome didn't — key on its
|
|
179
|
+
// boundary so a narrow .sussignore rule can target this finding.
|
|
180
|
+
boundary: boundaryKey(target.boundary) ?? prdBoundaryLabel(prd),
|
|
181
|
+
intent: { name: prd.title },
|
|
182
|
+
scenario: scenarioRef,
|
|
183
|
+
message: `Scenario ${label} in PRD "${prd.title}" links to "${ref}", but boundary intent "${name}" declares no outcome "${outcomeId}" (known outcomes: ${known}).`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
function scenarioLabel(title, index) {
|
|
189
|
+
return title !== null ? `"${title}"` : `#${index + 1}`;
|
|
190
|
+
}
|
|
191
|
+
function prdBoundaryLabel(prd) {
|
|
192
|
+
return `prd:${prd.title}`;
|
|
193
|
+
}
|
|
194
|
+
function indexBoundaryIntentsByName(intents) {
|
|
195
|
+
const byName = /* @__PURE__ */ new Map();
|
|
196
|
+
for (const intent of intents) {
|
|
197
|
+
if (intent.kind !== "boundary") {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const bucket = byName.get(intent.name);
|
|
201
|
+
if (bucket === void 0) {
|
|
202
|
+
byName.set(intent.name, [intent]);
|
|
203
|
+
} else {
|
|
204
|
+
bucket.push(intent);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return byName;
|
|
208
|
+
}
|
|
209
|
+
var SEVERITY_DOWNGRADE = {
|
|
210
|
+
error: "warning",
|
|
211
|
+
warning: "info",
|
|
212
|
+
info: "info"
|
|
213
|
+
};
|
|
214
|
+
function withProvenance(findings, source) {
|
|
215
|
+
if (source !== "inferred") {
|
|
216
|
+
return findings;
|
|
217
|
+
}
|
|
218
|
+
return findings.map((f) => ({
|
|
219
|
+
...f,
|
|
220
|
+
severity: SEVERITY_DOWNGRADE[f.severity]
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
function applyIntentSuppressions(findings, rules, opts = {}) {
|
|
224
|
+
return applySuppressionsToFindings(
|
|
225
|
+
findings,
|
|
226
|
+
rules,
|
|
227
|
+
(rule, finding) => {
|
|
228
|
+
if (rule.consumer !== void 0) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return rule.boundary === void 0 || ruleBoundaryMatchesKey(rule.boundary, finding.boundary);
|
|
232
|
+
},
|
|
233
|
+
opts
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
function indexCodeByBoundary(code) {
|
|
237
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
238
|
+
for (const summary of code) {
|
|
239
|
+
if (BOUNDARY_ROLE[summary.kind] !== "provider") {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const binding = summary.identity.boundaryBinding;
|
|
243
|
+
if (binding === null) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const key = boundaryKey(binding);
|
|
247
|
+
if (key === null) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const bucket = byKey.get(key);
|
|
251
|
+
if (bucket === void 0) {
|
|
252
|
+
byKey.set(key, [summary]);
|
|
253
|
+
} else {
|
|
254
|
+
bucket.push(summary);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return byKey;
|
|
258
|
+
}
|
|
259
|
+
function compareIntentToImpl(intent, impl, boundary) {
|
|
260
|
+
const findings = [];
|
|
261
|
+
const ref = codeRef(impl);
|
|
262
|
+
const codeOutcomes = impl.transitions.map(toCodeOutcome).filter((o) => o !== null);
|
|
263
|
+
for (const outcome of intent.outcomes) {
|
|
264
|
+
const matches = codeOutcomes.filter((co) => outcomeMatches(outcome, co));
|
|
265
|
+
if (matches.length === 0) {
|
|
266
|
+
findings.push({
|
|
267
|
+
kind: "uncoveredOutcome",
|
|
268
|
+
severity: "error",
|
|
269
|
+
boundary,
|
|
270
|
+
intent: { name: intent.name, outcomeId: outcome.id },
|
|
271
|
+
code: ref,
|
|
272
|
+
message: `Intent "${intent.name}" declares ${describeOutcome(outcome)} at ${boundary}; ${impl.identity.name} has no transition that produces it.`
|
|
273
|
+
});
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const declaredBody = outcome.body;
|
|
277
|
+
if (declaredBody === null) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const bodied = matches.filter(
|
|
281
|
+
(m) => m.body !== null
|
|
282
|
+
);
|
|
283
|
+
if (bodied.length === 0) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const verdicts = bodied.map((m) => bodyShapesMatch(m.body, declaredBody));
|
|
287
|
+
if (verdicts.some((v) => v !== "nomatch")) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
findings.push({
|
|
291
|
+
kind: "outcomeShapeMismatch",
|
|
292
|
+
severity: "error",
|
|
293
|
+
boundary,
|
|
294
|
+
intent: { name: intent.name, outcomeId: outcome.id },
|
|
295
|
+
code: ref,
|
|
296
|
+
message: `Body shape for ${describeOutcome(outcome)} at ${boundary} disagrees with intent "${intent.name}": ${impl.identity.name} produces an incompatible shape.`
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const declared = new Set(
|
|
300
|
+
intent.outcomes.filter((o) => o.kind === "response" && o.status !== null).map((o) => o.status)
|
|
301
|
+
);
|
|
302
|
+
const undeclaredStatuses = /* @__PURE__ */ new Set();
|
|
303
|
+
for (const co of codeOutcomes) {
|
|
304
|
+
if (co.kind !== "response" || co.status === null || declared.has(co.status)) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
undeclaredStatuses.add(co.status);
|
|
308
|
+
}
|
|
309
|
+
for (const status of undeclaredStatuses) {
|
|
310
|
+
findings.push({
|
|
311
|
+
kind: "undeclaredOutcome",
|
|
312
|
+
severity: "info",
|
|
313
|
+
boundary,
|
|
314
|
+
intent: { name: intent.name },
|
|
315
|
+
code: ref,
|
|
316
|
+
message: `${impl.identity.name} produces status ${status} at ${boundary}; intent "${intent.name}" does not declare it.`
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return findings;
|
|
320
|
+
}
|
|
321
|
+
function toCodeOutcome(t) {
|
|
322
|
+
const output = t.output;
|
|
323
|
+
if (output.type === "response") {
|
|
324
|
+
const status = output.statusCode !== null && output.statusCode.type === "literal" ? Number(output.statusCode.value) : null;
|
|
325
|
+
return {
|
|
326
|
+
kind: "response",
|
|
327
|
+
status: status !== null && Number.isFinite(status) ? status : null,
|
|
328
|
+
body: output.body ?? null,
|
|
329
|
+
errorType: null
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (output.type === "return") {
|
|
333
|
+
return {
|
|
334
|
+
kind: "return",
|
|
335
|
+
status: null,
|
|
336
|
+
body: output.value,
|
|
337
|
+
errorType: null
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (output.type === "throw") {
|
|
341
|
+
return {
|
|
342
|
+
kind: "throw",
|
|
343
|
+
status: null,
|
|
344
|
+
body: null,
|
|
345
|
+
errorType: output.exceptionType
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
function outcomeMatches(intent, code) {
|
|
351
|
+
if (intent.kind !== code.kind) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (intent.kind === "response") {
|
|
355
|
+
return intent.status === code.status;
|
|
356
|
+
}
|
|
357
|
+
if (intent.kind === "throw") {
|
|
358
|
+
return intent.errorType === null || code.errorType === null || intent.errorType === code.errorType;
|
|
359
|
+
}
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
function unkeyedBoundaryLabel(binding) {
|
|
363
|
+
const semantics = binding.semantics;
|
|
364
|
+
if (semantics.name === "function-call") {
|
|
365
|
+
const target = semantics.module ?? semantics.package ?? "?";
|
|
366
|
+
return `fn:${target}::${semantics.exportName ?? "?"}`;
|
|
367
|
+
}
|
|
368
|
+
return semantics.name;
|
|
369
|
+
}
|
|
370
|
+
function describeOutcome(outcome) {
|
|
371
|
+
if (outcome.kind === "response") {
|
|
372
|
+
return `status ${outcome.status}`;
|
|
373
|
+
}
|
|
374
|
+
if (outcome.kind === "throw") {
|
|
375
|
+
return outcome.errorType !== null ? `throw ${outcome.errorType}` : "a thrown error";
|
|
376
|
+
}
|
|
377
|
+
return "a return value";
|
|
378
|
+
}
|
|
379
|
+
export {
|
|
380
|
+
applyIntentSuppressions,
|
|
381
|
+
checkIntentAgreement
|
|
382
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@suss/checker-intent",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Pair team-authored intent (IntentSummary) against derived code (BehavioralSummary) and report where they diverge.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"suss",
|
|
8
|
+
"intent",
|
|
9
|
+
"checker",
|
|
10
|
+
"coverage"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Nimbus Cloud AI LLC",
|
|
14
|
+
"homepage": "https://github.com/nimbuscloud-ai/suss/tree/main/packages/checker-intent#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/nimbuscloud-ai/suss.git",
|
|
18
|
+
"directory": "packages/checker-intent"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/nimbuscloud-ai/suss/issues"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:coverage": "vitest run --coverage",
|
|
42
|
+
"lint": "biome check .",
|
|
43
|
+
"lint:fix": "biome check --write .",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"zod": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@suss/behavioral-ir": "0.0.1",
|
|
51
|
+
"@suss/intent-ir": "0.0.1",
|
|
52
|
+
"@suss/ir-core": "0.0.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"tsup": "*",
|
|
56
|
+
"typescript": "*",
|
|
57
|
+
"vitest": "*",
|
|
58
|
+
"zod": "^4.0.0"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
}
|
|
63
|
+
}
|