ceulen 0.8.0 → 0.10.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/extensions/lib/registry.ts +16 -3
  3. package/extensions/modules/a2a/configPanel.ts +435 -0
  4. package/extensions/modules/a2a/index.ts +1117 -0
  5. package/extensions/modules/a2a/lib/activity.ts +173 -0
  6. package/extensions/modules/a2a/lib/client.ts +1061 -0
  7. package/extensions/modules/a2a/lib/config.ts +920 -0
  8. package/extensions/modules/a2a/lib/discovery.ts +158 -0
  9. package/extensions/modules/a2a/lib/gateway.ts +889 -0
  10. package/extensions/modules/a2a/lib/mdns.ts +233 -0
  11. package/extensions/modules/a2a/lib/outcome.ts +48 -0
  12. package/extensions/modules/a2a/lib/persistence.ts +123 -0
  13. package/extensions/modules/a2a/lib/protocol.ts +506 -0
  14. package/extensions/modules/a2a/lib/registry.ts +146 -0
  15. package/extensions/modules/a2a/lib/retry.ts +86 -0
  16. package/extensions/modules/a2a/lib/security.ts +394 -0
  17. package/extensions/modules/a2a/lib/server.ts +1436 -0
  18. package/extensions/modules/a2a/test/activity.test.ts +138 -0
  19. package/extensions/modules/a2a/test/bridge.test.ts +101 -0
  20. package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
  21. package/extensions/modules/a2a/test/chai.ts +101 -0
  22. package/extensions/modules/a2a/test/client.test.ts +856 -0
  23. package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
  24. package/extensions/modules/a2a/test/config.test.ts +1396 -0
  25. package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
  26. package/extensions/modules/a2a/test/discovery.test.ts +144 -0
  27. package/extensions/modules/a2a/test/extension.test.ts +135 -0
  28. package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
  29. package/extensions/modules/a2a/test/helpers.ts +39 -0
  30. package/extensions/modules/a2a/test/mdns.test.ts +131 -0
  31. package/extensions/modules/a2a/test/outcome.test.ts +61 -0
  32. package/extensions/modules/a2a/test/persistence.test.ts +92 -0
  33. package/extensions/modules/a2a/test/protocol.test.ts +217 -0
  34. package/extensions/modules/a2a/test/registry.test.ts +114 -0
  35. package/extensions/modules/a2a/test/retry.test.ts +136 -0
  36. package/extensions/modules/a2a/test/security.test.ts +281 -0
  37. package/extensions/modules/a2a/test/server.test.ts +1966 -0
  38. package/extensions/modules/a2a/test/tmp.ts +59 -0
  39. package/extensions/modules/a2a/test/vendor.test.ts +57 -0
  40. package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
  41. package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
  42. package/extensions/modules/a2a/vendor/package.json +1 -0
  43. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
  44. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
  45. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
  46. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
  47. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
  48. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
  49. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
  50. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
  51. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
  52. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
  53. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
  54. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
  55. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
  56. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
  57. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
  58. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
  59. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
  60. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
  61. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
  62. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
  63. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
  64. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
  65. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
  66. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
  67. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
  68. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
  69. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
  70. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
  71. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
  72. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
  73. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
  74. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
  75. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
  76. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
  77. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
  78. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
  79. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
  80. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
  81. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
  82. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
  83. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
  84. package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
  85. package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
  86. package/extensions/modules/composer/test/module.test.ts +2 -2
  87. package/extensions/modules/config/index.ts +3 -0
  88. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  89. package/extensions/modules/gh/configPanel.ts +82 -0
  90. package/extensions/modules/gh/index.ts +86 -0
  91. package/extensions/modules/gh/lib/gh-cli.ts +337 -0
  92. package/extensions/modules/gh/lib/ops.ts +771 -0
  93. package/extensions/modules/gh/test/gh.test.ts +280 -0
  94. package/extensions/modules/plan/lib/plan-tools.ts +8 -0
  95. package/extensions/modules/repair/index.ts +138 -0
  96. package/extensions/modules/repair/lib/guards.ts +1 -1
  97. package/extensions/modules/repair/lib/read-selector.ts +242 -0
  98. package/extensions/modules/repair/test/read-selector.test.ts +198 -0
  99. package/extensions/modules/steering/configPanel.ts +8 -0
  100. package/extensions/modules/steering/index.ts +6 -0
  101. package/extensions/modules/steering/lib/settings.ts +6 -2
  102. package/extensions/modules/steering/lib/think.ts +66 -0
  103. package/extensions/modules/steering/test/harness.ts +5 -0
  104. package/extensions/modules/steering/test/settings.test.ts +2 -0
  105. package/extensions/modules/steering/test/think.test.ts +77 -0
  106. package/extensions/modules/todo/configPanel.ts +55 -0
  107. package/extensions/modules/todo/index.ts +46 -13
  108. package/extensions/modules/todo/lib/render.ts +271 -0
  109. package/extensions/modules/todo/lib/settings.ts +73 -0
  110. package/extensions/modules/todo/test/todo.test.ts +276 -0
  111. package/extensions/modules/web/index.ts +37 -1
  112. package/extensions/modules/web/lib/a11y.ts +252 -0
  113. package/extensions/modules/web/test/a11y.test.ts +218 -0
  114. package/extensions/modules/web/test/extension.test.ts +2 -2
  115. package/extensions/modules/web/test/hook.test.ts +2 -2
  116. package/extensions/modules/web/vendor/axe/LICENSE +362 -0
  117. package/extensions/modules/web/vendor/axe/LICENSE-3RD-PARTY.txt +66 -0
  118. package/extensions/modules/web/vendor/axe/README.md +19 -0
  119. package/extensions/modules/web/vendor/axe/axe.min.js +12 -0
  120. package/package.json +2 -2
  121. package/skills/a2a/SKILL.md +63 -0
  122. package/skills/web/SKILL.md +1 -0
@@ -0,0 +1,205 @@
1
+ var packet = require('../dns-packet/index.js') // ponytail: vendored from multicast-dns 7.2.5 — path localized
2
+ var dgram = require('dgram')
3
+ var thunky = require('../thunky/index.js') // ponytail: vendored from multicast-dns 7.2.5 — path localized
4
+ var events = require('events')
5
+ var os = require('os')
6
+
7
+ var noop = function () {}
8
+
9
+ module.exports = function (opts) {
10
+ if (!opts) opts = {}
11
+
12
+ var that = new events.EventEmitter()
13
+ var port = typeof opts.port === 'number' ? opts.port : 5353
14
+ var type = opts.type || 'udp4'
15
+ var ip = opts.ip || opts.host || (type === 'udp4' ? '224.0.0.251' : null)
16
+ var me = {address: ip, port: port}
17
+ var memberships = {}
18
+ var destroyed = false
19
+ var interval = null
20
+
21
+ if (type === 'udp6' && (!ip || !opts.interface)) {
22
+ throw new Error('For IPv6 multicast you must specify `ip` and `interface`')
23
+ }
24
+
25
+ var socket = opts.socket || dgram.createSocket({
26
+ type: type,
27
+ reuseAddr: opts.reuseAddr !== false,
28
+ toString: function () {
29
+ return type
30
+ }
31
+ })
32
+
33
+ socket.on('error', function (err) {
34
+ if (err.code === 'EACCES' || err.code === 'EADDRINUSE') that.emit('error', err)
35
+ else that.emit('warning', err)
36
+ })
37
+
38
+ socket.on('message', function (message, rinfo) {
39
+ try {
40
+ message = packet.decode(message)
41
+ } catch (err) {
42
+ that.emit('warning', err)
43
+ return
44
+ }
45
+
46
+ that.emit('packet', message, rinfo)
47
+
48
+ if (message.type === 'query') that.emit('query', message, rinfo)
49
+ if (message.type === 'response') that.emit('response', message, rinfo)
50
+ })
51
+
52
+ socket.on('listening', function () {
53
+ if (!port) port = me.port = socket.address().port
54
+ if (opts.multicast !== false) {
55
+ that.update()
56
+ interval = setInterval(that.update, 5000)
57
+ socket.setMulticastTTL(opts.ttl || 255)
58
+ socket.setMulticastLoopback(opts.loopback !== false)
59
+ }
60
+ })
61
+
62
+ var bind = thunky(function (cb) {
63
+ if (!port || opts.bind === false) return cb(null)
64
+ socket.once('error', cb)
65
+ socket.bind(port, opts.bind || opts.interface, function () {
66
+ socket.removeListener('error', cb)
67
+ cb(null)
68
+ })
69
+ })
70
+
71
+ bind(function (err) {
72
+ if (err) return that.emit('error', err)
73
+ that.emit('ready')
74
+ })
75
+
76
+ that.send = function (value, rinfo, cb) {
77
+ if (typeof rinfo === 'function') return that.send(value, null, rinfo)
78
+ if (!cb) cb = noop
79
+ if (!rinfo) rinfo = me
80
+ else if (!rinfo.host && !rinfo.address) rinfo.address = me.address
81
+
82
+ bind(onbind)
83
+
84
+ function onbind (err) {
85
+ if (destroyed) return cb()
86
+ if (err) return cb(err)
87
+ var message = packet.encode(value)
88
+ socket.send(message, 0, message.length, rinfo.port, rinfo.address || rinfo.host, cb)
89
+ }
90
+ }
91
+
92
+ that.response =
93
+ that.respond = function (res, rinfo, cb) {
94
+ if (Array.isArray(res)) res = {answers: res}
95
+
96
+ res.type = 'response'
97
+ res.flags = (res.flags || 0) | packet.AUTHORITATIVE_ANSWER
98
+ that.send(res, rinfo, cb)
99
+ }
100
+
101
+ that.query = function (q, type, rinfo, cb) {
102
+ if (typeof type === 'function') return that.query(q, null, null, type)
103
+ if (typeof type === 'object' && type && type.port) return that.query(q, null, type, rinfo)
104
+ if (typeof rinfo === 'function') return that.query(q, type, null, rinfo)
105
+ if (!cb) cb = noop
106
+
107
+ if (typeof q === 'string') q = [{name: q, type: type || 'ANY'}]
108
+ if (Array.isArray(q)) q = {type: 'query', questions: q}
109
+
110
+ q.type = 'query'
111
+ that.send(q, rinfo, cb)
112
+ }
113
+
114
+ that.destroy = function (cb) {
115
+ if (!cb) cb = noop
116
+ if (destroyed) return process.nextTick(cb)
117
+ destroyed = true
118
+ clearInterval(interval)
119
+
120
+ // Need to drop memberships by hand and ignore errors.
121
+ // socket.close() does not cope with errors.
122
+ for (var iface in memberships) {
123
+ try {
124
+ socket.dropMembership(ip, iface)
125
+ } catch (e) {
126
+ // eat it
127
+ }
128
+ }
129
+ memberships = {}
130
+ socket.close(cb)
131
+ }
132
+
133
+ that.update = function () {
134
+ var ifaces = opts.interface ? [].concat(opts.interface) : allInterfaces()
135
+ var updated = false
136
+
137
+ for (var i = 0; i < ifaces.length; i++) {
138
+ var addr = ifaces[i]
139
+ if (memberships[addr]) continue
140
+
141
+ try {
142
+ socket.addMembership(ip, addr)
143
+ memberships[addr] = true
144
+ updated = true
145
+ } catch (err) {
146
+ that.emit('warning', err)
147
+ }
148
+ }
149
+
150
+ if (updated) {
151
+ if (socket.setMulticastInterface) {
152
+ try {
153
+ socket.setMulticastInterface(opts.interface || defaultInterface())
154
+ } catch (err) {
155
+ that.emit('warning', err)
156
+ }
157
+ }
158
+ that.emit('networkInterface')
159
+ }
160
+ }
161
+
162
+ return that
163
+ }
164
+
165
+ function defaultInterface () {
166
+ var networks = os.networkInterfaces()
167
+ var names = Object.keys(networks)
168
+
169
+ for (var i = 0; i < names.length; i++) {
170
+ var net = networks[names[i]]
171
+ for (var j = 0; j < net.length; j++) {
172
+ var iface = net[j]
173
+ if (isIPv4(iface.family) && !iface.internal) {
174
+ if (os.platform() === 'darwin' && names[i] === 'en0') return iface.address
175
+ return '0.0.0.0'
176
+ }
177
+ }
178
+ }
179
+
180
+ return '127.0.0.1'
181
+ }
182
+
183
+ function allInterfaces () {
184
+ var networks = os.networkInterfaces()
185
+ var names = Object.keys(networks)
186
+ var res = []
187
+
188
+ for (var i = 0; i < names.length; i++) {
189
+ var net = networks[names[i]]
190
+ for (var j = 0; j < net.length; j++) {
191
+ var iface = net[j]
192
+ if (isIPv4(iface.family)) {
193
+ res.push(iface.address)
194
+ // could only addMembership once per interface (https://nodejs.org/api/dgram.html#dgram_socket_addmembership_multicastaddress_multicastinterface)
195
+ break
196
+ }
197
+ }
198
+ }
199
+
200
+ return res
201
+ }
202
+
203
+ function isIPv4 (family) { // for backwards compat
204
+ return family === 4 || family === 'IPv4'
205
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Mathias Buus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+ var nextTick = nextTickArgs
4
+ process.nextTick(upgrade, 42) // pass 42 and see if upgrade is called with it
5
+
6
+ module.exports = thunky
7
+
8
+ function thunky (fn) {
9
+ var state = run
10
+ return thunk
11
+
12
+ function thunk (callback) {
13
+ state(callback || noop)
14
+ }
15
+
16
+ function run (callback) {
17
+ var stack = [callback]
18
+ state = wait
19
+ fn(done)
20
+
21
+ function wait (callback) {
22
+ stack.push(callback)
23
+ }
24
+
25
+ function done (err) {
26
+ var args = arguments
27
+ state = isError(err) ? run : finished
28
+ while (stack.length) finished(stack.shift())
29
+
30
+ function finished (callback) {
31
+ nextTick(apply, callback, args)
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ function isError (err) { // inlined from util so this works in the browser
38
+ return Object.prototype.toString.call(err) === '[object Error]'
39
+ }
40
+
41
+ function noop () {}
42
+
43
+ function apply (callback, args) {
44
+ callback.apply(null, args)
45
+ }
46
+
47
+ function upgrade (val) {
48
+ if (val === 42) nextTick = process.nextTick
49
+ }
50
+
51
+ function nextTickArgs (fn, a, b) {
52
+ process.nextTick(function () {
53
+ fn(a, b)
54
+ })
55
+ }
@@ -305,8 +305,8 @@ describe("core module contract", () => {
305
305
  it("nextDisabled excludes core modules; withEnableRow adds no row for them", async () => {
306
306
  const { nextDisabled, withEnableRow } = await import("../../config/index.js");
307
307
  // working = enabled set; nextDisabled lists the NOT-enabled non-core modules.
308
- assert.deepEqual(nextDisabled(new Set(["munin"])), ["zai", "ponytail", "subagent", "plan", "todo", "repair", "serena", "fff", "web", "rules", "steering", "rtk"]);
309
- assert.deepEqual(nextDisabled(new Set(["router", "classifier", "ux", "munin", "usage", "ponytail", "subagent", "plan", "todo", "repair", "serena", "fff", "web", "rules", "steering", "zai", "rtk", "config"])), [], "all-on → nothing disabled");
308
+ assert.deepEqual(nextDisabled(new Set(["munin"])), ["zai", "ponytail", "subagent", "plan", "a2a", "todo", "repair", "serena", "fff", "web", "rules", "gh", "steering", "rtk"]);
309
+ assert.deepEqual(nextDisabled(new Set(["router", "classifier", "ux", "munin", "usage", "ponytail", "subagent", "plan", "a2a", "todo", "repair", "serena", "fff", "web", "gh", "rules", "steering", "zai", "rtk", "config"])), [], "all-on → nothing disabled");
310
310
  for (const core of ["composer", "advisor", "router", "classifier", "usage", "ux", "config"]) {
311
311
  assert.ok(!nextDisabled(new Set()).includes(core), `core (${core}) is never disableable`);
312
312
  }
@@ -253,10 +253,13 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
253
253
  ux: { section: "UX discipline", icon: "📐" },
254
254
  ponytail: { section: "Ponytail", icon: "🦥" },
255
255
  plan: { section: "Plan mode", icon: "🗺️" },
256
+ todo: { section: "Todo", icon: "☑" },
256
257
  serena: { section: "Serena" },
257
258
  repair: { section: "Repair", icon: "🔧" },
258
259
  fff: { section: "FFF search" },
259
260
  web: { section: "Web", icon: "🌍" },
261
+ gh: { section: "GitHub", icon: "🐙" },
262
+ a2a: { section: "A2A", icon: "📡" },
260
263
  rtk: { section: "RTK" },
261
264
  config: { section: "Ceulen config", icon: "🧩" },
262
265
  };
@@ -34,7 +34,7 @@ function toolGroups(): PanelGroup[] {
34
34
  describe("render smoke — ported modules' /config sections", () => {
35
35
  it("renders Enable + per-tool rows inside the boxed frame with zero overflow", () => {
36
36
  const groups = toolGroups();
37
- assert.equal(groups.length, 12, "serena + fff + ux + munin + classifier + advisor + subagent + repair + plan + todo + web + rules (rtk has no tools)");
37
+ assert.equal(groups.length, 15, "serena + fff + ux + munin + classifier + advisor + subagent + repair + plan + todo + web + rules + a2a + gh + steering·think (rtk has no tools)");
38
38
  const m = new ConfigPanelModel(groups, theme, "Settings");
39
39
  m.getHeight = () => 40;
40
40
  for (const w of [110, 100, 80, 60]) {
@@ -0,0 +1,82 @@
1
+ // gh module's /config contribution — Tools tab, GitHub section.
2
+ //
3
+ // One row: the run_watch budget. The module itself needs no settings (the gh
4
+ // binary + the user's gh auth own everything else). Saving writes the GLOBAL
5
+ // settings.json `gh` section; ops read it per call, so a save applies live.
6
+
7
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
8
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
9
+ import os from "node:os";
10
+ import path from "node:path";
11
+ import { row, type PanelGroup } from "../../lib/panel.js";
12
+ import type { ModuleConfig } from "../../lib/registry.js";
13
+
14
+ export const DEFAULT_RUN_WATCH_TIMEOUT_SECS = 600;
15
+
16
+ function agentDir(): string {
17
+ return process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent");
18
+ }
19
+
20
+ export function readRunWatchTimeoutSecs(): number {
21
+ for (const file of [path.join(agentDir(), "settings.json")]) {
22
+ try {
23
+ if (!existsSync(file)) continue;
24
+ const section = JSON.parse(readFileSync(file, "utf8"))?.gh;
25
+ const v = section?.runWatchTimeoutSecs;
26
+ if (typeof v === "number" && Number.isFinite(v) && v > 0) return Math.floor(v);
27
+ } catch {
28
+ // corrupt layer → default
29
+ }
30
+ }
31
+ return DEFAULT_RUN_WATCH_TIMEOUT_SECS;
32
+ }
33
+
34
+ function writeRunWatchTimeoutSecs(secs: number): string {
35
+ const file = path.join(agentDir(), "settings.json");
36
+ let settings: Record<string, unknown> = {};
37
+ if (existsSync(file)) {
38
+ try {
39
+ settings = JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>;
40
+ } catch {
41
+ throw new Error(`${file} is not valid JSON — fix or remove it before saving.`);
42
+ }
43
+ }
44
+ settings.gh = { ...(settings.gh as object | undefined ?? {}), runWatchTimeoutSecs: secs };
45
+ mkdirSync(path.dirname(file), { recursive: true });
46
+ const tmp = file + ".tmp";
47
+ writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
48
+ renameSync(tmp, file);
49
+ return file;
50
+ }
51
+
52
+ export function buildGhGroups(runWatchTimeoutSecs: number): PanelGroup[] {
53
+ return [
54
+ {
55
+ key: "gh",
56
+ label: "GitHub",
57
+ tab: "Tools",
58
+ icon: "🐙",
59
+ rows: [
60
+ row("gh.runWatchTimeoutSecs", "run_watch budget", "number", runWatchTimeoutSecs, (v) => {
61
+ runWatchTimeoutSecs = Math.max(10, Math.floor(Number(v)));
62
+ }, {
63
+ defaultValue: DEFAULT_RUN_WATCH_TIMEOUT_SECS,
64
+ description: "Seconds run_watch keeps polling a workflow run before reporting in-progress (capped at gh's 5-min command deadline).",
65
+ }),
66
+ ],
67
+ },
68
+ ];
69
+ }
70
+
71
+ /** gh's ModuleConfig for the central /config panel. */
72
+ export function ghConfig(_pi: ExtensionAPI): ModuleConfig {
73
+ let working = readRunWatchTimeoutSecs();
74
+ return {
75
+ groups: () => buildGhGroups(working),
76
+ save: async (edited, ctx: ExtensionContext) => {
77
+ if (![...edited].some((k) => k.startsWith("gh."))) return;
78
+ const file = writeRunWatchTimeoutSecs(working);
79
+ ctx.ui.notify(`Saved gh.runWatchTimeoutSecs=${working} to ${file} (applies to the next run_watch call).`, "info");
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,86 @@
1
+ // gh module — one `github` tool over the `gh` CLI (zero npm deps).
2
+ //
3
+ // Ported from oh-my-pi's github tool (tools/gh*.ts + utils/github.ts), scoped
4
+ // to READ-ONLY ops: repo_view, file_read, pr_view, pr_diff, the five search
5
+ // flavors, run_watch. Mutating flows (pr_create/checkout/push) are deferred —
6
+ // bash `gh` covers them, and a read-only tool lets plan mode auto-allow it
7
+ // (plan-tools.ts READ_ONLY_TOOLS).
8
+ //
9
+ // Registration is fail-open on a missing `gh` binary: the module loads, the
10
+ // Enable row stays reachable, but no tool registers (OMP's createIf pattern)
11
+ // until gh is installed.
12
+
13
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
14
+ import { Type } from "typebox";
15
+ import { readDisabledTools } from "../../lib/tools.js";
16
+ import { ghAvailable, realGh } from "./lib/gh-cli.js";
17
+ import { executeOp } from "./lib/ops.js";
18
+
19
+ const OP_ENUM = [
20
+ "repo_view", "file_read", "pr_view", "pr_diff",
21
+ "search_issues", "search_prs", "search_code", "search_commits", "search_repos",
22
+ "run_watch",
23
+ ] as const;
24
+
25
+ const DESCRIPTION = [
26
+ "Interact with GitHub via the `gh` CLI — repositories, files, pull requests, issues, and Actions.",
27
+ "Read-only operations:",
28
+ "- repo_view: repository metadata (default branch, stars, language, topics).",
29
+ "- file_read: a repository file's contents (text; binary → notice with URL) at an optional branch/ref.",
30
+ "- pr_view: PR metadata, body, files, reviews.",
31
+ "- pr_diff: a PR's unified diff.",
32
+ "- search_issues / search_prs / search_code / search_commits / search_repos: GitHub search with repo/org/user scoping and since/until date filters.",
33
+ "- run_watch: poll a workflow run until it completes; on failure, tails each failed job's logs (`tail` lines per job). Blocks up to ~5 min.",
34
+ "",
35
+ "Prefer these over bash `gh` invocations: repo/ref normalization handles `[host/]owner/repo` and URLs, prompts can never hang, output is capped and structured.",
36
+ ].join("\n");
37
+
38
+ export default function ghModule(pi: ExtensionAPI): void {
39
+ // No `gh` binary → no tool; /config's Enable row still renders (the module
40
+ // stays registered in the loader) so installing gh + /reload activates it.
41
+ if (!ghAvailable()) return;
42
+
43
+ const disabled = readDisabledTools();
44
+ pi.registerTool({
45
+ name: "github",
46
+ label: "GitHub",
47
+ description: DESCRIPTION,
48
+ promptSnippet: "Interact with GitHub repos, files, PRs, issues, Actions via gh",
49
+ promptGuidelines: [
50
+ "Prefer search_code over web search for code in known GitHub repos; scope with repo:/org:/user: or the repo param.",
51
+ "run_watch blocks until the run finishes — pass `run` plus `tail` to bound log lines.",
52
+ "Read-only surface: create/push/checkout flows go through bash `gh` explicitly.",
53
+ ],
54
+ parameters: Type.Object({
55
+ op: Type.Union(OP_ENUM.map((o) => Type.Literal(o)), { description: "github operation" }),
56
+ repo: Type.Optional(Type.String({ description: "[host/]owner/repo (or full URL where noted); defaults to the cwd checkout." })),
57
+ branch: Type.Optional(Type.String({ description: "branch / ref (file_read, repo_view)." })),
58
+ path: Type.Optional(Type.String({ description: "repository-relative file path (file_read)." })),
59
+ pr: Type.Optional(Type.String({ description: "pr number, url, or branch (pr_view, pr_diff)." })),
60
+ query: Type.Optional(Type.String({ description: "search query (search_* ops)." })),
61
+ since: Type.Optional(Type.String({ description: "lower-bound date filter: relative (3d, 2w) or ISO (search_*, not search_code)." })),
62
+ until: Type.Optional(Type.String({ description: "upper-bound date filter (search_*, not search_code)." })),
63
+ dateField: Type.Optional(Type.Union([Type.Literal("created"), Type.Literal("updated")], { description: "date field for since/until (default created)." })),
64
+ limit: Type.Optional(Type.Number({ description: "max results (search_*; default 10, max 50)." })),
65
+ run: Type.Optional(Type.String({ description: "actions run id or url (run_watch)." })),
66
+ tail: Type.Optional(Type.Number({ description: "failed-job log tail lines (run_watch; default 15, max 200)." })),
67
+ }),
68
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
69
+ const cwd = ctx?.cwd || process.cwd();
70
+ const p = params as Record<string, unknown>;
71
+ try {
72
+ const result = await executeOp(p.op as string, realGh, cwd, p as never, signal);
73
+ const content: Array<{ type: "text"; text: string } | { type: "image"; data: string; mimeType: string }> = [
74
+ { type: "text", text: result.text },
75
+ ];
76
+ if (result.image) {
77
+ content.push({ type: "image", data: result.image.data, mimeType: result.image.mimeType });
78
+ }
79
+ return { content, details: { op: p.op, repo: p.repo } };
80
+ } catch (err) {
81
+ return { content: [{ type: "text", text: err instanceof Error ? err.message : String(err) }], isError: true, details: undefined };
82
+ }
83
+ },
84
+ defaultActive: !disabled.has("github"),
85
+ });
86
+ }