ndrstnd 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 +201 -0
- package/README.md +56 -0
- package/dist/server/agent.d.ts +51 -0
- package/dist/server/agent.js +77 -0
- package/dist/server/agent.js.map +1 -0
- package/dist/server/analysis-core.d.ts +93 -0
- package/dist/server/analysis-core.js +442 -0
- package/dist/server/analysis-core.js.map +1 -0
- package/dist/server/analyze.d.ts +55 -0
- package/dist/server/analyze.js +72 -0
- package/dist/server/analyze.js.map +1 -0
- package/dist/server/artifact.d.ts +8 -0
- package/dist/server/artifact.js +43 -0
- package/dist/server/artifact.js.map +1 -0
- package/dist/server/claude.d.ts +29 -0
- package/dist/server/claude.js +243 -0
- package/dist/server/claude.js.map +1 -0
- package/dist/server/cli-support.d.ts +7 -0
- package/dist/server/cli-support.js +13 -0
- package/dist/server/cli-support.js.map +1 -0
- package/dist/server/cli.d.ts +2 -0
- package/dist/server/cli.js +276 -0
- package/dist/server/cli.js.map +1 -0
- package/dist/server/codex.d.ts +34 -0
- package/dist/server/codex.js +256 -0
- package/dist/server/codex.js.map +1 -0
- package/dist/server/conversation.d.ts +9 -0
- package/dist/server/conversation.js +57 -0
- package/dist/server/conversation.js.map +1 -0
- package/dist/server/evidence-ordering.d.ts +13 -0
- package/dist/server/evidence-ordering.js +143 -0
- package/dist/server/evidence-ordering.js.map +1 -0
- package/dist/server/git-model.d.ts +15 -0
- package/dist/server/git-model.js +156 -0
- package/dist/server/git-model.js.map +1 -0
- package/dist/server/git.d.ts +29 -0
- package/dist/server/git.js +124 -0
- package/dist/server/git.js.map +1 -0
- package/dist/server/http.d.ts +14 -0
- package/dist/server/http.js +139 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/preview-fixture.d.ts +1 -0
- package/dist/server/preview-fixture.js +23 -0
- package/dist/server/preview-fixture.js.map +1 -0
- package/dist/server/review-presentation.d.ts +3 -0
- package/dist/server/review-presentation.js +14 -0
- package/dist/server/review-presentation.js.map +1 -0
- package/dist/server/skill.d.ts +14 -0
- package/dist/server/skill.js +94 -0
- package/dist/server/skill.js.map +1 -0
- package/dist/server/store.d.ts +36 -0
- package/dist/server/store.js +134 -0
- package/dist/server/store.js.map +1 -0
- package/dist/server/version.d.ts +2 -0
- package/dist/server/version.js +13 -0
- package/dist/server/version.js.map +1 -0
- package/dist/shared/analysis-schema.d.ts +325 -0
- package/dist/shared/analysis-schema.js +50 -0
- package/dist/shared/analysis-schema.js.map +1 -0
- package/dist/shared/domain.d.ts +33 -0
- package/dist/shared/domain.js +2 -0
- package/dist/shared/domain.js.map +1 -0
- package/dist/web/evidence-model.d.ts +36 -0
- package/dist/web/evidence-model.js +134 -0
- package/dist/web/evidence-model.js.map +1 -0
- package/dist/web/frozen-review-data.d.ts +3 -0
- package/dist/web/frozen-review-data.js +202 -0
- package/dist/web/frozen-review-data.js.map +1 -0
- package/dist/web/language.d.ts +4 -0
- package/dist/web/language.js +14 -0
- package/dist/web/language.js.map +1 -0
- package/dist/web/page.d.ts +10 -0
- package/dist/web/page.js +1038 -0
- package/dist/web/page.js.map +1 -0
- package/dist/web/review-data.d.ts +20 -0
- package/dist/web/review-data.js +2 -0
- package/dist/web/review-data.js.map +1 -0
- package/dist/web/test-plan-model.d.ts +27 -0
- package/dist/web/test-plan-model.js +89 -0
- package/dist/web/test-plan-model.js.map +1 -0
- package/package.json +47 -0
- package/src/skill-assets/ndrstnd/SKILL.md +22 -0
- package/src/skill-assets/ndrstnd/agents/openai.yaml +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
|
79
|
+
by 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
|
|
95
|
+
Derivative 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
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying 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
|
|
163
|
+
has 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. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# ndrstnd
|
|
4
|
+
|
|
5
|
+
[](https://truizlop.github.io/ndrstnd/)
|
|
6
|
+
|
|
7
|
+
ndrstnd is a local comprehension workspace for large, agent-produced branch changes. It turns a branch diff into an evidence-linked Story, Timeline, Test plan, and Full diff instead of asking a reviewer to start in alphabetical path order.
|
|
8
|
+
|
|
9
|
+
## Install and start
|
|
10
|
+
|
|
11
|
+
npm install -g ndrstnd
|
|
12
|
+
ndrstnd auth login
|
|
13
|
+
ndrstnd skill install
|
|
14
|
+
ndrstnd review feature/my-change --base main --repo /path/to/repository
|
|
15
|
+
|
|
16
|
+
The command prints the review scope (base, changed files, whether uncommitted changes are included), drafts the narrative with your analysis agent (printing a heartbeat line every 15 seconds naming what the agent is doing, so a long analysis is never mistaken for a hang), then writes and opens a self-contained HTML review artifact. Artifacts live under the reviewed repository’s Git-ignored `.ndrstnd/` directory, are private to the local working copy, and are meant to be short-lived; delete them when the review is done.
|
|
17
|
+
|
|
18
|
+
ndrstnd analyzes with Codex or Claude Code and uses the agent’s existing authenticated session. It never stores a token itself.
|
|
19
|
+
|
|
20
|
+
## Choosing the agent
|
|
21
|
+
|
|
22
|
+
Every command accepts `--agent codex` or `--agent claude`:
|
|
23
|
+
|
|
24
|
+
ndrstnd auth login --agent claude
|
|
25
|
+
ndrstnd review feature/my-change --base main --agent claude
|
|
26
|
+
|
|
27
|
+
Without `--agent`, ndrstnd honors the `NDRSTND_AGENT` environment variable; then, when the command runs inside a Codex or Claude Code session (as it does when the installed skill triggers it), it uses that hosting agent; otherwise it falls back to the first installed CLI, preferring Codex. `ndrstnd auth status` reports both agents, and `ndrstnd skill install` installs the skill for every agent that is set up on the machine.
|
|
28
|
+
|
|
29
|
+
## Choosing the scope
|
|
30
|
+
|
|
31
|
+
Pick the invocation so the diff equals exactly the work being reviewed:
|
|
32
|
+
|
|
33
|
+
ndrstnd review feature/my-change --base main # committed work on a feature branch
|
|
34
|
+
ndrstnd review --uncommitted # only uncommitted working-tree changes
|
|
35
|
+
ndrstnd review --base main # commits since branching plus uncommitted changes
|
|
36
|
+
ndrstnd review --base empty # a repository with no useful base
|
|
37
|
+
|
|
38
|
+
Reviews always compare against the merge-base with the given base, so commits that landed on the base branch after the fork point never enter the review. Re-running an unchanged review reuses the cached analysis and says so; pass `--fresh` to analyze again.
|
|
39
|
+
|
|
40
|
+
Without a branch, ndrstnd reviews the checked-out branch including staged, unstaged, and untracked changes. When an inferred base would pull extra local commits into the review, ndrstnd warns before analyzing.
|
|
41
|
+
|
|
42
|
+
Add `--conversation path/to/ndrstnd-conversation-v1.json` to ground the narrative in the dialogue that produced the branch: motives, rejected alternatives, constraints, and any observed test runs feed the Story and the Test plan.
|
|
43
|
+
|
|
44
|
+
## Scope
|
|
45
|
+
|
|
46
|
+
ndrstnd is for understanding code: it explains the implementation story, evidence, risk signals, and selected lines. It deliberately does not critique the change, submit review comments, or edit the branch.
|
|
47
|
+
|
|
48
|
+
## Development structure
|
|
49
|
+
|
|
50
|
+
ndrstnd keeps deterministic transformation logic in small core modules and side effects at the boundary:
|
|
51
|
+
|
|
52
|
+
- `src/server/git-model.ts` parses Git output and classifies files; `src/server/git.ts` runs Git commands.
|
|
53
|
+
- `src/server/analysis-core.ts` builds prompts and validates the analysis contract; `src/server/analyze.ts` runs the analysis through the selected agent, which `src/server/agent.ts` resolves and `src/server/codex.ts` / `src/server/claude.ts` implement.
|
|
54
|
+
- `src/web/evidence-model.ts`, `src/web/test-plan-model.ts`, and `src/web/language.ts` derive presentation data; `src/web/page.ts` renders the self-contained artifact.
|
|
55
|
+
|
|
56
|
+
Run `npm run lint`, `npm test`, and `npm run build` before committing. The test suite includes pure unit tests, Git/HTTP/store integration tests, rendered artifact and browser-script UI tests, and an end-to-end artifact pipeline test.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type AuthStatus = {
|
|
2
|
+
state: "signed-in";
|
|
3
|
+
accountType: string;
|
|
4
|
+
} | {
|
|
5
|
+
state: "signed-out";
|
|
6
|
+
} | {
|
|
7
|
+
state: "unreachable";
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
/** A liveness snapshot of a running turn, emitted on every agent event so callers can print heartbeats. */
|
|
11
|
+
export interface TurnActivity {
|
|
12
|
+
label: string;
|
|
13
|
+
notifications: number;
|
|
14
|
+
draftCharacters: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentTextThread {
|
|
17
|
+
send(prompt: string, onActivity?: (activity: TurnActivity) => void): Promise<string>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentClient {
|
|
21
|
+
startTextThread(cwd: string): Promise<AgentTextThread>;
|
|
22
|
+
close(): void;
|
|
23
|
+
}
|
|
24
|
+
export type ReviewAgentId = "codex" | "claude";
|
|
25
|
+
export interface ReviewAgent {
|
|
26
|
+
id: ReviewAgentId;
|
|
27
|
+
/** Human-readable name used in CLI output, error messages, and artifacts. */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Executable probed on PATH when no agent is requested explicitly. */
|
|
30
|
+
command: string;
|
|
31
|
+
/** Arguments after the command that start the interactive sign-in flow. */
|
|
32
|
+
loginArgs: string[];
|
|
33
|
+
/** The agent's configuration directory, whose skills/ subdirectory receives the ndrstnd skill. */
|
|
34
|
+
homeDirectory(): string;
|
|
35
|
+
createClient(): AgentClient;
|
|
36
|
+
getAuthStatus(): Promise<AuthStatus>;
|
|
37
|
+
}
|
|
38
|
+
export declare const codexAgent: ReviewAgent;
|
|
39
|
+
export declare const claudeAgent: ReviewAgent;
|
|
40
|
+
/** Codex stays first: it was ndrstnd's original agent, so it remains the default when both CLIs are installed. */
|
|
41
|
+
export declare const reviewAgents: readonly ReviewAgent[];
|
|
42
|
+
export declare function reviewAgentById(id: string): ReviewAgent | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The agent whose session this process was launched from, if any. Each CLI marks
|
|
45
|
+
* the shell commands it runs: Claude Code sets CLAUDECODE, and Codex sets
|
|
46
|
+
* CODEX_SANDBOX for sandboxed commands. Claude Code wins when both appear,
|
|
47
|
+
* because its marker is set unconditionally and so names the innermost host.
|
|
48
|
+
*/
|
|
49
|
+
export declare function hostAgent(env?: NodeJS.ProcessEnv): ReviewAgent | undefined;
|
|
50
|
+
/** Resolves --agent, then NDRSTND_AGENT, then the agent hosting this process, then the first supported agent whose CLI is installed. */
|
|
51
|
+
export declare function resolveReviewAgent(requested?: string | undefined): Promise<ReviewAgent>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { delimiter, join } from "node:path";
|
|
5
|
+
import { CodexAppServerClient, getCodexAuthStatus } from "./codex.js";
|
|
6
|
+
import { ClaudeCodeClient, getClaudeAuthStatus } from "./claude.js";
|
|
7
|
+
export const codexAgent = {
|
|
8
|
+
id: "codex",
|
|
9
|
+
name: "Codex",
|
|
10
|
+
command: "codex",
|
|
11
|
+
loginArgs: ["login"],
|
|
12
|
+
homeDirectory: () => process.env.CODEX_HOME ?? join(homedir(), ".codex"),
|
|
13
|
+
createClient: () => new CodexAppServerClient(),
|
|
14
|
+
getAuthStatus: getCodexAuthStatus,
|
|
15
|
+
};
|
|
16
|
+
export const claudeAgent = {
|
|
17
|
+
id: "claude",
|
|
18
|
+
name: "Claude Code",
|
|
19
|
+
command: "claude",
|
|
20
|
+
loginArgs: ["auth", "login"],
|
|
21
|
+
homeDirectory: () => process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"),
|
|
22
|
+
createClient: () => new ClaudeCodeClient(),
|
|
23
|
+
getAuthStatus: getClaudeAuthStatus,
|
|
24
|
+
};
|
|
25
|
+
/** Codex stays first: it was ndrstnd's original agent, so it remains the default when both CLIs are installed. */
|
|
26
|
+
export const reviewAgents = [codexAgent, claudeAgent];
|
|
27
|
+
export function reviewAgentById(id) {
|
|
28
|
+
return reviewAgents.find((agent) => agent.id === id);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The agent whose session this process was launched from, if any. Each CLI marks
|
|
32
|
+
* the shell commands it runs: Claude Code sets CLAUDECODE, and Codex sets
|
|
33
|
+
* CODEX_SANDBOX for sandboxed commands. Claude Code wins when both appear,
|
|
34
|
+
* because its marker is set unconditionally and so names the innermost host.
|
|
35
|
+
*/
|
|
36
|
+
export function hostAgent(env = process.env) {
|
|
37
|
+
if (env["CLAUDECODE"] !== undefined && env["CLAUDECODE"] !== "")
|
|
38
|
+
return claudeAgent;
|
|
39
|
+
if (env["CODEX_SANDBOX"] !== undefined && env["CODEX_SANDBOX"] !== "")
|
|
40
|
+
return codexAgent;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Resolves --agent, then NDRSTND_AGENT, then the agent hosting this process, then the first supported agent whose CLI is installed. */
|
|
44
|
+
export async function resolveReviewAgent(requested = process.env.NDRSTND_AGENT) {
|
|
45
|
+
if (requested !== undefined && requested !== "") {
|
|
46
|
+
const agent = reviewAgentById(requested);
|
|
47
|
+
if (agent === undefined)
|
|
48
|
+
throw new Error(`Unknown analysis agent: ${requested}. Supported agents: ${reviewAgents.map((candidate) => candidate.id).join(", ")}.`);
|
|
49
|
+
return agent;
|
|
50
|
+
}
|
|
51
|
+
const host = hostAgent();
|
|
52
|
+
if (host !== undefined)
|
|
53
|
+
return host;
|
|
54
|
+
for (const agent of reviewAgents) {
|
|
55
|
+
if (await commandIsInstalled(agent.command))
|
|
56
|
+
return agent;
|
|
57
|
+
}
|
|
58
|
+
return codexAgent;
|
|
59
|
+
}
|
|
60
|
+
async function commandIsInstalled(command) {
|
|
61
|
+
const extensions = process.platform === "win32" ? ["", ".cmd", ".exe", ".bat"] : [""];
|
|
62
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
63
|
+
if (directory === "")
|
|
64
|
+
continue;
|
|
65
|
+
for (const extension of extensions) {
|
|
66
|
+
try {
|
|
67
|
+
await access(join(directory, command + extension), constants.X_OK);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Keep probing the remaining PATH entries.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/server/agent.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { AnalysisDocument } from "../shared/analysis-schema.js";
|
|
2
|
+
import type { CollectedReviewInput } from "./git.js";
|
|
3
|
+
import type { ConversationContext } from "./conversation.js";
|
|
4
|
+
export declare function parseAnalysisDocument(value: unknown, input: CollectedReviewInput, options?: {
|
|
5
|
+
focus?: "require" | "salvage";
|
|
6
|
+
}): AnalysisDocument;
|
|
7
|
+
export declare const PROSE_WORD_RANGES: {
|
|
8
|
+
readonly summary: {
|
|
9
|
+
readonly min: 35;
|
|
10
|
+
readonly max: 75;
|
|
11
|
+
};
|
|
12
|
+
readonly synopsis: {
|
|
13
|
+
readonly min: 20;
|
|
14
|
+
readonly max: 55;
|
|
15
|
+
};
|
|
16
|
+
readonly beforeAfter: {
|
|
17
|
+
readonly min: 8;
|
|
18
|
+
readonly max: 40;
|
|
19
|
+
};
|
|
20
|
+
readonly goal: {
|
|
21
|
+
readonly min: 12;
|
|
22
|
+
readonly max: 40;
|
|
23
|
+
};
|
|
24
|
+
readonly youNowHave: {
|
|
25
|
+
readonly min: 12;
|
|
26
|
+
readonly max: 40;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare function analysisPrompt(input: CollectedReviewInput, conversation?: ConversationContext): string;
|
|
30
|
+
/**
|
|
31
|
+
* Inline patch text spares the analysis agent a git round trip per hunk, the dominant cost
|
|
32
|
+
* on small and medium branches, where every inspection command is a full model
|
|
33
|
+
* turn. The budget keeps huge branches on reference-first inspection so the
|
|
34
|
+
* prompt stays bounded.
|
|
35
|
+
*/
|
|
36
|
+
export declare const INLINE_PATCH_BUDGET = 40000;
|
|
37
|
+
export declare function buildPromptReviewInput(input: CollectedReviewInput, conversation?: ConversationContext): {
|
|
38
|
+
target: string;
|
|
39
|
+
base: string;
|
|
40
|
+
mergeBase: string;
|
|
41
|
+
inspection: {
|
|
42
|
+
workingDirectory: string;
|
|
43
|
+
summaryCommand: string;
|
|
44
|
+
patchCommand: string;
|
|
45
|
+
currentFileCommand: string;
|
|
46
|
+
note: string;
|
|
47
|
+
};
|
|
48
|
+
files: {
|
|
49
|
+
id: string;
|
|
50
|
+
path: string;
|
|
51
|
+
previousPath: string | undefined;
|
|
52
|
+
status: "unknown" | "added" | "modified" | "deleted" | "renamed" | "copied";
|
|
53
|
+
binary: boolean;
|
|
54
|
+
signal: import("../shared/domain.js").FileSignal;
|
|
55
|
+
signalReason: string | undefined;
|
|
56
|
+
hunks: {
|
|
57
|
+
id: string;
|
|
58
|
+
fileId: string;
|
|
59
|
+
path: string | undefined;
|
|
60
|
+
oldStart: number;
|
|
61
|
+
newStart: number;
|
|
62
|
+
lineCount: number;
|
|
63
|
+
additions: number;
|
|
64
|
+
deletions: number;
|
|
65
|
+
context: number;
|
|
66
|
+
patch: string | undefined;
|
|
67
|
+
changedLineSamples: {
|
|
68
|
+
kind: import("../shared/domain.js").DiffLineKind;
|
|
69
|
+
oldLine: number | undefined;
|
|
70
|
+
newLine: number | undefined;
|
|
71
|
+
preview: string;
|
|
72
|
+
}[];
|
|
73
|
+
}[];
|
|
74
|
+
}[];
|
|
75
|
+
construction: {
|
|
76
|
+
suggestedEvidenceOrder: string[];
|
|
77
|
+
defineBeforeUse: {
|
|
78
|
+
symbol: string | undefined;
|
|
79
|
+
definedIn: string;
|
|
80
|
+
usedIn: string;
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
conversation: {
|
|
84
|
+
source: "portable-json" | "markdown";
|
|
85
|
+
messageCount: number;
|
|
86
|
+
excerptedMessages: {
|
|
87
|
+
role: "assistant" | "user";
|
|
88
|
+
timestamp: string | undefined;
|
|
89
|
+
excerpt: string;
|
|
90
|
+
}[];
|
|
91
|
+
} | undefined;
|
|
92
|
+
};
|
|
93
|
+
export declare function extractJson(text: string): string;
|