sloppatrol 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 +202 -0
- package/NOTICE +7 -0
- package/README.md +205 -2
- package/dist/agents/index.d.ts +9 -0
- package/dist/agents/index.js +7 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/lib/cli-runtime.d.ts +17 -0
- package/dist/agents/lib/cli-runtime.js +156 -0
- package/dist/agents/lib/cli-runtime.js.map +1 -0
- package/dist/agents/lib/mcp-server.d.ts +22 -0
- package/dist/agents/lib/mcp-server.js +94 -0
- package/dist/agents/lib/mcp-server.js.map +1 -0
- package/dist/agents/lib/model-runtime.d.ts +18 -0
- package/dist/agents/lib/model-runtime.js +151 -0
- package/dist/agents/lib/model-runtime.js.map +1 -0
- package/dist/agents/lib/repo-tools.d.ts +11 -0
- package/dist/agents/lib/repo-tools.js +79 -0
- package/dist/agents/lib/repo-tools.js.map +1 -0
- package/dist/agents/lib/schema.d.ts +15 -0
- package/dist/agents/lib/schema.js +33 -0
- package/dist/agents/lib/schema.js.map +1 -0
- package/dist/agents/lib/session.d.ts +27 -0
- package/dist/agents/lib/session.js +55 -0
- package/dist/agents/lib/session.js.map +1 -0
- package/dist/agents/lib/types.d.ts +46 -0
- package/dist/agents/lib/types.js +2 -0
- package/dist/agents/lib/types.js.map +1 -0
- package/dist/census/index.d.ts +23 -0
- package/dist/census/index.js +49 -0
- package/dist/census/index.js.map +1 -0
- package/dist/census/lib/guardrails.d.ts +7 -0
- package/dist/census/lib/guardrails.js +42 -0
- package/dist/census/lib/guardrails.js.map +1 -0
- package/dist/census/lib/signals.d.ts +19 -0
- package/dist/census/lib/signals.js +60 -0
- package/dist/census/lib/signals.js.map +1 -0
- package/dist/census/lib/stack.d.ts +12 -0
- package/dist/census/lib/stack.js +78 -0
- package/dist/census/lib/stack.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +186 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/lib/argv.d.ts +9 -0
- package/dist/cli/lib/argv.js +63 -0
- package/dist/cli/lib/argv.js.map +1 -0
- package/dist/cli/lib/doctor.d.ts +3 -0
- package/dist/cli/lib/doctor.js +51 -0
- package/dist/cli/lib/doctor.js.map +1 -0
- package/dist/cli/lib/init.d.ts +1 -0
- package/dist/cli/lib/init.js +90 -0
- package/dist/cli/lib/init.js.map +1 -0
- package/dist/cli/lib/status.d.ts +2 -0
- package/dist/cli/lib/status.js +15 -0
- package/dist/cli/lib/status.js.map +1 -0
- package/dist/cli/lib/usage.d.ts +1 -0
- package/dist/cli/lib/usage.js +32 -0
- package/dist/cli/lib/usage.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +5 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/lib/detect.d.ts +3 -0
- package/dist/config/lib/detect.js +22 -0
- package/dist/config/lib/detect.js.map +1 -0
- package/dist/config/lib/load.d.ts +15 -0
- package/dist/config/lib/load.js +40 -0
- package/dist/config/lib/load.js.map +1 -0
- package/dist/config/lib/presets.d.ts +15 -0
- package/dist/config/lib/presets.js +37 -0
- package/dist/config/lib/presets.js.map +1 -0
- package/dist/config/lib/schema.d.ts +887 -0
- package/dist/config/lib/schema.js +128 -0
- package/dist/config/lib/schema.js.map +1 -0
- package/dist/dashboard/index.d.ts +15 -0
- package/dist/dashboard/index.js +63 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/dashboard/lib/snapshot.d.ts +32 -0
- package/dist/dashboard/lib/snapshot.js +60 -0
- package/dist/dashboard/lib/snapshot.js.map +1 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/index.js +9 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/lib/agents.d.ts +25 -0
- package/dist/domain/lib/agents.js +2 -0
- package/dist/domain/lib/agents.js.map +1 -0
- package/dist/domain/lib/checks.d.ts +37 -0
- package/dist/domain/lib/checks.js +2 -0
- package/dist/domain/lib/checks.js.map +1 -0
- package/dist/domain/lib/ids.d.ts +2 -0
- package/dist/domain/lib/ids.js +7 -0
- package/dist/domain/lib/ids.js.map +1 -0
- package/dist/domain/lib/metrics.d.ts +58 -0
- package/dist/domain/lib/metrics.js +17 -0
- package/dist/domain/lib/metrics.js.map +1 -0
- package/dist/domain/lib/opportunity.d.ts +73 -0
- package/dist/domain/lib/opportunity.js +48 -0
- package/dist/domain/lib/opportunity.js.map +1 -0
- package/dist/domain/lib/proof.d.ts +61 -0
- package/dist/domain/lib/proof.js +2 -0
- package/dist/domain/lib/proof.js.map +1 -0
- package/dist/domain/lib/refactor.d.ts +50 -0
- package/dist/domain/lib/refactor.js +2 -0
- package/dist/domain/lib/refactor.js.map +1 -0
- package/dist/gate/index.d.ts +23 -0
- package/dist/gate/index.js +36 -0
- package/dist/gate/index.js.map +1 -0
- package/dist/gate/lib/checks.d.ts +13 -0
- package/dist/gate/lib/checks.js +62 -0
- package/dist/gate/lib/checks.js.map +1 -0
- package/dist/gate/lib/diff.d.ts +13 -0
- package/dist/gate/lib/diff.js +31 -0
- package/dist/gate/lib/diff.js.map +1 -0
- package/dist/gate/lib/frozen.d.ts +6 -0
- package/dist/gate/lib/frozen.js +81 -0
- package/dist/gate/lib/frozen.js.map +1 -0
- package/dist/gate/lib/guards.d.ts +23 -0
- package/dist/gate/lib/guards.js +66 -0
- package/dist/gate/lib/guards.js.map +1 -0
- package/dist/gate/lib/markers.d.ts +11 -0
- package/dist/gate/lib/markers.js +23 -0
- package/dist/gate/lib/markers.js.map +1 -0
- package/dist/gate/lib/recorded.d.ts +8 -0
- package/dist/gate/lib/recorded.js +32 -0
- package/dist/gate/lib/recorded.js.map +1 -0
- package/dist/gate/lib/test-count.d.ts +3 -0
- package/dist/gate/lib/test-count.js +23 -0
- package/dist/gate/lib/test-count.js.map +1 -0
- package/dist/git/index.d.ts +16 -0
- package/dist/git/index.js +63 -0
- package/dist/git/index.js.map +1 -0
- package/dist/github/index.d.ts +3 -0
- package/dist/github/index.js +3 -0
- package/dist/github/index.js.map +1 -0
- package/dist/github/lib/fake.d.ts +11 -0
- package/dist/github/lib/fake.js +22 -0
- package/dist/github/lib/fake.js.map +1 -0
- package/dist/github/lib/gh-cli.d.ts +13 -0
- package/dist/github/lib/gh-cli.js +55 -0
- package/dist/github/lib/gh-cli.js.map +1 -0
- package/dist/github/lib/port.d.ts +19 -0
- package/dist/github/lib/port.js +2 -0
- package/dist/github/lib/port.js.map +1 -0
- package/dist/globs/index.d.ts +4 -0
- package/dist/globs/index.js +57 -0
- package/dist/globs/index.js.map +1 -0
- package/dist/metrics/index.d.ts +23 -0
- package/dist/metrics/index.js +54 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/lib/rubric.d.ts +19 -0
- package/dist/metrics/lib/rubric.js +147 -0
- package/dist/metrics/lib/rubric.js.map +1 -0
- package/dist/metrics/lib/signals.d.ts +4 -0
- package/dist/metrics/lib/signals.js +30 -0
- package/dist/metrics/lib/signals.js.map +1 -0
- package/dist/patrol/index.d.ts +7 -0
- package/dist/patrol/index.js +7 -0
- package/dist/patrol/index.js.map +1 -0
- package/dist/patrol/lib/attempt.d.ts +10 -0
- package/dist/patrol/lib/attempt.js +80 -0
- package/dist/patrol/lib/attempt.js.map +1 -0
- package/dist/patrol/lib/base.d.ts +26 -0
- package/dist/patrol/lib/base.js +58 -0
- package/dist/patrol/lib/base.js.map +1 -0
- package/dist/patrol/lib/cycle.d.ts +17 -0
- package/dist/patrol/lib/cycle.js +61 -0
- package/dist/patrol/lib/cycle.js.map +1 -0
- package/dist/patrol/lib/deps.d.ts +10 -0
- package/dist/patrol/lib/deps.js +2 -0
- package/dist/patrol/lib/deps.js.map +1 -0
- package/dist/patrol/lib/judge.d.ts +14 -0
- package/dist/patrol/lib/judge.js +103 -0
- package/dist/patrol/lib/judge.js.map +1 -0
- package/dist/patrol/lib/lock.d.ts +8 -0
- package/dist/patrol/lib/lock.js +34 -0
- package/dist/patrol/lib/lock.js.map +1 -0
- package/dist/patrol/lib/loop.d.ts +9 -0
- package/dist/patrol/lib/loop.js +33 -0
- package/dist/patrol/lib/loop.js.map +1 -0
- package/dist/patrol/lib/pick.d.ts +11 -0
- package/dist/patrol/lib/pick.js +24 -0
- package/dist/patrol/lib/pick.js.map +1 -0
- package/dist/patrol/lib/proof-text.d.ts +3 -0
- package/dist/patrol/lib/proof-text.js +40 -0
- package/dist/patrol/lib/proof-text.js.map +1 -0
- package/dist/patrol/lib/proof.d.ts +29 -0
- package/dist/patrol/lib/proof.js +153 -0
- package/dist/patrol/lib/proof.js.map +1 -0
- package/dist/patrol/lib/publish.d.ts +14 -0
- package/dist/patrol/lib/publish.js +83 -0
- package/dist/patrol/lib/publish.js.map +1 -0
- package/dist/patrol/lib/recover.d.ts +7 -0
- package/dist/patrol/lib/recover.js +24 -0
- package/dist/patrol/lib/recover.js.map +1 -0
- package/dist/patrol/lib/retire.d.ts +7 -0
- package/dist/patrol/lib/retire.js +31 -0
- package/dist/patrol/lib/retire.js.map +1 -0
- package/dist/patrol/lib/scorecard.d.ts +15 -0
- package/dist/patrol/lib/scorecard.js +128 -0
- package/dist/patrol/lib/scorecard.js.map +1 -0
- package/dist/patrol/lib/steps.d.ts +10 -0
- package/dist/patrol/lib/steps.js +63 -0
- package/dist/patrol/lib/steps.js.map +1 -0
- package/dist/playbook/index.d.ts +3 -0
- package/dist/playbook/index.js +39 -0
- package/dist/playbook/index.js.map +1 -0
- package/dist/processes/index.d.ts +4 -0
- package/dist/processes/index.js +25 -0
- package/dist/processes/index.js.map +1 -0
- package/dist/roles/index.d.ts +6 -0
- package/dist/roles/index.js +6 -0
- package/dist/roles/index.js.map +1 -0
- package/dist/roles/lib/assessor.d.ts +21 -0
- package/dist/roles/lib/assessor.js +89 -0
- package/dist/roles/lib/assessor.js.map +1 -0
- package/dist/roles/lib/change-tools.d.ts +20 -0
- package/dist/roles/lib/change-tools.js +82 -0
- package/dist/roles/lib/change-tools.js.map +1 -0
- package/dist/roles/lib/context.d.ts +17 -0
- package/dist/roles/lib/context.js +5 -0
- package/dist/roles/lib/context.js.map +1 -0
- package/dist/roles/lib/prompts.d.ts +5 -0
- package/dist/roles/lib/prompts.js +78 -0
- package/dist/roles/lib/prompts.js.map +1 -0
- package/dist/roles/lib/refactorer.d.ts +14 -0
- package/dist/roles/lib/refactorer.js +51 -0
- package/dist/roles/lib/refactorer.js.map +1 -0
- package/dist/roles/lib/reviewer.d.ts +15 -0
- package/dist/roles/lib/reviewer.js +56 -0
- package/dist/roles/lib/reviewer.js.map +1 -0
- package/dist/roles/lib/scorecard-text.d.ts +3 -0
- package/dist/roles/lib/scorecard-text.js +29 -0
- package/dist/roles/lib/scorecard-text.js.map +1 -0
- package/dist/roles/lib/surveyor.d.ts +14 -0
- package/dist/roles/lib/surveyor.js +124 -0
- package/dist/roles/lib/surveyor.js.map +1 -0
- package/dist/rules/index.d.ts +11 -0
- package/dist/rules/index.js +81 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/store/index.d.ts +42 -0
- package/dist/store/index.js +95 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/lib/json-files.d.ts +5 -0
- package/dist/store/lib/json-files.js +26 -0
- package/dist/store/lib/json-files.js.map +1 -0
- package/package.json +58 -4
- package/playbook/principles.md +41 -0
- package/playbook/safety.md +41 -0
- package/playbook/smells.md +45 -0
- package/playbook/stacks/go.md +120 -0
- package/playbook/stacks/kotlin.md +116 -0
- package/playbook/stacks/node-backend.md +114 -0
- package/playbook/stacks/python.md +117 -0
- package/playbook/stacks/react.md +112 -0
- package/playbook/stacks/rust.md +114 -0
- package/playbook/stacks/swift.md +118 -0
- package/playbook/stacks/typescript.md +112 -0
- package/playbook/testing.md +63 -0
- package/ui/app.js +611 -0
- package/ui/index.html +37 -0
- package/ui/style.css +686 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,206 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sloppatrol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sloppatrol is a team of agents that patrols your repo all day and makes the code cleaner, one small pull request at a time. It never changes what the code does.
|
|
4
|
+
|
|
5
|
+
It is the code-quality sibling of [Bugpatrol](https://github.com/agent-labs-dev/bugpatrol) and [Speedpatrol](https://github.com/agent-labs-dev/speedpatrol): one `.sloppatrol/` folder, agent roles on any agent runtime, a patrol loop, a live dashboard, and GitHub pull requests.
|
|
6
|
+
|
|
7
|
+
- The **surveyor** reads the code and records **opportunities**: shallow modules, mixed concerns, hidden dependencies, deep imports, duplicated owners, dead code, tests that mock the team's own code.
|
|
8
|
+
- The **refactorer** makes one opportunity real, in its own git worktree.
|
|
9
|
+
- The **gate** is code, not a model. It decides what is kept: guards on the diff, then every check of your repo.
|
|
10
|
+
- The **assessor** scores code against a rubric of seven quality metrics: for the repo's scorecard, and blind, before and after, for every refactor.
|
|
11
|
+
- The **reviewer** reads a change that passed the gate. It can only reject.
|
|
12
|
+
- Each verified refactor becomes a draft pull request.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx sloppatrol init
|
|
16
|
+
npx sloppatrol
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Why you can trust a refactor
|
|
20
|
+
|
|
21
|
+
An agent proposes; code decides. A refactor is kept only when every step below passes, and no agent can overrule one.
|
|
22
|
+
|
|
23
|
+
| Step | What it checks |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| One side | A **source** refactor changes no test file, so your existing tests prove the behaviour held. A **tests** refactor changes no source file, so the unchanged source proves the new tests right. |
|
|
26
|
+
| Frozen files | No manifest, lockfile, tool config, CI file, snapshot or `.env` changes. No path in `ignore`. |
|
|
27
|
+
| No suppression | No added `@ts-ignore`, `eslint-disable`, `# type: ignore`, `as any`, coverage exclusion, or skipped or focused test. A suppression that moves with its code is fine. |
|
|
28
|
+
| Tests kept | The diff removes no test case, and changes no test file that no check runs (`uncheckedTests`). |
|
|
29
|
+
| Size | At most `guards.maxFiles` files and `guards.maxLines` lines. |
|
|
30
|
+
| Checks | Every command in `checks` passes, as it passes on `main`. Sloppatrol does no work while `main` is red. |
|
|
31
|
+
| Review | A reviewer agent reads the diff against the playbook, and rejects when in doubt. |
|
|
32
|
+
|
|
33
|
+
| Mutation | A **tests** refactor plants one bug in the unchanged source; a test check must turn red. A test that cannot fail proves nothing. |
|
|
34
|
+
| Improvement | The assessor scores the changed files before and after, blind. The target metrics must go up; no other metric may drop. |
|
|
35
|
+
|
|
36
|
+
So the stronger your tests, the more Sloppatrol can do. Each check must run the same work on `main` and on every refactor: a command that picks its tests from the diff (`--changed`, `affected`) runs less on `main`, so a failure on a refactor can be old. `sloppatrol doctor` warns about such a check. Where code has no tests, the surveyor proposes **characterization tests** first: tests that pin what the code does today. To move a test from a mocking library to a fake, it makes two refactors: `inject-dependency` (source: add a seam, with today's behaviour as the default), then `replace-mock` (tests: inject a fake through the seam).
|
|
37
|
+
|
|
38
|
+
## The metrics
|
|
39
|
+
|
|
40
|
+
An assessor agent scores each file against a fixed rubric, and cites the lines behind each score. For each metric it picks one of five anchored levels, and Sloppatrol shows the result as 0 (worst) to 100 (best): a level of 3 is 75. A scorecard also shows one **overall** score, the mean of all metrics. The rubric anchors every level in things a reader can point at, so scores stay consistent ([ADR 0004](docs/adr/0004-llm-judged-metrics.md)).
|
|
41
|
+
|
|
42
|
+
| Metric | The question |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| Simplicity | Can a reader follow each function without holding much in their head? |
|
|
45
|
+
| Modularity | Does the file own one concept, behind a small interface, apart from other concerns? |
|
|
46
|
+
| Injection | Does the code receive what it depends on, or reach out for it? |
|
|
47
|
+
| Purity | How much of the logic lives in pure functions (same input, same output, no side effects), with state and effects kept small and at the edge? |
|
|
48
|
+
| Test quality | Do the tests prove behaviour through the interface, and would they fail if it broke? |
|
|
49
|
+
| Clarity | Does every name, comment and abstraction earn its place? |
|
|
50
|
+
| Agent-friendliness | How hard is it for an agent to change this file wrong, and is it a pattern worth copying? |
|
|
51
|
+
|
|
52
|
+
The scorecard also checks the repo's own guardrails, from files alone: an agent guide, strict types, a linter, module boundary rules, a pre-commit hook, CI and tests. Each one turns a wrong edit into a failed check. Sloppatrol reports a missing one; it never adds one itself, because tool configs are frozen.
|
|
53
|
+
|
|
54
|
+
Each commit gets a **scorecard** of the whole repo. A file keeps its scores while its content does not change, and each cycle scores up to `metrics.panel` more files: the most changed first, then the largest. So coverage grows each cycle until every file is scored, and the scorecard shows how much it covers. Every mean is weighted by lines. The surveyor starts from the worst scores, and each opportunity names the metrics it will raise. `sloppatrol score --files 200` scores more now; the dashboard shows the trend.
|
|
55
|
+
|
|
56
|
+
## The proof
|
|
57
|
+
|
|
58
|
+
Every pull request carries its proof, built by code and by a blind assessor, never by the agent that wrote the change:
|
|
59
|
+
|
|
60
|
+
- **It breaks nothing:** the side it changed, the guards it passed, the same checks green on `main` and on the change (with the test counts), and for a tests refactor, the planted bug its tests caught.
|
|
61
|
+
- **It makes the code better:** each metric before and after, the target marked, and the measured lines, nesting, comments, mocks and suppressions.
|
|
62
|
+
- **It follows the repo's rules:** the rule files read, and the reviewer's account of each rule that applies.
|
|
63
|
+
|
|
64
|
+
## Your repo's rules
|
|
65
|
+
|
|
66
|
+
Every agent reads your repo's own rules before it acts, and they win over the playbook: `.sloppatrol/instructions.md`, every `AGENTS.md` and `CLAUDE.md` from the repo root down to the changed files (with their `@path` imports), `CONTRIBUTING.md`, `CODING_STANDARDS.md`, `GLOSSARY.md`, and the titles of your decision records. `sloppatrol doctor` lists what it found.
|
|
67
|
+
|
|
68
|
+
## The playbook
|
|
69
|
+
|
|
70
|
+
The agents follow a [playbook](playbook/) of top-tier engineering practice, written for agents:
|
|
71
|
+
|
|
72
|
+
- [Principles](playbook/principles.md): deep modules, seams, ports and adapters, one owner per concept, separation of concerns, dependency injection, single responsibility, small files, no sediment. The vocabulary comes from Ousterhout, Feathers, Fowler, and [Matt Pocock's skills](https://github.com/mattpocock/skills).
|
|
73
|
+
- [Testing](playbook/testing.md): test through the interface; fakes injected through a seam, never a mocking library for your own code.
|
|
74
|
+
- [Smells](playbook/smells.md) and [Safety](playbook/safety.md): what to look for, and the behaviour a refactor must keep.
|
|
75
|
+
- One page per stack, picked from what the census detects: [TypeScript](playbook/stacks/typescript.md), [React and React Native](playbook/stacks/react.md), [Node backends](playbook/stacks/node-backend.md), [Python](playbook/stacks/python.md), [Go](playbook/stacks/go.md), [Swift](playbook/stacks/swift.md), [Kotlin](playbook/stacks/kotlin.md), [Rust](playbook/stacks/rust.md).
|
|
76
|
+
|
|
77
|
+
Your repo's own rules win over the playbook: `.sloppatrol/instructions.md`, `CLAUDE.md`, `AGENTS.md`, `CONTRIBUTING.md`, `GLOSSARY.md`, and the decision records in `docs/adr/`.
|
|
78
|
+
|
|
79
|
+
## Commands
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
Start
|
|
83
|
+
sloppatrol init Create .sloppatrol/ with a guess at your checks
|
|
84
|
+
sloppatrol doctor Show the config, the agent each role runs on, and what is missing
|
|
85
|
+
|
|
86
|
+
Run
|
|
87
|
+
sloppatrol Patrol all day: a cycle every patrol.intervalMinutes, with the dashboard
|
|
88
|
+
sloppatrol --once One cycle, then stop
|
|
89
|
+
sloppatrol dashboard Only the dashboard (http://127.0.0.1:4322)
|
|
90
|
+
|
|
91
|
+
One step at a time
|
|
92
|
+
sloppatrol check Run your checks on the patrolled commit (the oracle)
|
|
93
|
+
sloppatrol survey Let the surveyor record opportunities now
|
|
94
|
+
sloppatrol refactor [id] Attempt one opportunity now: the best open one, or <id>
|
|
95
|
+
sloppatrol score Score the repo now: the metrics of the panel of files
|
|
96
|
+
sloppatrol publish Open pull requests for verified refactors (--dry-run)
|
|
97
|
+
|
|
98
|
+
Read
|
|
99
|
+
sloppatrol status The opportunities, the refactors and the agents
|
|
100
|
+
sloppatrol census What the surveyor sees: stack, large files, mocks, churn
|
|
101
|
+
sloppatrol dismiss <id> Never propose this opportunity again (--reason "...")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## A cycle
|
|
105
|
+
|
|
106
|
+
```mermaid
|
|
107
|
+
flowchart TB
|
|
108
|
+
start(["sloppatrol"]) --> pull["Resolve origin/main, check it out"]
|
|
109
|
+
pull --> base{{"Checks on main<br/>(code)"}}
|
|
110
|
+
base -->|red| wait
|
|
111
|
+
base -->|green| survey["Survey, when the backlog is low<br/>LLM · surveyor"]
|
|
112
|
+
survey --> pick["Pick the strongest opportunity<br/>no file overlap with open PRs"]
|
|
113
|
+
pick --> refactor["Refactor in a worktree<br/>LLM · refactorer"]
|
|
114
|
+
refactor --> guards{{"Guards on the diff<br/>(code)"}}
|
|
115
|
+
guards -->|pass| checks{{"Your checks<br/>(code)"}}
|
|
116
|
+
checks -->|pass| review["Review<br/>LLM · reviewer, veto only"]
|
|
117
|
+
review -->|approve| pr["Draft pull request"]
|
|
118
|
+
guards -->|fail| reject["Rejected: worktree removed"]
|
|
119
|
+
checks -->|fail| reject
|
|
120
|
+
review -->|reject| reject
|
|
121
|
+
pr --> wait["Wait patrol.intervalMinutes"]
|
|
122
|
+
reject --> wait
|
|
123
|
+
wait --> pull
|
|
124
|
+
|
|
125
|
+
classDef llm fill:#312e81,stroke:#a5b4fc,color:#ffffff
|
|
126
|
+
classDef code fill:#1e293b,stroke:#64748b,color:#e2e8f0
|
|
127
|
+
class survey,refactor,review llm
|
|
128
|
+
class start,pull,base,pick,guards,checks,pr,reject,wait code
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- A merged pull request finishes its opportunity. A closed one dismisses it for good.
|
|
132
|
+
- At most `github.maxOpen` pull requests wait at once, and two never touch the same file.
|
|
133
|
+
- An opportunity that fails the gate `maxAttempts` times is exhausted.
|
|
134
|
+
|
|
135
|
+
## The dashboard
|
|
136
|
+
|
|
137
|
+
`sloppatrol` serves a dashboard on `http://127.0.0.1:4322` while it patrols (`--no-dashboard` turns it off; `sloppatrol dashboard` serves it alone). It shows, live:
|
|
138
|
+
|
|
139
|
+
- **Agents**: what the patrol, the surveyor, the refactorer, the gate and the reviewer do now.
|
|
140
|
+
- **Refactors**: each attempt as a pipeline (refactorer → guards → checks → mutation → metrics → review → pull request), with its full proof.
|
|
141
|
+
- **Scorecard**: each metric's score and trend over commits, and every file of the panel with the evidence behind its scores.
|
|
142
|
+
- **Checks**: every check run on `main`, on each refactor, and each run the refactorer starts itself, with the output of each check.
|
|
143
|
+
- **Backlog**: the opportunities by status, with the problem, the change and the files.
|
|
144
|
+
- **Sessions**: every agent session as a timeline of its tool calls.
|
|
145
|
+
|
|
146
|
+
## Any agent, any model
|
|
147
|
+
|
|
148
|
+
By default every role runs on the agent CLI you have installed: `agent: auto` picks `claude`, then `codex`, then `opencode`, from your `PATH`. The surveyor and the reviewer get read-only access; the refactorer gets edit access in its own worktree. Every role reaches Sloppatrol through its tools over a local MCP server.
|
|
149
|
+
|
|
150
|
+
```yaml
|
|
151
|
+
agent: auto # or claude | codex | opencode
|
|
152
|
+
agents:
|
|
153
|
+
reviewer: { use: codex } # a second opinion from another agent
|
|
154
|
+
surveyor:
|
|
155
|
+
use: { runtime: model, via: openrouter, model: anthropic/claude-opus-5.5 }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`{ runtime: model, via: anthropic | openai | openrouter | custom, model }` runs Sloppatrol's own tool loop on an API key. `{ runtime: cli, command: "..." }` runs any command, with `{prompt}`, `{mcp}`, `{mcpUrl}` and `{workdir}` filled in.
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
# .sloppatrol/sloppatrol.yml
|
|
164
|
+
agent: auto
|
|
165
|
+
prepare: [pnpm install --frozen-lockfile] # each fresh checkout and worktree
|
|
166
|
+
checks: # the oracle
|
|
167
|
+
- { name: typecheck, run: pnpm typecheck }
|
|
168
|
+
- { name: lint, run: pnpm lint }
|
|
169
|
+
- { name: test, run: pnpm test, tests: true } # tests: true marks the checks a planted bug must turn red
|
|
170
|
+
focus: [src/**] # where the surveyor looks (default: everywhere)
|
|
171
|
+
ignore: [src/generated/**] # what no agent may change
|
|
172
|
+
uncheckedTests: [tests/e2e/**] # tests no check runs: no refactor may change them
|
|
173
|
+
guards: { maxFiles: 12, maxLines: 600 }
|
|
174
|
+
metrics: { enabled: true, panel: 100, tolerance: 0.5, judges: 3 } # panel: files newly scored per cycle
|
|
175
|
+
agents:
|
|
176
|
+
surveyor: { minBacklog: 3, maxPerSurvey: 8 }
|
|
177
|
+
refactorer: { maxPerCycle: 1, maxAttempts: 2 }
|
|
178
|
+
reviewer: { enabled: true }
|
|
179
|
+
github: { enabled: true, draft: true, maxOpen: 3, labels: [sloppatrol] }
|
|
180
|
+
patrol: { intervalMinutes: 60, pull: origin/main }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Every role also takes `maxSteps`, `timeoutMinutes` and `budgetUsd` (model runtime). Pull requests open with your `gh` login.
|
|
184
|
+
|
|
185
|
+
`.sloppatrol/sloppatrol.yml` and `.sloppatrol/instructions.md` are committed. `.sloppatrol/runs/` holds local data (checkouts, worktrees, opportunities, refactors, check runs, sessions) as plain JSON, and git ignores it.
|
|
186
|
+
|
|
187
|
+
## Docs
|
|
188
|
+
|
|
189
|
+
- [Glossary](GLOSSARY.md)
|
|
190
|
+
- [Decisions](docs/adr/): why it works this way.
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
pnpm install
|
|
196
|
+
pnpm build
|
|
197
|
+
pnpm test
|
|
198
|
+
pnpm check # Biome, module boundaries (dependency-cruiser), types
|
|
199
|
+
pnpm knip
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Sloppatrol follows its own playbook: each folder in `src/` is a deep module, other modules reach it only through its root files, the CLI is the only composition root, and the tests use real git repos, real processes, an in-memory GitHub and a scripted agent, with no mocking library.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
Apache-2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RoleRuntime } from '../config/index.js';
|
|
2
|
+
import type { Runtime } from './lib/types.js';
|
|
3
|
+
export { editTools, repoTools } from './lib/repo-tools.js';
|
|
4
|
+
export { finishTool, str, strList, tool } from './lib/schema.js';
|
|
5
|
+
export { runRole } from './lib/session.js';
|
|
6
|
+
export type { RoleOutcome } from './lib/types.js';
|
|
7
|
+
/** Builds the runtime for a role. The CLI injects this; tests can inject their own. */
|
|
8
|
+
export type RuntimeFactory = (use: RoleRuntime) => Runtime;
|
|
9
|
+
export declare const createRuntime: RuntimeFactory;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CliRuntime } from './lib/cli-runtime.js';
|
|
2
|
+
import { ModelRuntime } from './lib/model-runtime.js';
|
|
3
|
+
export { editTools, repoTools } from './lib/repo-tools.js';
|
|
4
|
+
export { finishTool, str, strList, tool } from './lib/schema.js';
|
|
5
|
+
export { runRole } from './lib/session.js';
|
|
6
|
+
export const createRuntime = (use) => use.runtime === 'cli' ? new CliRuntime(use) : new ModelRuntime(use);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAM3C,MAAM,CAAC,MAAM,aAAa,GAAmB,CAAC,GAAG,EAAE,EAAE,CACnD,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RoleRuntime } from '../../config/index.js';
|
|
2
|
+
import type { EventSink, RoleOutcome, RoleTask, Runtime } from './types.js';
|
|
3
|
+
type CliUse = Extract<RoleRuntime, {
|
|
4
|
+
runtime: 'cli';
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* A local agent CLI (claude, codex, opencode, or any command) runs the role.
|
|
8
|
+
* It gets the prompt on stdin and in `{prompt}`, and the role's tools over a
|
|
9
|
+
* local MCP server in `{mcp}` / `{mcpUrl}`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CliRuntime implements Runtime {
|
|
12
|
+
private readonly use;
|
|
13
|
+
readonly label: string;
|
|
14
|
+
constructor(use: CliUse);
|
|
15
|
+
run(task: RoleTask, emit: EventSink): Promise<RoleOutcome>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { stopGroup, track } from '../../processes/index.js';
|
|
6
|
+
import { serveTools } from './mcp-server.js';
|
|
7
|
+
function quote(value) {
|
|
8
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
9
|
+
}
|
|
10
|
+
/** One line of output as feed text: a JSON event becomes its message, or nothing. */
|
|
11
|
+
function displayLine(line) {
|
|
12
|
+
if (!line.trimStart().startsWith('{'))
|
|
13
|
+
return line;
|
|
14
|
+
try {
|
|
15
|
+
const event = JSON.parse(line);
|
|
16
|
+
if (event.type === 'item.completed' && typeof event.item?.text === 'string')
|
|
17
|
+
return event.item.text;
|
|
18
|
+
if (event.type === 'text' && typeof event.part?.text === 'string')
|
|
19
|
+
return event.part.text;
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return line;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What a CLI printed. `claude -p --output-format json` prints one object with
|
|
28
|
+
* the result and its cost; `codex exec --json` and `opencode run --format
|
|
29
|
+
* json` print one event per line.
|
|
30
|
+
*/
|
|
31
|
+
function parseCliOutput(stdout) {
|
|
32
|
+
const trimmed = stdout.trim();
|
|
33
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
34
|
+
try {
|
|
35
|
+
const claude = JSON.parse(trimmed);
|
|
36
|
+
if (typeof claude.result === 'string') {
|
|
37
|
+
return {
|
|
38
|
+
text: claude.result,
|
|
39
|
+
costUsd: typeof claude.total_cost_usd === 'number' ? claude.total_cost_usd : 0,
|
|
40
|
+
...(claude.is_error === true ? { error: claude.result } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
/* not one object: read it line by line */
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const text = trimmed.split('\n').map(displayLine).filter(Boolean).join('\n');
|
|
49
|
+
return { text, costUsd: 0 };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A local agent CLI (claude, codex, opencode, or any command) runs the role.
|
|
53
|
+
* It gets the prompt on stdin and in `{prompt}`, and the role's tools over a
|
|
54
|
+
* local MCP server in `{mcp}` / `{mcpUrl}`.
|
|
55
|
+
*/
|
|
56
|
+
export class CliRuntime {
|
|
57
|
+
use;
|
|
58
|
+
label;
|
|
59
|
+
constructor(use) {
|
|
60
|
+
this.use = use;
|
|
61
|
+
this.label = `cli:${use.label}`;
|
|
62
|
+
}
|
|
63
|
+
async run(task, emit) {
|
|
64
|
+
const temp = await mkdtemp(join(tmpdir(), 'sloppatrol-agent-'));
|
|
65
|
+
let summary = '';
|
|
66
|
+
let finished = false;
|
|
67
|
+
let steps = 0;
|
|
68
|
+
const mcp = await serveTools(task.tools, {
|
|
69
|
+
maxCalls: task.maxSteps,
|
|
70
|
+
onStart(name, input) {
|
|
71
|
+
emit({ kind: 'tool-call', summary: `Called ${name}.`, tool: name, input });
|
|
72
|
+
},
|
|
73
|
+
onCall(name, _input, result, ms) {
|
|
74
|
+
steps++;
|
|
75
|
+
emit({
|
|
76
|
+
kind: 'tool-result',
|
|
77
|
+
summary: result.summary ?? `${name}: ${result.text.split('\n')[0]?.slice(0, 160) ?? ''}`,
|
|
78
|
+
tool: name,
|
|
79
|
+
output: result.text.slice(0, 2000),
|
|
80
|
+
durationMs: ms,
|
|
81
|
+
});
|
|
82
|
+
if (result.done) {
|
|
83
|
+
summary = result.text;
|
|
84
|
+
finished = true;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const prompt = `${task.system}\n\n${task.prompt}`;
|
|
90
|
+
const promptFile = join(temp, 'prompt.md');
|
|
91
|
+
const mcpFile = join(temp, 'mcp.json');
|
|
92
|
+
await writeFile(promptFile, prompt);
|
|
93
|
+
await writeFile(mcpFile, JSON.stringify({ mcpServers: { sloppatrol: { type: 'http', url: mcp.url } } }));
|
|
94
|
+
const values = {
|
|
95
|
+
prompt: promptFile,
|
|
96
|
+
mcp: mcpFile,
|
|
97
|
+
mcpUrl: mcp.url,
|
|
98
|
+
workdir: task.workdir,
|
|
99
|
+
};
|
|
100
|
+
const command = (this.use.command ?? '').replace(/\{(prompt|mcp|mcpUrl|workdir)\}/g, (_, name) => quote(values[name]));
|
|
101
|
+
const child = spawn('/bin/sh', ['-c', command], {
|
|
102
|
+
cwd: task.workdir,
|
|
103
|
+
// run_checks runs for minutes; Claude Code's default MCP tool
|
|
104
|
+
// timeout abandons it and the agent calls it again over the first.
|
|
105
|
+
env: { MCP_TOOL_TIMEOUT: String(task.timeoutMs), ...process.env },
|
|
106
|
+
detached: true,
|
|
107
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
108
|
+
});
|
|
109
|
+
track(child);
|
|
110
|
+
child.stdin.on('error', () => undefined);
|
|
111
|
+
child.stdin.end(prompt);
|
|
112
|
+
let stdout = '';
|
|
113
|
+
let stderr = '';
|
|
114
|
+
let partial = '';
|
|
115
|
+
child.stdout.on('data', (chunk) => {
|
|
116
|
+
stdout += chunk.toString();
|
|
117
|
+
const lines = (partial + chunk.toString()).split('\n');
|
|
118
|
+
partial = lines.pop() ?? '';
|
|
119
|
+
const text = lines.map(displayLine).filter(Boolean).join('\n').trim();
|
|
120
|
+
if (text)
|
|
121
|
+
emit({ kind: 'thought', summary: text.slice(-300) });
|
|
122
|
+
});
|
|
123
|
+
child.stderr.on('data', (chunk) => {
|
|
124
|
+
stderr += chunk.toString();
|
|
125
|
+
});
|
|
126
|
+
let timedOut = false;
|
|
127
|
+
const timer = setTimeout(() => {
|
|
128
|
+
timedOut = true;
|
|
129
|
+
stopGroup(child);
|
|
130
|
+
}, task.timeoutMs);
|
|
131
|
+
const code = await new Promise((done, reject) => {
|
|
132
|
+
child.once('error', reject);
|
|
133
|
+
child.once('exit', done);
|
|
134
|
+
}).finally(() => clearTimeout(timer));
|
|
135
|
+
const parsed = parseCliOutput(stdout);
|
|
136
|
+
if (parsed.text)
|
|
137
|
+
emit({ kind: 'thought', summary: parsed.text.slice(-300), costUsd: parsed.costUsd });
|
|
138
|
+
const base = { steps, costUsd: parsed.costUsd, summary: summary || parsed.text, finished };
|
|
139
|
+
if (timedOut)
|
|
140
|
+
return { ...base, stop: 'timeout' };
|
|
141
|
+
if (code !== 0 || parsed.error) {
|
|
142
|
+
return {
|
|
143
|
+
...base,
|
|
144
|
+
stop: 'error',
|
|
145
|
+
error: parsed.error || stderr.trim().split('\n').slice(-20).join('\n') || `CLI exited ${code}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return { ...base, stop: 'done' };
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await mcp.close();
|
|
152
|
+
await rm(temp, { recursive: true, force: true });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=cli-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-runtime.js","sourceRoot":"","sources":["../../../src/agents/lib/cli-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC;AAC/C,CAAC;AAED,qFAAqF;AACrF,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAI5B,CAAC;QACF,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAg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,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,cAAc,IAAI,EAAE;iBAC/F,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACnC,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Tool, ToolResult } from './types.js';
|
|
2
|
+
type Options = {
|
|
3
|
+
/** A call starts: a person can see a slow tool run while it runs. */
|
|
4
|
+
onStart?: (name: string, input: Record<string, unknown>) => void;
|
|
5
|
+
onCall?: (name: string, input: Record<string, unknown>, result: ToolResult, ms: number) => void;
|
|
6
|
+
maxCalls?: number;
|
|
7
|
+
};
|
|
8
|
+
/** Runs one tool call under the step budget. `finish` is always allowed. */
|
|
9
|
+
export declare function callTool(tools: Tool[], name: string, input: Record<string, unknown>, budget: {
|
|
10
|
+
calls: number;
|
|
11
|
+
max: number;
|
|
12
|
+
}): Promise<ToolResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Serves a role's tools to a CLI agent over streamable HTTP. Stateless: each
|
|
15
|
+
* request gets its own server and transport. The step budget lives out here,
|
|
16
|
+
* so it holds across every session the CLI opens.
|
|
17
|
+
*/
|
|
18
|
+
export declare function serveTools(tools: Tool[], options?: Options): Promise<{
|
|
19
|
+
url: string;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}>;
|
|
22
|
+
export {};
|