@hncode/hncode-sdk 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 +131 -0
- package/README.md +183 -0
- package/index.d.ts +436 -0
- package/index.js +109 -0
- package/package.json +42 -0
- package/targets.d.ts +714 -0
- package/targets.js +719 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization,
|
|
69
|
+
or government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control of,
|
|
122
|
+
or are under common control with that organization. **Control**
|
|
123
|
+
means ownership of substantially all the assets of an entity,
|
|
124
|
+
or the power to direct its management and policies by vote,
|
|
125
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
126
|
+
|
|
127
|
+
**Your licenses** are all the licenses granted to you for the
|
|
128
|
+
software under these terms.
|
|
129
|
+
|
|
130
|
+
**Use** means anything you do with the software requiring one
|
|
131
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @hncode/hncode-sdk
|
|
2
|
+
|
|
3
|
+
Types and runtime helpers for writing [hncode](https://npmjs.com/package/@hncode/hncode) plugins.
|
|
4
|
+
|
|
5
|
+
A plugin runs **inside** the hncode process: the host calls your `install(api)` and
|
|
6
|
+
hands you the `api` object. So a plugin never imports hncode itself — but at author
|
|
7
|
+
time you want completion for `api.` and, for `api.patch`, the list of symbols you
|
|
8
|
+
may target. That is what this package provides.
|
|
9
|
+
|
|
10
|
+
- **`HncodePluginApi`** — the type of the `api` object (every method, its
|
|
11
|
+
signature and return).
|
|
12
|
+
- **`PatchTarget`** — a literal union of every symbol a plugin may patch
|
|
13
|
+
(`'llm.js#LLM.requestText'`, `'git.js#commit'`, …), so the target string
|
|
14
|
+
completes and is checked.
|
|
15
|
+
- **Runtime helpers** — `definePlugin`, `parsePatchTarget`, `HOOK_NAMES`,
|
|
16
|
+
`LEGACY_SEAMS`, and the generated `PATCH_TARGETS` list.
|
|
17
|
+
|
|
18
|
+
It has **zero dependencies** and pulls in none of the CLI.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i -D @hncode/hncode-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Write a plugin
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// plugins/hello/index.js
|
|
30
|
+
import { definePlugin, HOOK_NAMES } from '@hncode/hncode-sdk';
|
|
31
|
+
|
|
32
|
+
export default definePlugin({
|
|
33
|
+
name: 'hello',
|
|
34
|
+
version: '1.0.0',
|
|
35
|
+
install(api) {
|
|
36
|
+
api.registerCommand({
|
|
37
|
+
name: 'hello',
|
|
38
|
+
description: 'Say hello',
|
|
39
|
+
run: () => 'hi',
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
In TypeScript (or with JSDoc `checkJs`), `api` is typed automatically once the
|
|
46
|
+
plugin's default export is annotated:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import type { HncodePlugin } from '@hncode/hncode-sdk';
|
|
50
|
+
|
|
51
|
+
const plugin: HncodePlugin = {
|
|
52
|
+
name: 'hello',
|
|
53
|
+
version: '1.0.0',
|
|
54
|
+
install(api) {
|
|
55
|
+
api.registerCommand({ name: 'hello', description: 'Say hello', run: () => 'hi' });
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
export default plugin;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Patching hncode's own code
|
|
62
|
+
|
|
63
|
+
`api.patch(target, handler)` wraps an exported function or class method in
|
|
64
|
+
hncode's `src/` without editing it (the equivalent of a Minecraft mixin).
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import { isPatchTarget } from '@hncode/hncode-sdk/targets';
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
name: 'audit', version: '1.0.0',
|
|
71
|
+
install(api) {
|
|
72
|
+
// `target` is typed as PatchTarget, so it completes.
|
|
73
|
+
api.patch('git.js#commit', {
|
|
74
|
+
before: (...args) => console.log('commit', args),
|
|
75
|
+
after: (result) => result,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
A handler may supply any of:
|
|
82
|
+
|
|
83
|
+
- `before(...args)` — runs before the call. Return an array to **replace** the args.
|
|
84
|
+
- `after(result, args)` — runs after. Return a non-`undefined` value to **replace** the result.
|
|
85
|
+
- `around(original, args, this)` — full control; its return value is the result.
|
|
86
|
+
|
|
87
|
+
Async functions are handled transparently.
|
|
88
|
+
|
|
89
|
+
## Logging
|
|
90
|
+
|
|
91
|
+
`api.log` is callable **and** carries the four methods, like `console`:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
api.log('plain call'); // -> an info notice
|
|
95
|
+
api.log.warn('careful'); // -> a warning notice
|
|
96
|
+
api.log.error('failed');
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
There are no separate `api.info` / `api.warn` / `api.error` members. Everything reaches
|
|
100
|
+
the chat and is mirrored to the terminal, so a plugin author watching stderr sees it too.
|
|
101
|
+
|
|
102
|
+
## Introspection
|
|
103
|
+
|
|
104
|
+
What the current load has registered, live (not a snapshot):
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
api.tools; // ToolSpec[] — including other plugins'
|
|
108
|
+
api.commands; // CommandSpec[]
|
|
109
|
+
api.hooks; // { [hookName]: fn[] }
|
|
110
|
+
api.config; // plugin-supplied defaults, before user overrides
|
|
111
|
+
api.plugins; // [{ name, version }] in install order
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Useful for avoiding a name collision before calling `registerTool` / `registerCommand`.
|
|
115
|
+
|
|
116
|
+
## Driving the UI
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
api.openFileTree('src'); // the /files browser; false if it could not open
|
|
120
|
+
api.closeFileTree();
|
|
121
|
+
|
|
122
|
+
api.themeNames; // ['auto','dark','light','nord','dracula','gruvbox','mono']
|
|
123
|
+
api.getTheme(); // the one in force
|
|
124
|
+
api.setTheme('gruvbox'); // false for an unknown name
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`openFileTree` returns whether the browser actually opened. An empty workspace or a
|
|
128
|
+
headless host gives `false`, so a plugin can tell rather than waiting on a panel that never
|
|
129
|
+
appeared.
|
|
130
|
+
|
|
131
|
+
## Subagents
|
|
132
|
+
|
|
133
|
+
The same controls the model has as tools, for a plugin:
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
for (const a of api.subagents()) {
|
|
137
|
+
// { id, runId, taskId, type, description, startedAt }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
api.messageSubagent(a.id, 'also check the tests'); // { ok, message }
|
|
141
|
+
api.interruptSubagent(a.id); // omit the id to stop all
|
|
142
|
+
api.closeSubagent(a.id); // stop AND drop from the list
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`api.subagents()` lists only what is running now — a finished agent is no longer
|
|
146
|
+
controllable. The live handles (`steer`, `interrupt`) are not exposed; the calls above are
|
|
147
|
+
the whole surface.
|
|
148
|
+
|
|
149
|
+
## Keybindings
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
api.isKeyBound('ctrl+t'); // true if a built-in, another plugin or the user took it
|
|
153
|
+
api.boundKeys; // every claimed token
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`registerKeybind` overwrites silently, so check first if you want to be polite. Any
|
|
157
|
+
spelling works — `'ctrl+t'` and `'c-t'` are the same key.
|
|
158
|
+
|
|
159
|
+
## Lifecycle hooks
|
|
160
|
+
|
|
161
|
+
`api.registerHook(name, fn)`. The names the host actually fires:
|
|
162
|
+
|
|
163
|
+
`onStartup`, `onShutdown`, `onTurnStart`, `onTurnEnd`, `onBeforeRequest`,
|
|
164
|
+
`onAfterRequest`, `onToolExecute`, `onToolResult`, `onNewMessage`, `onSessionSave`.
|
|
165
|
+
|
|
166
|
+
`HOOK_NAMES` holds the same list at runtime.
|
|
167
|
+
|
|
168
|
+
## Regenerating the target list
|
|
169
|
+
|
|
170
|
+
`targets.js` / `targets.d.ts` are generated from the main package's `src/`, so they
|
|
171
|
+
must be refreshed whenever the main package changes:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# from a checkout where hncode-sdk/ sits next to hncode's src/
|
|
175
|
+
node scripts/gen-targets.mjs # uses the parent directory
|
|
176
|
+
node scripts/gen-targets.mjs D:\hncode # or point at the root explicitly
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
This runs automatically on `prepublishOnly`.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
PolyForm Noncommercial 1.0.0 — same as hncode.
|