@srobroek/pi-repomix 0.0.0-stage → 0.6.3
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/CHANGELOG.md +66 -0
- package/LICENSE +202 -0
- package/README.md +72 -2
- package/extensions/repomix.js +485 -0
- package/package.json +34 -4
- package/skills/repomix/SKILL.md +79 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
## repomix [0.6.3](https://github.com/srobroek/harness-plugins/compare/repomix--v0.6.2...repomix--v0.6.3) (2026-11-24)
|
|
2
|
+
|
|
3
|
+
## repomix [0.6.2](https://github.com/srobroek/harness-plugins/compare/repomix--v0.6.1...repomix--v0.6.2) (2026-11-24)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **design:** make MCP servers opt-in ([1ecb493](https://github.com/srobroek/harness-plugins/commit/1ecb493f35ebfe9112f9e4661fa1b2e5ec457fc4))
|
|
8
|
+
|
|
9
|
+
## repomix [0.6.1](https://github.com/srobroek/harness-plugins/compare/repomix--v0.6.0...repomix--v0.6.1) (2026-11-23)
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **whats-new:** grant MCP tools to the whats-new research agent ([8ae7fe0](https://github.com/srobroek/harness-plugins/commit/8ae7fe05c65e2df2f53ebf944c8f9bd5b7625cf9))
|
|
14
|
+
|
|
15
|
+
## repomix [0.6.0](https://github.com/srobroek/harness-plugins/compare/repomix--v0.5.1...repomix--v0.6.0) (2026-11-23)
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **project:** port content plugins to Pi ([5b0d32a](https://github.com/srobroek/harness-plugins/commit/5b0d32abbe2faf67934ca1d8e3b53f9eca0cee01))
|
|
20
|
+
|
|
21
|
+
## repomix [0.5.1](https://github.com/srobroek/harness-plugins/compare/repomix--v0.5.0...repomix--v0.5.1) (2026-11-23)
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* make every plugin agent's OMP form correct ([96b7bfe](https://github.com/srobroek/harness-plugins/commit/96b7bfea3c35017b34a28f59e81fb059f6c68a24))
|
|
26
|
+
|
|
27
|
+
## repomix [0.5.0](https://github.com/srobroek/harness-plugins/compare/repomix--v0.4.1...repomix--v0.5.0) (2026-11-22)
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* **delivery:** ship the orchestrator agent ([#121](https://github.com/srobroek/harness-plugins/issues/121)) ([53f33c0](https://github.com/srobroek/harness-plugins/commit/53f33c016315732220a7c87066267931ee87f514))
|
|
32
|
+
|
|
33
|
+
## repomix [0.4.1](https://github.com/srobroek/harness-plugins/compare/repomix--v0.4.0...repomix--v0.4.1) (2026-11-21)
|
|
34
|
+
|
|
35
|
+
### Bug Fixes
|
|
36
|
+
|
|
37
|
+
* **code-challenge:** close dogfood friction in skill, schema and validation ([043a8b3](https://github.com/srobroek/harness-plugins/commit/043a8b39057ec8fca54d09adebb0532c2154e330))
|
|
38
|
+
* stop forcing confirmation prompts in delivery, dep-update, design and repomix ([fe59fa1](https://github.com/srobroek/harness-plugins/commit/fe59fa10692bc61a3d7b2b7c8eb728ee6a0050b5))
|
|
39
|
+
|
|
40
|
+
# Changelog
|
|
41
|
+
|
|
42
|
+
## [0.4.0](https://github.com/srobroek/opencode-plugins/compare/repomix--v0.3.0...repomix--v0.4.0) (2026-11-20)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* plugin scan fixes, wider agent access and the plugin-audit plugin ([9c71525](https://github.com/srobroek/opencode-plugins/commit/9c7152559776aaf80cfed9626d78bafdd845fa9a))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Refactors
|
|
51
|
+
|
|
52
|
+
* **lib:** one MCP tool grant table for the tools option ([f8cc1d8](https://github.com/srobroek/opencode-plugins/commit/f8cc1d817d62b211b712d1889200f7c91f049c89))
|
|
53
|
+
|
|
54
|
+
## [0.3.0](https://github.com/srobroek/opencode-plugins/compare/repomix--v0.2.0...repomix--v0.3.0) (2026-11-19)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Features
|
|
58
|
+
|
|
59
|
+
* stop long tools and their processes on ToolContext.signal ([94c0ac5](https://github.com/srobroek/opencode-plugins/commit/94c0ac59e12df53eee73d3152da8523f10148bb0))
|
|
60
|
+
|
|
61
|
+
## [0.2.0](https://github.com/srobroek/opencode-plugins/compare/repomix--v0.1.0...repomix--v0.2.0) (2026-10-27)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
* **repomix:** repomix_pack tool and repomix skill for bulk repo context ([31ca20b](https://github.com/srobroek/opencode-plugins/commit/31ca20b6eb57fa58ae201e985c3db832ab2066fe))
|
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/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# repomix
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Packs a local directory, or a remote repository at a ref, into one file with
|
|
4
|
+
[repomix](https://github.com/yamadashy/repomix), for questions that need many files at
|
|
5
|
+
once: an external repo's layout and APIs, a whole module for review, a diff between two
|
|
6
|
+
versions, or a doc set. The pack goes to a file and only its path and metrics come back,
|
|
7
|
+
so it never lands in the context.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
Install the Pi package from npm:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pi install npm:@srobroek/pi-repomix
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
opencode plugin add 'github:srobroek/harness-plugins::path:plugins/repomix/opencode'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Install repomix globally with the installer you prefer, for example `mise use -g
|
|
21
|
+
npm:repomix@1.19.0`, `npm i -g repomix`, `brew install repomix`, or `pipx install
|
|
22
|
+
repomix`. Without it on PATH, the tool runs `npx --yes repomix@1.19.0`, because npx
|
|
23
|
+
downloads code. Your permission rules decide whether that runs; set `confirmPack`
|
|
24
|
+
(below) to prompt first.
|
|
25
|
+
|
|
26
|
+
## Tool
|
|
27
|
+
|
|
28
|
+
`repomix_pack` takes `directory` (default: the session directory) or `remote`
|
|
29
|
+
(`owner/repo` or an https URL) with an optional `ref`, plus `include` and `ignore` globs,
|
|
30
|
+
`compress`, `style` (`xml`, `markdown` or `plain`), `lineNumbers` and `timeoutSeconds`
|
|
31
|
+
(default 300). It writes `repomix-<target>-<id>.<ext>` to `$TMPDIR/opencode/repomix/` and
|
|
32
|
+
returns the path, the file, token and character totals, the ten largest files, and the
|
|
33
|
+
files the secret scan left out. Packs older than a day are removed on the next run.
|
|
34
|
+
|
|
35
|
+
Every run:
|
|
36
|
+
|
|
37
|
+
- passes `--config` an empty JSON file, so neither the target's `repomix.config.*` (a JS
|
|
38
|
+
or TS config is code) nor your global repomix config is loaded. A target's
|
|
39
|
+
`.repomixignore` and `.gitignore` still apply.
|
|
40
|
+
- runs in an empty directory under the temp dir.
|
|
41
|
+
- never passes `--no-security-check` or `--remote-trust-config`.
|
|
42
|
+
- passes `--no-file-summary` and `--no-git-sort-by-changes`, so two packs of one repo at
|
|
43
|
+
different refs diff cleanly.
|
|
44
|
+
|
|
45
|
+
The tool asks permission as `repomix_pack`, with the absolute directory or `remote@ref` as
|
|
46
|
+
the resource. Your permission rules decide: an allowed call runs without a prompt, and a deny
|
|
47
|
+
or ask rule always wins. To prompt when a pack would run through npx, even if a rule allows
|
|
48
|
+
it, set the plugin option `confirmPack` to `true` (default `false`):
|
|
49
|
+
|
|
50
|
+
```jsonc
|
|
51
|
+
{
|
|
52
|
+
"plugins": [{
|
|
53
|
+
"package": "github:srobroek/harness-plugins::path:plugins/repomix/opencode",
|
|
54
|
+
"options": { "confirmPack": true }
|
|
55
|
+
}]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The `researcher` agent (agent-researcher, and delivery's fallback copy) and build's
|
|
60
|
+
`external-repo-worker` allow `repomix_pack`. Other agents keep your default for it, which
|
|
61
|
+
is a prompt unless you configure otherwise. The shipped allowlist agents deny it.
|
|
62
|
+
|
|
63
|
+
## Skill
|
|
64
|
+
|
|
65
|
+
`repomix` lists when packing beats grep and read, the recipes for each case, how to read
|
|
66
|
+
a pack in slices, and when `compress` loses information. It also carries a CLI recipe,
|
|
67
|
+
so it is exported to Claude Code.
|
|
68
|
+
|
|
69
|
+
The npm package exposes `repomix_pack` as a Pi tool. It confirms before packing; the pack is written under a temp directory, and only the path and metrics are returned.
|
|
70
|
+
|
|
71
|
+
## Optional: the repomix MCP server
|
|
72
|
+
|
|
73
|
+
The plugin does not configure the repomix MCP server. In Pi's `.pi/mcp.json` or the user MCP configuration, `repomix --mcp` exposes its tools. `--sandbox` confines file access to the working directory but disables remote packing.
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// Generated by scripts/build.ts. Do not edit.
|
|
3
|
+
// plugins/repomix/pi-src/repomix.ts
|
|
4
|
+
import { statSync as statSync2 } from "fs";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
|
|
7
|
+
// plugins/repomix/shared/pack.ts
|
|
8
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from "fs";
|
|
9
|
+
import { tmpdir } from "os";
|
|
10
|
+
import { basename, isAbsolute, join, resolve } from "path";
|
|
11
|
+
|
|
12
|
+
// lib/src/subprocess.ts
|
|
13
|
+
import { constants } from "os";
|
|
14
|
+
var EXIT_GRACE_MS = 2000;
|
|
15
|
+
var EXIT_POLL_MS = 100;
|
|
16
|
+
function goneWatch(graceMs, pollMs) {
|
|
17
|
+
const polls = Math.max(1, Math.ceil(graceMs / Math.max(1, pollMs)));
|
|
18
|
+
let since = null;
|
|
19
|
+
let seen = 0;
|
|
20
|
+
return (alive) => {
|
|
21
|
+
if (alive) {
|
|
22
|
+
since = null;
|
|
23
|
+
seen = 0;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
since ??= Date.now();
|
|
27
|
+
seen++;
|
|
28
|
+
return seen > polls && Date.now() - since >= graceMs;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function processAlive(pid) {
|
|
32
|
+
try {
|
|
33
|
+
process.kill(pid, 0);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return error.code === "EPERM";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function killChild(child, group) {
|
|
40
|
+
if (group) {
|
|
41
|
+
try {
|
|
42
|
+
process.kill(-child.pid, "SIGKILL");
|
|
43
|
+
return;
|
|
44
|
+
} catch {}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
child.kill("SIGKILL");
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
function unref(timer) {
|
|
51
|
+
timer.unref?.();
|
|
52
|
+
}
|
|
53
|
+
function capture(stream) {
|
|
54
|
+
if (!(stream instanceof ReadableStream))
|
|
55
|
+
return { text: Promise.resolve(""), snapshot: () => "", cancel: () => {} };
|
|
56
|
+
const reader = stream.getReader();
|
|
57
|
+
const decoder = new TextDecoder;
|
|
58
|
+
let collected = "";
|
|
59
|
+
const text = (async () => {
|
|
60
|
+
try {
|
|
61
|
+
for (;; ) {
|
|
62
|
+
const chunk = await reader.read();
|
|
63
|
+
if (chunk.done)
|
|
64
|
+
break;
|
|
65
|
+
collected += decoder.decode(chunk.value, { stream: true });
|
|
66
|
+
}
|
|
67
|
+
} catch {}
|
|
68
|
+
collected += decoder.decode();
|
|
69
|
+
return collected;
|
|
70
|
+
})();
|
|
71
|
+
const cancel = () => {
|
|
72
|
+
try {
|
|
73
|
+
reader.cancel().catch(() => {
|
|
74
|
+
return;
|
|
75
|
+
});
|
|
76
|
+
} catch {}
|
|
77
|
+
};
|
|
78
|
+
return { text, snapshot: () => collected, cancel };
|
|
79
|
+
}
|
|
80
|
+
function supervise(child, options = {}) {
|
|
81
|
+
const grace = Math.max(0, options.graceMs ?? EXIT_GRACE_MS);
|
|
82
|
+
const pollMs = Math.max(1, options.pollMs ?? EXIT_POLL_MS);
|
|
83
|
+
const alive = options.alive ?? processAlive;
|
|
84
|
+
const group = options.group ?? false;
|
|
85
|
+
const { signal, timeoutMs } = options;
|
|
86
|
+
const out = capture(child.stdout);
|
|
87
|
+
const err = capture(child.stderr);
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
let ended = null;
|
|
90
|
+
let exitSeen = false;
|
|
91
|
+
let settled = false;
|
|
92
|
+
const gone = goneWatch(grace, pollMs);
|
|
93
|
+
let deadline;
|
|
94
|
+
let graceTimer;
|
|
95
|
+
const settle = (run) => {
|
|
96
|
+
if (settled)
|
|
97
|
+
return;
|
|
98
|
+
settled = true;
|
|
99
|
+
clearTimeout(deadline);
|
|
100
|
+
clearTimeout(graceTimer);
|
|
101
|
+
clearInterval(poller);
|
|
102
|
+
signal?.removeEventListener("abort", onAbort);
|
|
103
|
+
resolve(run);
|
|
104
|
+
};
|
|
105
|
+
const end = (cause) => {
|
|
106
|
+
if (ended !== null || settled)
|
|
107
|
+
return;
|
|
108
|
+
ended = cause;
|
|
109
|
+
if (cause !== "lost" || group)
|
|
110
|
+
killChild(child, group);
|
|
111
|
+
out.cancel();
|
|
112
|
+
err.cancel();
|
|
113
|
+
graceTimer = setTimeout(() => settle({ kind: cause, stdout: out.snapshot(), stderr: err.snapshot() }), grace);
|
|
114
|
+
if (options.unref)
|
|
115
|
+
unref(graceTimer);
|
|
116
|
+
};
|
|
117
|
+
const onAbort = () => end("aborted");
|
|
118
|
+
const poller = setInterval(() => {
|
|
119
|
+
if (exitSeen || ended !== null || settled)
|
|
120
|
+
return;
|
|
121
|
+
if (gone(alive(child.pid)))
|
|
122
|
+
end("lost");
|
|
123
|
+
}, pollMs);
|
|
124
|
+
unref(poller);
|
|
125
|
+
if (timeoutMs !== undefined && timeoutMs > 0 && Number.isFinite(timeoutMs)) {
|
|
126
|
+
deadline = setTimeout(() => end("timeout"), timeoutMs);
|
|
127
|
+
if (options.unref)
|
|
128
|
+
unref(deadline);
|
|
129
|
+
}
|
|
130
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
131
|
+
if (signal?.aborted)
|
|
132
|
+
onAbort();
|
|
133
|
+
child.exited.then(() => {
|
|
134
|
+
exitSeen = true;
|
|
135
|
+
}, () => {
|
|
136
|
+
return;
|
|
137
|
+
});
|
|
138
|
+
Promise.all([child.exited, out.text, err.text]).then(([exitCode, stdout, stderr]) => {
|
|
139
|
+
if (ended !== null)
|
|
140
|
+
settle({ kind: ended, stdout, stderr });
|
|
141
|
+
else
|
|
142
|
+
settle({ kind: "exited", exitCode, signalCode: signalName(child.signalCode), stdout, stderr });
|
|
143
|
+
}, () => end("lost"));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function signalName(code) {
|
|
147
|
+
if (code === null || code === undefined)
|
|
148
|
+
return null;
|
|
149
|
+
if (typeof code === "string")
|
|
150
|
+
return code;
|
|
151
|
+
return Object.entries(constants.signals).find(([, n]) => n === code)?.[0] ?? String(code);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// plugins/repomix/shared/pack.ts
|
|
155
|
+
var PACK_TOOL = "repomix_pack";
|
|
156
|
+
var REPOMIX_VERSION = "1.19.0";
|
|
157
|
+
var DEFAULT_TIMEOUT_SECONDS = 300;
|
|
158
|
+
var MAX_TIMEOUT_SECONDS = 900;
|
|
159
|
+
var TOP_FILES = 10;
|
|
160
|
+
var LARGE_PACK_TOKENS = 50000;
|
|
161
|
+
var PACK_TTL_MS = 24 * 60 * 60 * 1000;
|
|
162
|
+
var MAX_ERROR_CHARS = 4000;
|
|
163
|
+
var STYLES = { xml: "xml", markdown: "md", plain: "txt" };
|
|
164
|
+
var ANCHORS = { xml: '<file path="', markdown: "## File: ", plain: "File: " };
|
|
165
|
+
var PACK_DESCRIPTION = `Pack a local directory or a remote repo at a ref into one file; returns its path, token counts and top files.
|
|
166
|
+
` + "Runs repomix (PATH, else npx --yes repomix@" + REPOMIX_VERSION + "; the harness permission policy controls the run, and the confirmPack option can ask first). The pack is written under a temporary directory and never returned: grep it for the " + "file anchors and read slices. The target's repomix.config.* is never loaded and the secret scan always runs. " + "Use for bulk context over many files; for a single lookup use grep/read.";
|
|
167
|
+
var PACK_INPUT = {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: {
|
|
170
|
+
directory: {
|
|
171
|
+
type: "string",
|
|
172
|
+
description: "Local directory to pack; relative paths resolve against the session directory (default: it)"
|
|
173
|
+
},
|
|
174
|
+
remote: { type: "string", description: "Remote repo instead of a directory: owner/repo or an https URL" },
|
|
175
|
+
ref: { type: "string", description: "Remote only: branch, tag or commit (default: the default branch)" },
|
|
176
|
+
include: { type: "array", items: { type: "string" }, description: 'Globs to include, for example "src/**"' },
|
|
177
|
+
ignore: { type: "array", items: { type: "string" }, description: "Extra globs to exclude" },
|
|
178
|
+
compress: {
|
|
179
|
+
type: "boolean",
|
|
180
|
+
description: "Keep only signatures, types and doc comments (Tree-sitter); lossy for tests and no gain on markdown"
|
|
181
|
+
},
|
|
182
|
+
style: { type: "string", enum: Object.keys(STYLES), description: "Output format (default xml)" },
|
|
183
|
+
lineNumbers: { type: "boolean", description: "Prefix each line with its line number, for citing a review" },
|
|
184
|
+
timeoutSeconds: {
|
|
185
|
+
type: "integer",
|
|
186
|
+
minimum: 1,
|
|
187
|
+
maximum: MAX_TIMEOUT_SECONDS,
|
|
188
|
+
description: `Kill repomix after this long (default ${DEFAULT_TIMEOUT_SECONDS})`
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
additionalProperties: false
|
|
192
|
+
};
|
|
193
|
+
var SHORTHAND = /^[\w.-]+\/[\w.-]+$/;
|
|
194
|
+
var HTTPS_URL = /^https:\/\/[\w.-]+(?::\d+)?\/[^\s]+$/;
|
|
195
|
+
var REF = /^[\w][\w./+@-]*$/;
|
|
196
|
+
function readPatterns(value, name) {
|
|
197
|
+
if (value === undefined)
|
|
198
|
+
return [];
|
|
199
|
+
const list = typeof value === "string" ? [value] : value;
|
|
200
|
+
if (!Array.isArray(list))
|
|
201
|
+
return `${name} must be an array of glob strings`;
|
|
202
|
+
for (const pattern of list) {
|
|
203
|
+
if (typeof pattern !== "string" || pattern.trim() === "")
|
|
204
|
+
return `every ${name} pattern must be a non-empty string`;
|
|
205
|
+
if (pattern.includes(","))
|
|
206
|
+
return `${name} pattern ${JSON.stringify(pattern)} contains a comma; pass each glob separately`;
|
|
207
|
+
}
|
|
208
|
+
return list;
|
|
209
|
+
}
|
|
210
|
+
function readPackParams(input) {
|
|
211
|
+
const value = input ?? {};
|
|
212
|
+
const { directory, remote, ref } = value;
|
|
213
|
+
if (directory !== undefined && (typeof directory !== "string" || directory.trim() === ""))
|
|
214
|
+
return "directory must be a non-empty string";
|
|
215
|
+
if (remote !== undefined && (typeof remote !== "string" || remote.trim() === ""))
|
|
216
|
+
return "remote must be a non-empty string";
|
|
217
|
+
if (directory !== undefined && remote !== undefined)
|
|
218
|
+
return "pass either directory or remote, not both";
|
|
219
|
+
if (typeof remote === "string" && !SHORTHAND.test(remote) && !HTTPS_URL.test(remote))
|
|
220
|
+
return `remote ${JSON.stringify(remote)} is not owner/repo or an https URL`;
|
|
221
|
+
if (ref !== undefined) {
|
|
222
|
+
if (remote === undefined)
|
|
223
|
+
return "ref applies only to a remote pack; check out the ref locally or pass remote";
|
|
224
|
+
if (typeof ref !== "string" || !REF.test(ref) || ref.includes(".."))
|
|
225
|
+
return `ref ${JSON.stringify(ref)} is not a branch, tag or commit`;
|
|
226
|
+
}
|
|
227
|
+
const include = readPatterns(value.include, "include");
|
|
228
|
+
if (typeof include === "string")
|
|
229
|
+
return include;
|
|
230
|
+
const ignore = readPatterns(value.ignore, "ignore");
|
|
231
|
+
if (typeof ignore === "string")
|
|
232
|
+
return ignore;
|
|
233
|
+
for (const key of ["compress", "lineNumbers"])
|
|
234
|
+
if (value[key] !== undefined && typeof value[key] !== "boolean")
|
|
235
|
+
return `${key} must be a boolean`;
|
|
236
|
+
const style = value.style ?? "xml";
|
|
237
|
+
if (typeof style !== "string" || !(style in STYLES))
|
|
238
|
+
return `style must be one of ${Object.keys(STYLES).join(", ")}`;
|
|
239
|
+
const timeout = value.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
240
|
+
if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)
|
|
241
|
+
return `timeoutSeconds must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`;
|
|
242
|
+
const params = {
|
|
243
|
+
include,
|
|
244
|
+
ignore,
|
|
245
|
+
compress: value.compress === true,
|
|
246
|
+
style,
|
|
247
|
+
lineNumbers: value.lineNumbers === true,
|
|
248
|
+
timeoutSeconds: timeout
|
|
249
|
+
};
|
|
250
|
+
if (typeof directory === "string")
|
|
251
|
+
params.directory = directory;
|
|
252
|
+
if (typeof remote === "string")
|
|
253
|
+
params.remote = remote;
|
|
254
|
+
if (typeof ref === "string")
|
|
255
|
+
params.ref = ref;
|
|
256
|
+
return params;
|
|
257
|
+
}
|
|
258
|
+
function resolveTarget(params, cwd) {
|
|
259
|
+
if (params.remote !== undefined) {
|
|
260
|
+
const target = { kind: "remote", remote: params.remote };
|
|
261
|
+
if (params.ref !== undefined)
|
|
262
|
+
target.ref = params.ref;
|
|
263
|
+
return target;
|
|
264
|
+
}
|
|
265
|
+
const directory = params.directory ?? ".";
|
|
266
|
+
return { kind: "local", directory: isAbsolute(directory) ? directory : resolve(cwd, directory) };
|
|
267
|
+
}
|
|
268
|
+
function targetResource(target) {
|
|
269
|
+
return target.kind === "local" ? target.directory : target.ref ? `${target.remote}@${target.ref}` : target.remote;
|
|
270
|
+
}
|
|
271
|
+
function chooseRunner(which) {
|
|
272
|
+
const found = which("repomix");
|
|
273
|
+
return found ? { kind: "path", argv: [found] } : { kind: "npx", argv: ["npx", "--yes", `repomix@${REPOMIX_VERSION}`] };
|
|
274
|
+
}
|
|
275
|
+
function packArgv(runner, params, target, config, output) {
|
|
276
|
+
return [
|
|
277
|
+
...runner.argv,
|
|
278
|
+
`--config=${config}`,
|
|
279
|
+
`--output=${output}`,
|
|
280
|
+
`--style=${params.style}`,
|
|
281
|
+
"--no-file-summary",
|
|
282
|
+
"--no-git-sort-by-changes",
|
|
283
|
+
`--top-files-len=${TOP_FILES}`,
|
|
284
|
+
...params.compress ? ["--compress"] : [],
|
|
285
|
+
...params.lineNumbers ? ["--output-show-line-numbers"] : [],
|
|
286
|
+
...params.include.length > 0 ? [`--include=${params.include.join(",")}`] : [],
|
|
287
|
+
...params.ignore.length > 0 ? [`--ignore=${params.ignore.join(",")}`] : [],
|
|
288
|
+
...target.kind === "remote" ? [`--remote=${target.remote}`, ...target.ref ? [`--remote-branch=${target.ref}`] : []] : [target.directory]
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
function packLabel(target) {
|
|
292
|
+
const raw = target.kind === "local" ? basename(target.directory) : `${target.remote.replace(/\.git$/, "").split("/").slice(-1)[0]}${target.ref ? `-${target.ref}` : ""}`;
|
|
293
|
+
return raw.replace(/[^\w.-]+/g, "-").replace(/^[-.]+/, "").slice(0, 60) || "pack";
|
|
294
|
+
}
|
|
295
|
+
var ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
|
|
296
|
+
var count = (text) => Number(text.replace(/,/g, ""));
|
|
297
|
+
function parseSummary(stdout) {
|
|
298
|
+
const lines = stdout.replace(ANSI, "").split(/\r\n|\r|\n/);
|
|
299
|
+
const summary = { version: null, files: null, tokens: null, chars: null, topFiles: [], suspiciousExcluded: [] };
|
|
300
|
+
let section = null;
|
|
301
|
+
for (const line of lines) {
|
|
302
|
+
const version = /Repomix v(\d[\w.+-]*)/.exec(line);
|
|
303
|
+
if (version && summary.version === null)
|
|
304
|
+
summary.version = version[1] ?? null;
|
|
305
|
+
if (/Top \d+ Files/.test(line))
|
|
306
|
+
section = "top";
|
|
307
|
+
else if (/Security Check:/.test(line))
|
|
308
|
+
section = "security";
|
|
309
|
+
else if (/Pack Summary:|^\s*(Total Files|These files have been excluded)/.test(line))
|
|
310
|
+
section = null;
|
|
311
|
+
const total = /^\s*Total (Files|Tokens|Chars):\s*([\d,]+)/.exec(line);
|
|
312
|
+
if (total) {
|
|
313
|
+
const key = total[1] === "Files" ? "files" : total[1] === "Tokens" ? "tokens" : "chars";
|
|
314
|
+
summary[key] = count(total[2] ?? "");
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (section === "top") {
|
|
318
|
+
const top = /^\s*\d+\.\s+(.+?) \(([\d,]+) tokens/.exec(line);
|
|
319
|
+
if (top)
|
|
320
|
+
summary.topFiles.push({ path: top[1] ?? "", tokens: count(top[2] ?? "") });
|
|
321
|
+
} else if (section === "security") {
|
|
322
|
+
const flagged = /^\s*\d+\.\s+(\S.*?)\s*$/.exec(line);
|
|
323
|
+
if (flagged)
|
|
324
|
+
summary.suspiciousExcluded.push(flagged[1] ?? "");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return summary;
|
|
328
|
+
}
|
|
329
|
+
function tail(text) {
|
|
330
|
+
const clean = text.replace(ANSI, "").trim();
|
|
331
|
+
return clean.length > MAX_ERROR_CHARS ? `\u2026${clean.slice(-MAX_ERROR_CHARS)}` : clean;
|
|
332
|
+
}
|
|
333
|
+
var fmt = (n) => n === null ? "?" : n.toLocaleString("en-US");
|
|
334
|
+
function interpretPack(run, output, style, timeoutSeconds, exists) {
|
|
335
|
+
if (run.kind !== "exited") {
|
|
336
|
+
const why = run.kind === "timeout" ? `repomix did not finish within ${timeoutSeconds}s and was killed` : run.kind === "aborted" ? "repomix was cancelled" : "repomix ended without an exit status";
|
|
337
|
+
return { ok: false, status: run.kind, text: [why, tail(run.stderr)].filter(Boolean).join(`
|
|
338
|
+
`) };
|
|
339
|
+
}
|
|
340
|
+
if (run.exitCode !== 0 || !exists(output)) {
|
|
341
|
+
const head = run.exitCode !== 0 ? `repomix failed (exit ${run.exitCode}).` : "repomix exited 0 but wrote no pack.";
|
|
342
|
+
return { ok: false, status: "failed", text: [head, tail(run.stderr), tail(run.stdout)].filter(Boolean).join(`
|
|
343
|
+
`) };
|
|
344
|
+
}
|
|
345
|
+
const summary = parseSummary(run.stdout);
|
|
346
|
+
const lines = [
|
|
347
|
+
`Packed ${fmt(summary.files)} files, ${fmt(summary.tokens)} tokens (${fmt(summary.chars)} chars) to ${output}`,
|
|
348
|
+
`Never read the whole pack: grep it for '${ANCHORS[style]}' to list files, then read slices with offset and limit.`
|
|
349
|
+
];
|
|
350
|
+
if (summary.tokens !== null && summary.tokens > LARGE_PACK_TOKENS)
|
|
351
|
+
lines.push(`Over ${fmt(LARGE_PACK_TOKENS)} tokens: hand the path to a researcher subagent rather than reading it here.`);
|
|
352
|
+
if (summary.topFiles.length > 0)
|
|
353
|
+
lines.push("Top files by tokens:", ...summary.topFiles.map((file) => ` ${fmt(file.tokens)} ${file.path}`));
|
|
354
|
+
if (summary.suspiciousExcluded.length > 0)
|
|
355
|
+
lines.push(`Left out by the secret scan (${summary.suspiciousExcluded.length}): ${summary.suspiciousExcluded.join(", ")}`);
|
|
356
|
+
return { ok: true, status: "packed", path: output, summary, text: lines.join(`
|
|
357
|
+
`) };
|
|
358
|
+
}
|
|
359
|
+
function prunePacks(root, now, ttlMs = PACK_TTL_MS) {
|
|
360
|
+
let names;
|
|
361
|
+
try {
|
|
362
|
+
names = readdirSync(root);
|
|
363
|
+
} catch {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
for (const name of names) {
|
|
367
|
+
if (!/^(repomix-|run-)/.test(name))
|
|
368
|
+
continue;
|
|
369
|
+
const path = join(root, name);
|
|
370
|
+
try {
|
|
371
|
+
if (now - statSync(path).mtimeMs > ttlMs)
|
|
372
|
+
rmSync(path, { recursive: true, force: true });
|
|
373
|
+
} catch {}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
var spawnRepomix = async (argv, { cwd, timeoutMs, signal }) => {
|
|
377
|
+
try {
|
|
378
|
+
const child = Bun.spawn(argv, {
|
|
379
|
+
cwd,
|
|
380
|
+
stdin: "ignore",
|
|
381
|
+
stdout: "pipe",
|
|
382
|
+
stderr: "pipe",
|
|
383
|
+
env: { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0" },
|
|
384
|
+
detached: true
|
|
385
|
+
});
|
|
386
|
+
return await supervise(child, { timeoutMs, signal, group: true });
|
|
387
|
+
} catch (error) {
|
|
388
|
+
return { kind: "exited", exitCode: 127, signalCode: null, stdout: "", stderr: String(error) };
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
async function runPack(params, target, runner, signal, deps = {}) {
|
|
392
|
+
const root = deps.root ?? join(tmpdir(), "srobroek", "repomix");
|
|
393
|
+
const now = deps.now?.() ?? Date.now();
|
|
394
|
+
mkdirSync(root, { recursive: true });
|
|
395
|
+
prunePacks(root, now);
|
|
396
|
+
const run = mkdtempSync(join(root, "run-"));
|
|
397
|
+
const config = join(run, "repomix.empty.json");
|
|
398
|
+
writeFileSync(config, `{}
|
|
399
|
+
`);
|
|
400
|
+
const id = `${now.toString(36)}${basename(run).slice(4)}`;
|
|
401
|
+
const output = join(root, `repomix-${packLabel(target)}-${id}.${STYLES[params.style]}`);
|
|
402
|
+
const exists = deps.exists ?? ((path) => {
|
|
403
|
+
try {
|
|
404
|
+
return statSync(path).isFile();
|
|
405
|
+
} catch {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
try {
|
|
410
|
+
const argv = packArgv(runner, params, target, config, output);
|
|
411
|
+
const result = await (deps.exec ?? spawnRepomix)(argv, { cwd: run, timeoutMs: params.timeoutSeconds * 1000, signal });
|
|
412
|
+
return interpretPack(result, output, params.style, params.timeoutSeconds, exists);
|
|
413
|
+
} finally {
|
|
414
|
+
rmSync(run, { recursive: true, force: true });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// plugins/repomix/pi-src/repomix.ts
|
|
419
|
+
var properties = PACK_INPUT.properties;
|
|
420
|
+
var parameters = Type.Object({
|
|
421
|
+
directory: Type.Optional(Type.String({ description: properties.directory.description })),
|
|
422
|
+
remote: Type.Optional(Type.String({ description: properties.remote.description })),
|
|
423
|
+
ref: Type.Optional(Type.String({ description: properties.ref.description })),
|
|
424
|
+
include: Type.Optional(Type.Array(Type.String(), { description: properties.include.description })),
|
|
425
|
+
ignore: Type.Optional(Type.Array(Type.String(), { description: properties.ignore.description })),
|
|
426
|
+
compress: Type.Optional(Type.Boolean({ description: properties.compress.description })),
|
|
427
|
+
style: Type.Optional(Type.Union([Type.Literal("xml"), Type.Literal("markdown"), Type.Literal("plain")], { description: properties.style.description })),
|
|
428
|
+
lineNumbers: Type.Optional(Type.Boolean({ description: properties.lineNumbers.description })),
|
|
429
|
+
timeoutSeconds: Type.Optional(Type.Integer({ minimum: 1, maximum: properties.timeoutSeconds.maximum, description: properties.timeoutSeconds.description }))
|
|
430
|
+
}, { additionalProperties: false });
|
|
431
|
+
var isDirectory = (path) => {
|
|
432
|
+
try {
|
|
433
|
+
return statSync2(path).isDirectory();
|
|
434
|
+
} catch {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
function registerRepomix(pi, overrides = {}) {
|
|
439
|
+
const which = overrides.which ?? ((bin) => Bun.which(bin));
|
|
440
|
+
pi.registerTool({
|
|
441
|
+
name: PACK_TOOL,
|
|
442
|
+
label: "Pack Repository",
|
|
443
|
+
description: PACK_DESCRIPTION,
|
|
444
|
+
parameters,
|
|
445
|
+
async execute(_id, raw, signal, _update, ctx) {
|
|
446
|
+
const params = readPackParams(raw);
|
|
447
|
+
if (typeof params === "string")
|
|
448
|
+
return { content: [{ type: "text", text: `${PACK_TOOL}: ${params}` }], details: { ok: false } };
|
|
449
|
+
const target = resolveTarget(params, ctx.cwd);
|
|
450
|
+
if (target.kind === "local" && !(overrides.isDirectory ?? isDirectory)(target.directory))
|
|
451
|
+
return { content: [{ type: "text", text: `${PACK_TOOL}: ${target.directory} is not a directory` }], details: { ok: false } };
|
|
452
|
+
const runner = chooseRunner(which);
|
|
453
|
+
const resource = targetResource(target);
|
|
454
|
+
if (!ctx.hasUI)
|
|
455
|
+
return { content: [{ type: "text", text: `${PACK_TOOL}: write refused because confirmation UI is unavailable for ${resource}` }], details: { ok: false } };
|
|
456
|
+
if (!await ctx.ui.confirm("Confirm repository pack", `Run ${runner.kind === "npx" ? `npx repomix@1.19.0` : "repomix"} to pack ${resource}? The pack will be written to a temporary file.`))
|
|
457
|
+
return { content: [{ type: "text", text: `${PACK_TOOL}: pack cancelled` }], details: { ok: false } };
|
|
458
|
+
try {
|
|
459
|
+
const result = await runPack(params, target, runner, signal, overrides);
|
|
460
|
+
return {
|
|
461
|
+
content: [{ type: "text", text: result.ok ? result.text : `${PACK_TOOL}: ${result.text}` }],
|
|
462
|
+
details: {
|
|
463
|
+
ok: result.ok,
|
|
464
|
+
status: result.status,
|
|
465
|
+
runner: runner.kind,
|
|
466
|
+
path: result.path,
|
|
467
|
+
files: result.summary?.files,
|
|
468
|
+
tokens: result.summary?.tokens,
|
|
469
|
+
topFiles: result.summary?.topFiles,
|
|
470
|
+
suspiciousExcluded: result.summary?.suspiciousExcluded
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
} catch (error) {
|
|
474
|
+
return { content: [{ type: "text", text: `${PACK_TOOL}: ${error instanceof Error ? error.message : String(error)}` }], details: { ok: false } };
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
function repomix_default(pi) {
|
|
480
|
+
registerRepomix(pi);
|
|
481
|
+
}
|
|
482
|
+
export {
|
|
483
|
+
repomix_default as default,
|
|
484
|
+
registerRepomix
|
|
485
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srobroek/pi-repomix",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.6.3",
|
|
4
|
+
"description": "Pack a local or remote repo into one file with repomix for bulk context: external repos, module packs and version diffs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/srobroek/harness-plugins.git",
|
|
12
|
+
"directory": "plugins/repomix/pi"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.md",
|
|
18
|
+
"extensions",
|
|
19
|
+
"skills"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"typebox": "*"
|
|
27
|
+
},
|
|
28
|
+
"pi": {
|
|
29
|
+
"extensions": [
|
|
30
|
+
"./extensions/repomix.js"
|
|
31
|
+
],
|
|
32
|
+
"skills": [
|
|
33
|
+
"./skills"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: repomix
|
|
3
|
+
description: "Use to pack a repo into one file with repomix for bulk context: external repo APIs, module review, version diffs, docs."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# repomix
|
|
7
|
+
|
|
8
|
+
repomix packs many files into one file. Use it when the question needs a lot of files at
|
|
9
|
+
once. For a single lookup ("where is X", "what does this function do"), use grep and read
|
|
10
|
+
instead: they cost less.
|
|
11
|
+
|
|
12
|
+
## When it helps
|
|
13
|
+
|
|
14
|
+
| Use case | Pack | Then |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| Learn an external repo's layout and APIs | `remote: "owner/repo"`, `ref: "<tag>"`, `compress: true`, `include: ["src/**"]` | grep the pack for file anchors, read the slices you need |
|
|
17
|
+
| Review a whole module | `directory: "<repo>"`, `include: ["<module>/**"]`, `ignore: ["**/dist/**"]`, `lineNumbers: true`, no compress | pass the pack path to the reviewer in its brief |
|
|
18
|
+
| Compare two versions | the same `remote` and `include` at two `ref`s, `compress: true` | `diff` the two pack files and read only the changed hunks |
|
|
19
|
+
| Read a doc set | `remote: "owner/repo"`, `include: ["docs/**/*.md"]`, `style: "markdown"`, no compress | grep for `## File: ` and read the relevant pages |
|
|
20
|
+
|
|
21
|
+
## Keep the pack out of your context
|
|
22
|
+
|
|
23
|
+
1. `repomix_pack` writes the pack to a temporary file and returns its path, file and token totals, top files, and any files the secret scan left out. It never returns the pack itself.
|
|
24
|
+
2. Never read the whole pack. Grep it for the file anchor (`<file path="` for xml,
|
|
25
|
+
`## File: ` for markdown, `File: ` for plain) to list the files with their line numbers,
|
|
26
|
+
then read one file's slice with offset and limit.
|
|
27
|
+
3. If a pack is over about 50k tokens, give its path to a researcher subagent with the
|
|
28
|
+
question, and work from its answer.
|
|
29
|
+
4. Narrow with `include` before you compress. A pack of `src/**` is often a tenth of the
|
|
30
|
+
whole repo.
|
|
31
|
+
|
|
32
|
+
## Compression
|
|
33
|
+
|
|
34
|
+
`compress` keeps imports, exported signatures, types and doc comments, and drops function
|
|
35
|
+
bodies. That suits an API or architecture overview of code (about 70% smaller for
|
|
36
|
+
TypeScript). Don't compress:
|
|
37
|
+
|
|
38
|
+
- Tests: the `describe`/`test` calls are dropped, so a compressed test file is only its
|
|
39
|
+
imports. Leave tests out (`ignore: ["**/*.test.*"]`) or pack them separately.
|
|
40
|
+
- Markdown and other prose: compression saves nothing there.
|
|
41
|
+
- Code you need to review line by line: pack it uncompressed with `lineNumbers`.
|
|
42
|
+
|
|
43
|
+
## Safety
|
|
44
|
+
|
|
45
|
+
- The target's `repomix.config.*` is never loaded. A JS or TS config is code, so packing a
|
|
46
|
+
third-party checkout is safe. A `.repomixignore` in the target still applies.
|
|
47
|
+
- The secret scan always runs. A flagged file is left out of the pack and named in the
|
|
48
|
+
result. The scan is a heuristic, so don't paste pack contents anywhere public.
|
|
49
|
+
- When repomix is not on PATH, the tool runs a pinned version through npx, because npx
|
|
50
|
+
downloads code. The user's permission rules decide whether that runs.
|
|
51
|
+
|
|
52
|
+
## Without the tool
|
|
53
|
+
|
|
54
|
+
Where the `repomix_pack` tool is not available, run the CLI with the same rules. Write to a temp file, never to stdout. Point `--config` at an empty JSON file so no config is loaded, and never pass `--no-security-check` or `--remote-trust-config`:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
dir=$(mktemp -d) && echo '{}' > "$dir/empty.json"
|
|
58
|
+
repomix --config="$dir/empty.json" --output="$dir/pack.xml" --no-file-summary \
|
|
59
|
+
--no-git-sort-by-changes --compress --include='src/**' \
|
|
60
|
+
--remote=owner/repo --remote-branch=v1.2.0
|
|
61
|
+
grep -n '<file path="' "$dir/pack.xml"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Without `--no-git-sort-by-changes`, repomix orders files by git churn, so two packs of
|
|
65
|
+
different versions diff noisily. Delete the temp directory when you are done.
|
|
66
|
+
## Optional Pi MCP server
|
|
67
|
+
|
|
68
|
+
Pi can run repomix's MCP server by adding `repomix` with `--mcp` to Pi's MCP configuration. `--sandbox` confines file access to the working directory but disables remote packing. Without `--sandbox`, the server can access any path available to the process.
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"repomix": {
|
|
74
|
+
"command": "repomix",
|
|
75
|
+
"args": ["--mcp", "--sandbox"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|