genshin-mods 0.0.0-stage → 4.0.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/.claude-plugin/plugin.json +12 -0
- package/LICENSE +201 -0
- package/README.md +78 -2
- package/hooks/hooks.json +1 -0
- package/package.json +40 -4
- package/src/models/ResinFigure.ts +5 -0
- package/src/models/TaskCall.ts +14 -0
- package/src/models/TaskTool.ts +5 -0
- package/src/models/WardAnswer.ts +8 -0
- package/src/register.ts +15 -0
- package/src/services/InitialState.ts +14 -0
- package/src/services/ModDescriptionMap.ts +12 -0
- package/src/services/band/getCommissionSummary.ts +21 -0
- package/src/services/band/registerBand.ts +215 -0
- package/src/services/commission/foldTaskCall.ts +26 -0
- package/src/services/commission/registerCommission.ts +48 -0
- package/src/services/constants.ts +26 -0
- package/src/services/registerLifecycle.ts +154 -0
- package/src/services/resin/getCacheRemainingMs.ts +4 -0
- package/src/services/resin/getResinFigures.ts +44 -0
- package/src/services/veil/registerVeil.ts +32 -0
- package/src/services/veil/veilText.ts +25 -0
- package/src/services/veil/veilValue.ts +11 -0
- package/src/services/ward/getCollidingRecord.ts +11 -0
- package/src/services/ward/getRecordsWithEdit.ts +15 -0
- package/src/services/ward/registerWard.ts +82 -0
- package/src/services/waypoints/parseWaypoints.ts +12 -0
- package/types/index.d.ts +43 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
|
+
"name": "genshin-mods",
|
|
4
|
+
"displayName": "Genshin Mods",
|
|
5
|
+
"description": "Five Claude Code mods under one band above the prompt: waypoints (the next steps, one press each), resin (cache, context, limits and cost, with warm, compact and a one-click handoff), veil (recording mode), commission (a goal's task list and clock) and ward (a question before editing a file another session just changed).",
|
|
6
|
+
"author": { "name": "Esposter", "url": "https://github.com/Esposter" },
|
|
7
|
+
"homepage": "https://esposter.com/docs/infra/claude-interface/genshin-mods",
|
|
8
|
+
"repository": "https://github.com/Esposter/Esposter",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"keywords": ["cache", "collision", "genshin", "handoff", "mods", "recording", "tasks"],
|
|
11
|
+
"types": "./types/index.d.ts"
|
|
12
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020-present Jimmy Chen
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
#
|
|
1
|
+
# genshin-mods
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![Apache-2.0 licensed][badge-license]][url-license]
|
|
4
|
+
[![NPM version][badge-npm-version]][url-npm]
|
|
5
|
+
[![NPM downloads][badge-npm-downloads]][url-npm]
|
|
6
|
+
[![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
|
|
7
|
+
|
|
8
|
+
A Claude Code plugin of five mods drawn as one band above the prompt, in the session character's colour: the next steps one press away, what the session is spending with a one-press handoff, recording mode, a goal's task list and clock, and a question before editing a file another session just changed.
|
|
9
|
+
|
|
10
|
+
- **Waypoints** — after each answered turn, up to three next steps the session suggests, each a button that sends it as the next prompt.
|
|
11
|
+
- **Resin** — the prompt cache's time left, the context window, the five-hour and weekly limits and the cost so far, with **Warm**, **Compact** and **Handoff**, and a toast before the cache goes cold.
|
|
12
|
+
- **Veil** — recording mode: emails, amounts, phone numbers and secrets shown as placeholders while the model still reads the real values.
|
|
13
|
+
- **Commission** — a goal meter over the session's task list: the goal, tasks done, the share complete and the minutes since it started.
|
|
14
|
+
- **Ward** — before an edit to a file another session changed in the last half hour, a question: proceed, move to a worktree, or cancel.
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
- 🚀 [Getting Started](#getting-started)
|
|
19
|
+
- 📖 [Documentation](#documentation)
|
|
20
|
+
- ⚖️ [License](#license)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## <a name="getting-started">🚀 Getting Started</a>
|
|
25
|
+
|
|
26
|
+
This repository is a Claude Code plugin marketplace named `esposter`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
claude plugin marketplace add Esposter/Esposter
|
|
30
|
+
claude plugin install genshin-mods@esposter
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A clone of this repository needs neither command: `.agents/settings.json` enables the plugin at project scope once you trust the repository. With [`genshin-persona`](https://github.com/Esposter/Esposter/tree/main/packages/genshin-persona) installed beside it, the band takes the session character's colour; without it, the game's interface gold.
|
|
34
|
+
|
|
35
|
+
Developing the plugin from a checkout loads the directory itself, with the installed copy disabled so only one of them answers:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
claude plugin disable genshin-mods@esposter
|
|
39
|
+
claude --plugin-dir packages/genshin-mods
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## <a name="documentation">📖 Documentation</a>
|
|
43
|
+
|
|
44
|
+
We highly recommend you take a look at the [documentation](https://esposter.com/docs/infra/claude-interface/genshin-mods) to level up.
|
|
45
|
+
|
|
46
|
+
### Command reference
|
|
47
|
+
|
|
48
|
+
Each mod is switched by its own slash command; bare, it flips, and the choice is kept across sessions:
|
|
49
|
+
|
|
50
|
+
| Command | What it does |
|
|
51
|
+
| :------------------------ | :------------------------------------------------------------------ |
|
|
52
|
+
| `/waypoints [on \| off]` | Suggests the next steps after each answered turn, or stops |
|
|
53
|
+
| `/resin [on \| off]` | Shows the cache, context, limits and cost row and its warning toast |
|
|
54
|
+
| `/veil [on \| off]` | Turns recording mode on or off; off by default |
|
|
55
|
+
| `/commission [on \| off]` | Shows the goal meter while a turn works through a task list |
|
|
56
|
+
| `/ward [on \| off]` | Asks before an edit to a file another session just changed |
|
|
57
|
+
|
|
58
|
+
With the band focused (a click or `ctrl+x tab`), `w`, `c` and `h` warm, compact and hand off, `1` to `3` send a waypoint and `g` opens or closes the whole task list.
|
|
59
|
+
|
|
60
|
+
### Commands
|
|
61
|
+
|
|
62
|
+
Run from `packages/genshin-mods/`:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm test # vitest watch mode (coverage is run from the repo root)
|
|
66
|
+
pnpm validate # claude plugin validate: the engine's own reading of the hooks module
|
|
67
|
+
pnpm lint:fix # auto-fix lint
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## <a name="license">⚖️ License</a>
|
|
71
|
+
|
|
72
|
+
This project is licensed under the [Apache-2.0 license](https://github.com/Esposter/Esposter/blob/main/LICENSE).
|
|
73
|
+
|
|
74
|
+
[badge-license]: https://img.shields.io/github/license/Esposter/Esposter.svg?color=blue
|
|
75
|
+
[url-license]: https://github.com/Esposter/Esposter/blob/main/LICENSE
|
|
76
|
+
[badge-npm-version]: https://img.shields.io/npm/v/genshin-mods/latest?color=brightgreen
|
|
77
|
+
[url-npm]: https://www.npmjs.com/package/genshin-mods/v/latest
|
|
78
|
+
[badge-npm-unpacked-size]: https://img.shields.io/npm/unpacked-size/genshin-mods/latest?label=npm
|
|
79
|
+
[badge-npm-downloads]: https://img.shields.io/npm/dm/genshin-mods.svg
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["../src/register.ts"] }
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genshin-mods",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "A Claude Code plugin of five mods under one band above the prompt: the next steps, the cache and usage with a one-click handoff, recording mode, a goal's task list and a question before editing a file another session just changed.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"claude-code-plugin",
|
|
8
|
+
"genshin",
|
|
9
|
+
"mods"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://esposter.com/docs/infra/claude-interface/genshin-mods",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Esposter/Esposter/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"author": "Jimmy Chen",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/Esposter/Esposter.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
".claude-plugin",
|
|
23
|
+
"hooks",
|
|
24
|
+
"src",
|
|
25
|
+
"types",
|
|
26
|
+
"!**/*.test.ts",
|
|
27
|
+
"!.claude-plugin/types"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"format": "oxfmt",
|
|
35
|
+
"format:check": "oxfmt --check",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"lint:fix": "eslint --fix .",
|
|
38
|
+
"test": "vitest",
|
|
39
|
+
"validate": "claude plugin validate ."
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "7667bc8c9a2b4e9dcacd6b845ee8cc9951250ae7"
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CommissionTask } from "../../types";
|
|
2
|
+
import type { TaskTool } from "./TaskTool";
|
|
3
|
+
|
|
4
|
+
// One task tool call with what its result says, in the shapes the engine's own tools declare
|
|
5
|
+
export type TaskCall =
|
|
6
|
+
| {
|
|
7
|
+
id: string;
|
|
8
|
+
// oxlint-disable-next-line literal-union/no-string-literal-union -- The engine's own TaskUpdate statuses
|
|
9
|
+
status?: "deleted" | CommissionTask["status"];
|
|
10
|
+
subject?: string;
|
|
11
|
+
tool: TaskTool.TaskUpdate;
|
|
12
|
+
}
|
|
13
|
+
| { id: string; subject: string; tool: TaskTool.TaskCreate }
|
|
14
|
+
| { todos: { content: string; status: CommissionTask["status"] }[]; tool: TaskTool.TodoWrite };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export enum WardAnswer {
|
|
2
|
+
Cancel = "Cancel",
|
|
3
|
+
Proceed = "Proceed",
|
|
4
|
+
Worktree = "Move to a worktree",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// In the order the question offers them
|
|
8
|
+
export const WardAnswers: readonly WardAnswer[] = [WardAnswer.Proceed, WardAnswer.Worktree, WardAnswer.Cancel];
|
package/src/register.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Register } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { registerBand } from "./services/band/registerBand";
|
|
4
|
+
import { registerCommission } from "./services/commission/registerCommission";
|
|
5
|
+
import { registerLifecycle } from "./services/registerLifecycle";
|
|
6
|
+
import { registerVeil } from "./services/veil/registerVeil";
|
|
7
|
+
import { registerWard } from "./services/ward/registerWard";
|
|
8
|
+
|
|
9
|
+
export const register: Register = (on) => {
|
|
10
|
+
registerBand(on);
|
|
11
|
+
registerCommission(on);
|
|
12
|
+
registerLifecycle(on);
|
|
13
|
+
registerVeil(on);
|
|
14
|
+
registerWard(on);
|
|
15
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PluginState } from "claude-code";
|
|
2
|
+
|
|
3
|
+
// Every state value's initial, read by each file's atoms: the engine traces a state reference only to an atom made in
|
|
4
|
+
// The file that uses it, so each file makes its own and this is the one place their initials are written
|
|
5
|
+
export const InitialState: PluginState["genshin-mods"] = {
|
|
6
|
+
commission: { goal: "", openedAt: 0, tasks: [] },
|
|
7
|
+
enabledMods: { commission: true, resin: true, veil: false, ward: true, waypoints: true },
|
|
8
|
+
isCommissionExpanded: false,
|
|
9
|
+
isHandingOff: false,
|
|
10
|
+
lastCacheRequestAt: 0,
|
|
11
|
+
lastPrompt: "",
|
|
12
|
+
now: 0,
|
|
13
|
+
waypoints: [],
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EnabledMods } from "../../types";
|
|
2
|
+
|
|
3
|
+
// Each mod's command, `/<name> [on|off]`, as the menu describes it
|
|
4
|
+
export const ModDescriptionMap: Record<keyof EnabledMods, string> = {
|
|
5
|
+
commission: "Show a goal's task list, how far it is and how long it has run.",
|
|
6
|
+
resin: "Show the cache, context, limits and cost, with warm, compact and handoff.",
|
|
7
|
+
veil: "Recording mode: show emails, amounts, phone numbers and secrets as placeholders.",
|
|
8
|
+
ward: "Ask before editing a file another session changed in the last half hour.",
|
|
9
|
+
waypoints: "Suggest the next steps after each answer, one press each.",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const ModNames = Object.keys(ModDescriptionMap) as (keyof EnabledMods)[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Commission } from "../../../types";
|
|
2
|
+
|
|
3
|
+
import { MINUTE_FORMATTER } from "../constants";
|
|
4
|
+
|
|
5
|
+
const PERCENT_FORMATTER = new Intl.NumberFormat("en", { style: "percent" });
|
|
6
|
+
|
|
7
|
+
// `goal · 3 of 4 · 75% · 12m`, the clock counting whole minutes from the commission's opening
|
|
8
|
+
export const getCommissionSummary = ({ goal, openedAt, tasks }: Commission, now: number): string => {
|
|
9
|
+
const done = tasks.filter(({ status }) => status === "completed").length;
|
|
10
|
+
const elapsedMinutes = Math.floor(
|
|
11
|
+
Temporal.Duration.from({ milliseconds: Math.max(0, now - openedAt) }).total("minutes"),
|
|
12
|
+
);
|
|
13
|
+
return [
|
|
14
|
+
goal,
|
|
15
|
+
`${done} of ${tasks.length}`,
|
|
16
|
+
PERCENT_FORMATTER.format(done / tasks.length),
|
|
17
|
+
MINUTE_FORMATTER.format(elapsedMinutes),
|
|
18
|
+
]
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.join(" · ");
|
|
21
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { EngineInterface, On, RenderElement, RenderInput } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { atom, read, update } from "claude-code";
|
|
4
|
+
|
|
5
|
+
import type { EnabledMods } from "../../../types";
|
|
6
|
+
|
|
7
|
+
import { ACCENT_COLOR, HANDOFF_QUESTION, MAX_SHOWN_TASKS, WARM_QUESTION } from "../constants";
|
|
8
|
+
import { InitialState } from "../InitialState";
|
|
9
|
+
import { getResinFigures } from "../resin/getResinFigures";
|
|
10
|
+
import { getCommissionSummary } from "./getCommissionSummary";
|
|
11
|
+
|
|
12
|
+
// The plugin's one band, a row per mod with something to say. `$` is followed only into functions in the file that
|
|
13
|
+
// Hooked it, so each row and each button's action lives here beside the hook
|
|
14
|
+
const commissionAtom = atom({ key: "commission", plugin: "genshin-mods" } as const, InitialState.commission);
|
|
15
|
+
const enabledModsAtom = atom({ key: "enabledMods", plugin: "genshin-mods" } as const, InitialState.enabledMods);
|
|
16
|
+
const isCommissionExpandedAtom = atom(
|
|
17
|
+
{ key: "isCommissionExpanded", plugin: "genshin-mods" } as const,
|
|
18
|
+
InitialState.isCommissionExpanded,
|
|
19
|
+
);
|
|
20
|
+
const isHandingOffAtom = atom({ key: "isHandingOff", plugin: "genshin-mods" } as const, InitialState.isHandingOff);
|
|
21
|
+
const lastCacheRequestAtAtom = atom(
|
|
22
|
+
{ key: "lastCacheRequestAt", plugin: "genshin-mods" } as const,
|
|
23
|
+
InitialState.lastCacheRequestAt,
|
|
24
|
+
);
|
|
25
|
+
const nowAtom = atom({ key: "now", plugin: "genshin-mods" } as const, InitialState.now);
|
|
26
|
+
const waypointsAtom = atom({ key: "waypoints", plugin: "genshin-mods" } as const, InitialState.waypoints);
|
|
27
|
+
|
|
28
|
+
// The engine's press slot takes no promise; every action here resolves each of its outcomes itself
|
|
29
|
+
const press = (action: () => Promise<unknown>) => () => {
|
|
30
|
+
// oxlint-disable-next-line typescript/no-floating-promises -- The press slot is the engine's and returns nothing
|
|
31
|
+
action();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const StatusMarkMap = { completed: "✓", in_progress: "▸", pending: "·" } as const;
|
|
35
|
+
|
|
36
|
+
// A fork re-sends the conversation's prefix, which renews the cache from the moment it is sent, and adds no row to the
|
|
37
|
+
// Transcript
|
|
38
|
+
const warmCache = async ($: EngineInterface) => {
|
|
39
|
+
const requestedAt = await $.clock.now();
|
|
40
|
+
const answer = await $.model.fork({ prompt: WARM_QUESTION });
|
|
41
|
+
if (!answer.isAnswered) {
|
|
42
|
+
$.ui.toast(`The cache was not warmed: ${answer.reason}.`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await update($, lastCacheRequestAtAtom, () => requestedAt);
|
|
47
|
+
await update($, nowAtom, () => requestedAt);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// The whole relay in one press: the clear waits for the handoff text, so a fork that fails clears nothing
|
|
51
|
+
const relay = async ($: EngineInterface) => {
|
|
52
|
+
const answer = await $.model.fork({ prompt: HANDOFF_QUESTION });
|
|
53
|
+
if (answer.isAnswered && answer.text.trim()) {
|
|
54
|
+
await $.command.run({ command: "clear" });
|
|
55
|
+
await $.prompt.submit({ text: answer.text });
|
|
56
|
+
} else $.ui.toast(`The handoff was not written: ${answer.isAnswered ? "it came back empty" : answer.reason}.`);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// The relay is settled rather than awaited, so a clear or submit that rejects still brings the buttons back
|
|
60
|
+
const handOff = async ($: EngineInterface) => {
|
|
61
|
+
await update($, isHandingOffAtom, () => true);
|
|
62
|
+
const [outcome] = await Promise.allSettled([relay($)]);
|
|
63
|
+
await update($, isHandingOffAtom, () => false);
|
|
64
|
+
if (outcome.status === "rejected") $.ui.toast(`The handoff failed: ${String(outcome.reason)}.`);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// The session character's colour, which the persona publishes, else the game's interface gold
|
|
68
|
+
const readAccent = async ($: EngineInterface) =>
|
|
69
|
+
(await read($, { key: "character", plugin: "genshin-persona" } as const))?.color || ACCENT_COLOR;
|
|
70
|
+
|
|
71
|
+
const drawResinRow = async (
|
|
72
|
+
$: EngineInterface,
|
|
73
|
+
e: RenderInput<"AbovePrompt">,
|
|
74
|
+
enabledMods: EnabledMods,
|
|
75
|
+
accent: string,
|
|
76
|
+
): Promise<RenderElement | undefined> => {
|
|
77
|
+
const lastCacheRequestAt = await read($, lastCacheRequestAtAtom);
|
|
78
|
+
if (lastCacheRequestAt === 0 || !enabledMods.resin) return undefined;
|
|
79
|
+
|
|
80
|
+
const figures = getResinFigures(await $.session.usage(), lastCacheRequestAt, await read($, nowAtom));
|
|
81
|
+
const isHandingOff = await read($, isHandingOffAtom);
|
|
82
|
+
const { Box, Button, Text } = $.ui.resolve(e);
|
|
83
|
+
return Box({
|
|
84
|
+
children: [
|
|
85
|
+
Text({ bold: true, children: "Resin ", color: accent }),
|
|
86
|
+
...figures.map(({ isWarning, label, text }) =>
|
|
87
|
+
Text({ children: `${label} ${text} `, color: isWarning ? "yellow" : undefined, dimColor: !isWarning }),
|
|
88
|
+
),
|
|
89
|
+
isHandingOff
|
|
90
|
+
? Text({ children: "writing the handoff…", dimColor: true })
|
|
91
|
+
: Box({
|
|
92
|
+
children: [
|
|
93
|
+
Button({ hotkey: "w", key: "resin-warm", label: "Warm", onPress: press(() => warmCache($)) }),
|
|
94
|
+
Button({
|
|
95
|
+
hotkey: "c",
|
|
96
|
+
key: "resin-compact",
|
|
97
|
+
label: "Compact",
|
|
98
|
+
onPress: press(() => $.session.compact()),
|
|
99
|
+
}),
|
|
100
|
+
Button({
|
|
101
|
+
hotkey: "h",
|
|
102
|
+
key: "resin-handoff",
|
|
103
|
+
label: "Handoff",
|
|
104
|
+
onPress: press(() => handOff($)),
|
|
105
|
+
variant: "primary",
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
flexDirection: "row",
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
flexDirection: "row",
|
|
112
|
+
flexWrap: "wrap",
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const drawCommissionRow = async (
|
|
117
|
+
$: EngineInterface,
|
|
118
|
+
e: RenderInput<"AbovePrompt">,
|
|
119
|
+
enabledMods: EnabledMods,
|
|
120
|
+
accent: string,
|
|
121
|
+
): Promise<RenderElement | undefined> => {
|
|
122
|
+
const commission = await read($, commissionAtom);
|
|
123
|
+
if (commission.tasks.length === 0 || !enabledMods.commission) return undefined;
|
|
124
|
+
|
|
125
|
+
const isExpanded = await read($, isCommissionExpandedAtom);
|
|
126
|
+
const shownTasks = isExpanded
|
|
127
|
+
? commission.tasks.slice(0, MAX_SHOWN_TASKS)
|
|
128
|
+
: commission.tasks.filter(({ status }) => status === "in_progress");
|
|
129
|
+
const { Box, Button, Text } = $.ui.resolve(e);
|
|
130
|
+
return Box({
|
|
131
|
+
children: [
|
|
132
|
+
Box({
|
|
133
|
+
children: [
|
|
134
|
+
Text({ bold: true, children: "Commission ", color: accent }),
|
|
135
|
+
Text({ children: `${getCommissionSummary(commission, await read($, nowAtom))} `, wrap: "truncate-end" }),
|
|
136
|
+
Button({
|
|
137
|
+
hotkey: "g",
|
|
138
|
+
key: "commission-expand",
|
|
139
|
+
label: isExpanded ? "Fewer" : "All tasks",
|
|
140
|
+
onPress: press(() => update($, isCommissionExpandedAtom, (value) => !value)),
|
|
141
|
+
plain: true,
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
flexDirection: "row",
|
|
145
|
+
}),
|
|
146
|
+
...shownTasks.map(({ status, subject }) =>
|
|
147
|
+
Text({
|
|
148
|
+
children: ` ${StatusMarkMap[status]} ${subject}`,
|
|
149
|
+
dimColor: status !== "in_progress",
|
|
150
|
+
wrap: "truncate-end",
|
|
151
|
+
}),
|
|
152
|
+
),
|
|
153
|
+
],
|
|
154
|
+
flexDirection: "column",
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const drawWaypointsRow = async (
|
|
159
|
+
$: EngineInterface,
|
|
160
|
+
e: RenderInput<"AbovePrompt">,
|
|
161
|
+
enabledMods: EnabledMods,
|
|
162
|
+
accent: string,
|
|
163
|
+
): Promise<RenderElement | undefined> => {
|
|
164
|
+
const waypoints = await read($, waypointsAtom);
|
|
165
|
+
if (waypoints.length === 0 || e.props.isWorking || !enabledMods.waypoints) return undefined;
|
|
166
|
+
|
|
167
|
+
const { Box, Button, Text } = $.ui.resolve(e);
|
|
168
|
+
return Box({
|
|
169
|
+
children: [
|
|
170
|
+
Text({ bold: true, children: "Waypoints", color: accent }),
|
|
171
|
+
...waypoints.map((waypoint, index) =>
|
|
172
|
+
Button({
|
|
173
|
+
hotkey: `${index + 1}`,
|
|
174
|
+
key: `waypoint-${index}`,
|
|
175
|
+
label: waypoint,
|
|
176
|
+
onPress: press(() => $.prompt.submit({ text: waypoint })),
|
|
177
|
+
plain: true,
|
|
178
|
+
}),
|
|
179
|
+
),
|
|
180
|
+
Button({
|
|
181
|
+
key: "waypoints-dismiss",
|
|
182
|
+
label: "Dismiss",
|
|
183
|
+
onPress: press(() => update($, waypointsAtom, () => InitialState.waypoints)),
|
|
184
|
+
plain: true,
|
|
185
|
+
role: "dismiss",
|
|
186
|
+
}),
|
|
187
|
+
],
|
|
188
|
+
flexDirection: "column",
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// The veil's marker first, so a recording never runs with it off unnoticed, and the engine's own band whenever no
|
|
193
|
+
// Mod has anything to say
|
|
194
|
+
export const registerBand = (on: On): void => {
|
|
195
|
+
on("ui.render", { component: "AbovePrompt" }, async ($, e, next) => {
|
|
196
|
+
if (e.props.hasSurvey) return next(e);
|
|
197
|
+
|
|
198
|
+
const enabledMods = await read($, enabledModsAtom);
|
|
199
|
+
const accent = await readAccent($);
|
|
200
|
+
const rows = (
|
|
201
|
+
await Promise.all([
|
|
202
|
+
drawResinRow($, e, enabledMods, accent),
|
|
203
|
+
drawCommissionRow($, e, enabledMods, accent),
|
|
204
|
+
drawWaypointsRow($, e, enabledMods, accent),
|
|
205
|
+
])
|
|
206
|
+
).filter((row) => row !== undefined);
|
|
207
|
+
if (rows.length === 0 && !enabledMods.veil) return next(e);
|
|
208
|
+
|
|
209
|
+
const { Box, Text } = $.ui.resolve(e);
|
|
210
|
+
const marker = enabledMods.veil
|
|
211
|
+
? [Text({ bold: true, children: "● Veil on: values are hidden on screen", color: "red" })]
|
|
212
|
+
: [];
|
|
213
|
+
return Box({ children: [...marker, ...rows], flexDirection: "column" });
|
|
214
|
+
});
|
|
215
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CommissionTask } from "../../../types";
|
|
2
|
+
import type { TaskCall } from "../../models/TaskCall";
|
|
3
|
+
|
|
4
|
+
import { TaskTool } from "../../models/TaskTool";
|
|
5
|
+
|
|
6
|
+
const DELETED_STATUS = "deleted";
|
|
7
|
+
|
|
8
|
+
export const foldTaskCall = (tasks: CommissionTask[], call: TaskCall): CommissionTask[] => {
|
|
9
|
+
switch (call.tool) {
|
|
10
|
+
case TaskTool.TaskCreate:
|
|
11
|
+
return [...tasks, { id: call.id, status: "pending", subject: call.subject }];
|
|
12
|
+
case TaskTool.TaskUpdate: {
|
|
13
|
+
const { id, status, subject } = call;
|
|
14
|
+
if (status === DELETED_STATUS) return tasks.filter((task) => task.id !== id);
|
|
15
|
+
else
|
|
16
|
+
return tasks.map((task) =>
|
|
17
|
+
task.id === id ? { ...task, status: status ?? task.status, subject: subject ?? task.subject } : task,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
// A todo list carries no ids and is written whole each time, so its place in the list is its id
|
|
21
|
+
case TaskTool.TodoWrite:
|
|
22
|
+
return call.todos.map(({ content, status }, index) => ({ id: `${index}`, status, subject: content }));
|
|
23
|
+
default:
|
|
24
|
+
return tasks;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EngineInterface, On } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { atom, read, update } from "claude-code";
|
|
4
|
+
|
|
5
|
+
import type { TaskCall } from "../../models/TaskCall";
|
|
6
|
+
|
|
7
|
+
import { TaskTool } from "../../models/TaskTool";
|
|
8
|
+
import { InitialState } from "../InitialState";
|
|
9
|
+
import { foldTaskCall } from "./foldTaskCall";
|
|
10
|
+
|
|
11
|
+
const commissionAtom = atom({ key: "commission", plugin: "genshin-mods" } as const, InitialState.commission);
|
|
12
|
+
const enabledModsAtom = atom({ key: "enabledMods", plugin: "genshin-mods" } as const, InitialState.enabledMods);
|
|
13
|
+
const lastPromptAtom = atom({ key: "lastPrompt", plugin: "genshin-mods" } as const, InitialState.lastPrompt);
|
|
14
|
+
|
|
15
|
+
// A task tool's call folded in once the tool has answered, opening the commission on its first task with the goal
|
|
16
|
+
// Read off the prompt that started the turn
|
|
17
|
+
const fold = async ($: EngineInterface, call: TaskCall) => {
|
|
18
|
+
if (!(await read($, enabledModsAtom)).commission) return;
|
|
19
|
+
const now = await $.clock.now();
|
|
20
|
+
const lastPrompt = await read($, lastPromptAtom);
|
|
21
|
+
await update($, commissionAtom, (commission) => ({
|
|
22
|
+
goal: commission.goal || (lastPrompt.split("\n").find(Boolean) ?? "").trim(),
|
|
23
|
+
openedAt: commission.openedAt || now,
|
|
24
|
+
tasks: foldTaskCall(commission.tasks, call),
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const registerCommission = (on: On): void => {
|
|
29
|
+
on("tool.call", { tool: "TaskCreate" }, async ($, e, next) => {
|
|
30
|
+
const result = await next(e);
|
|
31
|
+
if (!result.deny && !result.isError && result.result)
|
|
32
|
+
await fold($, { id: result.result.task.id, subject: e.subject, tool: TaskTool.TaskCreate });
|
|
33
|
+
return result;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
on("tool.call", { tool: "TaskUpdate" }, async ($, e, next) => {
|
|
37
|
+
const result = await next(e);
|
|
38
|
+
if (!result.deny && !result.isError)
|
|
39
|
+
await fold($, { id: e.taskId, status: e.status, subject: e.subject, tool: TaskTool.TaskUpdate });
|
|
40
|
+
return result;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
on("tool.call", { tool: "TodoWrite" }, async ($, e, next) => {
|
|
44
|
+
const result = await next(e);
|
|
45
|
+
if (!result.deny && !result.isError) await fold($, { todos: e.todos, tool: TaskTool.TodoWrite });
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The game's own interface gold, the accent wherever the persona publishes no character
|
|
2
|
+
export const ACCENT_COLOR = "#d3bc8e";
|
|
3
|
+
// The prompt cache's lifetime, which the engine chooses and does not report: an hour on a subscription
|
|
4
|
+
export const CACHE_LIFETIME_MS: number = Temporal.Duration.from({ hours: 1 }).total("milliseconds");
|
|
5
|
+
export const CACHE_LOW_MS: number = Temporal.Duration.from({ minutes: 10 }).total("milliseconds");
|
|
6
|
+
export const CACHE_WARNING_MS: number = Temporal.Duration.from({ minutes: 5 }).total("milliseconds");
|
|
7
|
+
export const CLOCK_TICK_MS: number = Temporal.Duration.from({ minutes: 1 }).total("milliseconds");
|
|
8
|
+
export const USAGE_WARNING_PERCENTAGE = 80;
|
|
9
|
+
export const MAX_WAYPOINTS = 3;
|
|
10
|
+
export const MAX_SHOWN_TASKS = 8;
|
|
11
|
+
// Whole minutes as the band writes them, `12m`
|
|
12
|
+
export const MINUTE_FORMATTER: Intl.NumberFormat = new Intl.NumberFormat("en", {
|
|
13
|
+
style: "unit",
|
|
14
|
+
unit: "minute",
|
|
15
|
+
unitDisplay: "narrow",
|
|
16
|
+
});
|
|
17
|
+
export const WARD_WINDOW_MS: number = Temporal.Duration.from({ minutes: 30 }).total("milliseconds");
|
|
18
|
+
export const NO_WAYPOINTS_ANSWER = "NONE";
|
|
19
|
+
// oxlint-disable-next-line typescript/no-inferrable-types -- `isolatedDeclarations` demands the annotation this template literal would otherwise infer
|
|
20
|
+
export const WAYPOINTS_QUESTION: string = `Leave the conversation as it is and answer one side question. List the next steps worth taking from here, at most ${MAX_WAYPOINTS}, most useful first: each one short imperative line the person could send you as their next prompt, with no numbering, no markup and nothing else. When the work is finished or waits on the person, answer ${NO_WAYPOINTS_ANSWER}.`;
|
|
21
|
+
export const WARM_QUESTION = "Answer with the one word OK.";
|
|
22
|
+
export const HANDOFF_QUESTION =
|
|
23
|
+
"Write a handoff of this session for a fresh conversation that will carry on the work with no other context. Write it as the prompt that conversation starts with: the goal, what is done, what is next in order, the files, commands and decisions that matter with their reasons, and any open question. Be complete but compact, plain markdown, nothing before or after it.";
|
|
24
|
+
export const VEIL_SECTION_ID = "genshin-mods-veil";
|
|
25
|
+
export const VEIL_SYSTEM_SECTION =
|
|
26
|
+
"Recording mode is on: the screen is being recorded or shared. Never write an email address, a phone number, a money amount, an API key, a token or a password in a reply; write a placeholder such as [email], [phone], [amount] or [secret] instead, even when asked for the value. Tool calls still use the real values.";
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { EngineInterface, On } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { atom, read, update } from "claude-code";
|
|
4
|
+
|
|
5
|
+
import type { EnabledMods } from "../../types";
|
|
6
|
+
|
|
7
|
+
import { CACHE_WARNING_MS, CLOCK_TICK_MS, VEIL_SECTION_ID, VEIL_SYSTEM_SECTION, WAYPOINTS_QUESTION } from "./constants";
|
|
8
|
+
import { InitialState } from "./InitialState";
|
|
9
|
+
import { ModDescriptionMap, ModNames } from "./ModDescriptionMap";
|
|
10
|
+
import { getCacheRemainingMs } from "./resin/getCacheRemainingMs";
|
|
11
|
+
import { parseWaypoints } from "./waypoints/parseWaypoints";
|
|
12
|
+
|
|
13
|
+
const commissionAtom = atom({ key: "commission", plugin: "genshin-mods" } as const, InitialState.commission);
|
|
14
|
+
const enabledModsAtom = atom({ key: "enabledMods", plugin: "genshin-mods" } as const, InitialState.enabledMods);
|
|
15
|
+
const isCommissionExpandedAtom = atom(
|
|
16
|
+
{ key: "isCommissionExpanded", plugin: "genshin-mods" } as const,
|
|
17
|
+
InitialState.isCommissionExpanded,
|
|
18
|
+
);
|
|
19
|
+
const lastPromptAtom = atom({ key: "lastPrompt", plugin: "genshin-mods" } as const, InitialState.lastPrompt);
|
|
20
|
+
const lastCacheRequestAtAtom = atom(
|
|
21
|
+
{ key: "lastCacheRequestAt", plugin: "genshin-mods" } as const,
|
|
22
|
+
InitialState.lastCacheRequestAt,
|
|
23
|
+
);
|
|
24
|
+
const nowAtom = atom({ key: "now", plugin: "genshin-mods" } as const, InitialState.now);
|
|
25
|
+
const waypointsAtom = atom({ key: "waypoints", plugin: "genshin-mods" } as const, InitialState.waypoints);
|
|
26
|
+
|
|
27
|
+
// The events a plugin may hook once with no matcher, each hooked here for every mod, with the commands that switch
|
|
28
|
+
// The mods. Neither variable is drawn: the expiry already warned about, so each warns once, and whether a turn is
|
|
29
|
+
// Renewing the cache itself, when no warning is owed
|
|
30
|
+
let warnedLastCacheRequestAt = 0;
|
|
31
|
+
let isTurnRunning = false;
|
|
32
|
+
|
|
33
|
+
const tick = async ($: EngineInterface) => {
|
|
34
|
+
const now = await $.clock.now();
|
|
35
|
+
await update($, nowAtom, () => now);
|
|
36
|
+
const lastCacheRequestAt = await read($, lastCacheRequestAtAtom);
|
|
37
|
+
const remainingMs = getCacheRemainingMs(lastCacheRequestAt, now);
|
|
38
|
+
const isWarningDue = lastCacheRequestAt > 0 && remainingMs > 0 && remainingMs <= CACHE_WARNING_MS;
|
|
39
|
+
if (
|
|
40
|
+
!isWarningDue ||
|
|
41
|
+
isTurnRunning ||
|
|
42
|
+
warnedLastCacheRequestAt === lastCacheRequestAt ||
|
|
43
|
+
!(await read($, enabledModsAtom)).resin
|
|
44
|
+
)
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
warnedLastCacheRequestAt = lastCacheRequestAt;
|
|
48
|
+
$.ui.toast("The prompt cache goes cold in five minutes: warm it, compact or hand off from the band.");
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const suggestWaypoints = async ($: EngineInterface) => {
|
|
52
|
+
const answer = await $.model.fork({ prompt: WAYPOINTS_QUESTION });
|
|
53
|
+
if (answer.isAnswered) await update($, waypointsAtom, () => parseWaypoints(answer.text));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const closeCommission = async ($: EngineInterface) => {
|
|
57
|
+
await update($, commissionAtom, () => InitialState.commission);
|
|
58
|
+
await update($, isCommissionExpandedAtom, () => InitialState.isCommissionExpanded);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const registerLifecycle = (on: On): void => {
|
|
62
|
+
// The bare command flips a mod and an argument sets it, kept in the store so it holds for every later session
|
|
63
|
+
for (const name of ModNames)
|
|
64
|
+
on("command.run", { command: name }, async ($, e) => {
|
|
65
|
+
const argument = e.args.trim().toLowerCase();
|
|
66
|
+
const enabledMods = await update($, enabledModsAtom, (value) => ({
|
|
67
|
+
...value,
|
|
68
|
+
[name]: argument ? argument === "on" : !value[name],
|
|
69
|
+
}));
|
|
70
|
+
await $.store.set(enabledModsAtom.ref.key, enabledMods);
|
|
71
|
+
return { text: `${name} is ${enabledMods[name] ? "on" : "off"}.` };
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
on("session.start", async ($, e, next) => {
|
|
75
|
+
const stored = (await $.store.get(enabledModsAtom.ref.key)) as Partial<EnabledMods> | undefined;
|
|
76
|
+
await update($, enabledModsAtom, (value) => ({ ...value, ...stored }));
|
|
77
|
+
await Promise.all(
|
|
78
|
+
ModNames.map((name) =>
|
|
79
|
+
$.command.register({ argumentHint: "[on|off]", description: ModDescriptionMap[name], name }),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
// oxlint-disable-next-line unicorn/no-array-method-this-argument -- The engine's clock, not Array.prototype.every
|
|
83
|
+
$.clock.every(CLOCK_TICK_MS, () => {
|
|
84
|
+
// oxlint-disable-next-line typescript/no-floating-promises -- The engine's timer slot takes no promise, and every call in the tick resolves
|
|
85
|
+
tick($);
|
|
86
|
+
});
|
|
87
|
+
return next(e);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// A `/clear` or a resume carries on in this process under another conversation, with no `session.start` for it, so
|
|
91
|
+
// Nothing the old one showed is kept
|
|
92
|
+
on("session.end", async ($, e, next) => {
|
|
93
|
+
if (e.reason === "clear" || e.reason === "resume") {
|
|
94
|
+
await update($, lastCacheRequestAtAtom, () => InitialState.lastCacheRequestAt);
|
|
95
|
+
await update($, waypointsAtom, () => InitialState.waypoints);
|
|
96
|
+
await closeCommission($);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return next(e);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// The prompt is kept as the goal of a commission this turn may open, and a commission whose every task is done has
|
|
103
|
+
// Shown its finished row since the last turn ended, so it closes as the person moves on
|
|
104
|
+
on("prompt.submit", async ($, e, next) => {
|
|
105
|
+
await update($, waypointsAtom, () => InitialState.waypoints);
|
|
106
|
+
await update($, lastPromptAtom, () => e.text);
|
|
107
|
+
const { tasks } = await read($, commissionAtom);
|
|
108
|
+
if (tasks.length > 0 && tasks.every(({ status }) => status === "completed")) await closeCommission($);
|
|
109
|
+
return next(e);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// While the veil is on, the model is told to write placeholders too, so a reply never holds a value to hide
|
|
113
|
+
on("prompt.compose", async ($, e, next) => {
|
|
114
|
+
const result = await next(e);
|
|
115
|
+
if ((await read($, enabledModsAtom)).veil)
|
|
116
|
+
return { sections: [...result.sections, { id: VEIL_SECTION_ID, scope: "session", text: VEIL_SYSTEM_SECTION }] };
|
|
117
|
+
else return result;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
on("turn.start", (_$, e, next) => {
|
|
121
|
+
isTurnRunning = true;
|
|
122
|
+
return next(e);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// The cache's lifetime runs from the request that read or wrote it, so each of the main conversation's requests
|
|
126
|
+
// Restarts the countdown as it is sent, not as its reply ends
|
|
127
|
+
on("turn.step", async function* ($, e, next) {
|
|
128
|
+
if (e.agentId === undefined) {
|
|
129
|
+
const now = await $.clock.now();
|
|
130
|
+
await update($, lastCacheRequestAtAtom, () => now);
|
|
131
|
+
await update($, nowAtom, () => now);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return yield* next(e);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// An answer of the main conversation asks for waypoints off the turn's own dispatch, so the fork never holds the
|
|
138
|
+
// Turn's end or the next prompt behind it
|
|
139
|
+
on("turn.complete", async ($, e, next) => {
|
|
140
|
+
const result = await next(e);
|
|
141
|
+
if (e.agentId !== undefined) return result;
|
|
142
|
+
|
|
143
|
+
isTurnRunning = false;
|
|
144
|
+
|
|
145
|
+
const now = await $.clock.now();
|
|
146
|
+
await update($, nowAtom, () => now);
|
|
147
|
+
if (e.reason === "answer" && (await read($, enabledModsAtom)).waypoints)
|
|
148
|
+
$.clock.after(0, () => {
|
|
149
|
+
// oxlint-disable-next-line typescript/no-floating-promises -- The engine's timer slot takes no promise, and a fork resolves every outcome rather than rejecting
|
|
150
|
+
suggestWaypoints($);
|
|
151
|
+
});
|
|
152
|
+
return result;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SessionUsage } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import type { ResinFigure } from "../../models/ResinFigure";
|
|
4
|
+
|
|
5
|
+
import { CACHE_LOW_MS, MINUTE_FORMATTER, USAGE_WARNING_PERCENTAGE } from "../constants";
|
|
6
|
+
import { getCacheRemainingMs } from "./getCacheRemainingMs";
|
|
7
|
+
|
|
8
|
+
const TOKEN_FORMATTER = new Intl.NumberFormat("en", { maximumFractionDigits: 1, notation: "compact" });
|
|
9
|
+
const USD_CURRENCY_FORMATTER = new Intl.NumberFormat("en", { currency: "USD", style: "currency" });
|
|
10
|
+
const RateLimitLabelMap: Record<string, string> = { five_hour: "5h", seven_day: "7d" };
|
|
11
|
+
|
|
12
|
+
// The row's figures in the order they are read: the cache only once a request has started its clock, and each other
|
|
13
|
+
// Figure only once the engine has a reading, since a zero it never measured would read as a fact
|
|
14
|
+
export const getResinFigures = (
|
|
15
|
+
{ context, cost, rateLimits }: Pick<SessionUsage, "context" | "cost" | "rateLimits">,
|
|
16
|
+
lastCacheRequestAt: number,
|
|
17
|
+
now: number,
|
|
18
|
+
): ResinFigure[] => {
|
|
19
|
+
const figures: ResinFigure[] = [];
|
|
20
|
+
if (lastCacheRequestAt > 0) {
|
|
21
|
+
const remainingMs = getCacheRemainingMs(lastCacheRequestAt, now);
|
|
22
|
+
const remainingMinutes = Math.ceil(Temporal.Duration.from({ milliseconds: remainingMs }).total("minutes"));
|
|
23
|
+
const remaining = remainingMs > 0 ? MINUTE_FORMATTER.format(remainingMinutes) : "cold";
|
|
24
|
+
const resend = context.tokens === undefined ? "" : ` · re-sends ${TOKEN_FORMATTER.format(context.tokens)}`;
|
|
25
|
+
figures.push({ isWarning: remainingMs < CACHE_LOW_MS, label: "cache", text: `${remaining}${resend}` });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (context.tokens !== undefined)
|
|
29
|
+
figures.push({
|
|
30
|
+
isWarning: (context.percent ?? 0) >= USAGE_WARNING_PERCENTAGE,
|
|
31
|
+
label: "context",
|
|
32
|
+
text: `${TOKEN_FORMATTER.format(context.tokens)}/${TOKEN_FORMATTER.format(context.window)}`,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
for (const { kind, percentUsed } of rateLimits)
|
|
36
|
+
figures.push({
|
|
37
|
+
isWarning: percentUsed >= USAGE_WARNING_PERCENTAGE,
|
|
38
|
+
label: RateLimitLabelMap[kind] ?? kind,
|
|
39
|
+
text: `${Math.round(percentUsed)}%`,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (cost) figures.push({ isWarning: false, label: "cost", text: USD_CURRENCY_FORMATTER.format(cost.usd) });
|
|
43
|
+
return figures;
|
|
44
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { On } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { atom, read } from "claude-code";
|
|
4
|
+
|
|
5
|
+
import { InitialState } from "../InitialState";
|
|
6
|
+
import { veilText } from "./veilText";
|
|
7
|
+
import { veilValue } from "./veilValue";
|
|
8
|
+
|
|
9
|
+
const enabledModsAtom = atom({ key: "enabledMods", plugin: "genshin-mods" } as const, InitialState.enabledMods);
|
|
10
|
+
|
|
11
|
+
// Only the drawing changes: the transcript and what the model reads keep the real values. Each read subscribes the
|
|
12
|
+
// Row, so switching the veil redraws every row already on screen. The instruction the veil adds to the system prompt is
|
|
13
|
+
// An unmatched hook, so it is the lifecycle file's
|
|
14
|
+
export const registerVeil = (on: On): void => {
|
|
15
|
+
on("ui.render", { component: "AssistantMessage" }, async ($, e, next) =>
|
|
16
|
+
(await read($, enabledModsAtom)).veil
|
|
17
|
+
? next({ ...e, props: { ...e.props, text: veilText(e.props.text) } })
|
|
18
|
+
: next(e),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
on("ui.render", { component: "UserMessage" }, async ($, e, next) =>
|
|
22
|
+
(await read($, enabledModsAtom)).veil
|
|
23
|
+
? next({ ...e, props: { ...e.props, text: veilText(e.props.text) } })
|
|
24
|
+
: next(e),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
on("ui.render", { component: "ToolResult" }, async ($, e, next) =>
|
|
28
|
+
(await read($, enabledModsAtom)).veil
|
|
29
|
+
? next({ ...e, props: { ...e.props, output: veilValue(e.props.output) } })
|
|
30
|
+
: next(e),
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// A placeholder holds no digit, at sign or currency sign, so no pattern matches what another wrote and the order they
|
|
2
|
+
// Run in changes nothing. A secret is a known key prefix; a long run mixing letters and digits, read from the run's
|
|
3
|
+
// Start alone so a long run of neither is scanned once rather than again from every position in it; or whatever
|
|
4
|
+
// Follows a password's own label, however short
|
|
5
|
+
const VeilPatternMap = new Map<string, RegExp>([
|
|
6
|
+
[
|
|
7
|
+
"[amount]",
|
|
8
|
+
/[$€£¥₹]\s?\d[\d,]*(?:\.\d+)?(?:\s?[KkMmBb]\b)?|\b(?:USD|EUR|GBP|CAD|AUD|JPY|CNY)\s?\d[\d,]*(?:\.\d+)?|\b\d[\d,]*(?:\.\d+)?\s?(?:USD|EUR|GBP|CAD|AUD|JPY|CNY)\b/gu,
|
|
9
|
+
],
|
|
10
|
+
["[email]", /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu],
|
|
11
|
+
[
|
|
12
|
+
"[phone]",
|
|
13
|
+
/\+\d{1,3}[\s.-]?\(?\d{1,4}\)?(?:[\s.-]?\d{2,4}){2,4}|\(\d{3}\)\s?\d{3}[\s.-]\d{4}|\b\d{3}[\s.-]\d{3}[\s.-]\d{4}\b/gu,
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"[secret]",
|
|
17
|
+
/\b(?:sk-[\w-]{16,}|gh[opsu]_\w{16,}|github_pat_\w{16,}|xox[abpr]-[\w-]{10,}|AKIA[0-9A-Z]{16}|eyJ[\w-]+\.[\w-]+\.[\w-]+)|(?<![\w+=-])(?=[\w+=-]*\d)(?=[\w+=-]*[A-Za-z])[\w+=-]{32,}|(?<=\b(?:[Pp]assword|PASSWORD|passwd|pwd)\s*[:=]\s*)(?:"[^"\n]*"|'[^'\n]*'|\S+)/gu,
|
|
18
|
+
],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export const veilText = (text: string): string => {
|
|
22
|
+
let veiled = text;
|
|
23
|
+
for (const [placeholder, pattern] of VeilPatternMap) veiled = veiled.replaceAll(pattern, placeholder);
|
|
24
|
+
return veiled;
|
|
25
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { veilText } from "./veilText";
|
|
2
|
+
|
|
3
|
+
// A tool's output is whatever the tool recorded, so every string inside it is veiled and its shape is kept, which is
|
|
4
|
+
// What the engine draws the result from
|
|
5
|
+
export const veilValue = (value: unknown): unknown => {
|
|
6
|
+
if (typeof value === "string") return veilText(value);
|
|
7
|
+
else if (Array.isArray(value)) return value.map((item) => veilValue(item));
|
|
8
|
+
else if (value !== null && typeof value === "object")
|
|
9
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, veilValue(item)]));
|
|
10
|
+
else return value;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WardRecord } from "../../../types";
|
|
2
|
+
|
|
3
|
+
import { WARD_WINDOW_MS } from "../constants";
|
|
4
|
+
|
|
5
|
+
// Another session's edit inside the window is the one record that asks; a session's own edits never do
|
|
6
|
+
export const getCollidingRecord = (
|
|
7
|
+
record: undefined | WardRecord,
|
|
8
|
+
sessionId: string,
|
|
9
|
+
now: number,
|
|
10
|
+
): undefined | WardRecord =>
|
|
11
|
+
record && record.sessionId !== sessionId && now - record.editedAt < WARD_WINDOW_MS ? record : undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WardRecord } from "../../../types";
|
|
2
|
+
|
|
3
|
+
import { WARD_WINDOW_MS } from "../constants";
|
|
4
|
+
|
|
5
|
+
// The edit recorded and every record past the window dropped, so the file holds the last half hour and no more
|
|
6
|
+
export const getRecordsWithEdit = (
|
|
7
|
+
records: Record<string, WardRecord>,
|
|
8
|
+
path: string,
|
|
9
|
+
record: WardRecord,
|
|
10
|
+
): Record<string, WardRecord> => ({
|
|
11
|
+
...Object.fromEntries(
|
|
12
|
+
Object.entries(records).filter(([, { editedAt }]) => record.editedAt - editedAt < WARD_WINDOW_MS),
|
|
13
|
+
),
|
|
14
|
+
[path]: record,
|
|
15
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { EngineInterface, On, ToolCallResult } from "claude-code";
|
|
2
|
+
|
|
3
|
+
import { atom, read } from "claude-code";
|
|
4
|
+
|
|
5
|
+
import type { WardRecord } from "../../../types";
|
|
6
|
+
|
|
7
|
+
import { WardAnswer, WardAnswers } from "../../models/WardAnswer";
|
|
8
|
+
import { InitialState } from "../InitialState";
|
|
9
|
+
import { getCollidingRecord } from "./getCollidingRecord";
|
|
10
|
+
import { getRecordsWithEdit } from "./getRecordsWithEdit";
|
|
11
|
+
|
|
12
|
+
const enabledModsAtom = atom({ key: "enabledMods", plugin: "genshin-mods" } as const, InitialState.enabledMods);
|
|
13
|
+
const AGE_FORMATTER = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
|
14
|
+
|
|
15
|
+
// One file every session on the machine reads afresh, beside the persona's state, so an edit made a moment ago in
|
|
16
|
+
// Another session is always seen
|
|
17
|
+
const readRecordsPath = async ($: EngineInterface) => {
|
|
18
|
+
const home = (await $.env.get("HOME")) ?? (await $.env.get("USERPROFILE")) ?? "";
|
|
19
|
+
return `${home}/.claude/genshin-mods/ward.json`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const readRecords = async ($: EngineInterface, path: string): Promise<Record<string, WardRecord>> =>
|
|
23
|
+
(await $.fs.exists(path))
|
|
24
|
+
? // oxlint-disable-next-line no-restricted-properties -- The records hold numbers and ids, no date, and a mod cannot import the shared reviver
|
|
25
|
+
(JSON.parse(await $.fs.read(path)) as Record<string, WardRecord>)
|
|
26
|
+
: {};
|
|
27
|
+
|
|
28
|
+
// Before the edit: the question, when another session's record calls for one. After it: the edit recorded
|
|
29
|
+
const ward = async (
|
|
30
|
+
$: EngineInterface,
|
|
31
|
+
path: string,
|
|
32
|
+
proceed: () => Promise<ToolCallResult>,
|
|
33
|
+
): Promise<ToolCallResult> => {
|
|
34
|
+
if (!(await read($, enabledModsAtom)).ward) return proceed();
|
|
35
|
+
const recordsPath = await readRecordsPath($);
|
|
36
|
+
const sessionId = await $.session.id();
|
|
37
|
+
const now = await $.clock.now();
|
|
38
|
+
const collision = getCollidingRecord((await readRecords($, recordsPath))[path], sessionId, now);
|
|
39
|
+
// A session nobody watches has nobody to ask, and a guard that blocks unattended work is worse than none
|
|
40
|
+
if (collision && (await $.session.surfaces()).length > 0) {
|
|
41
|
+
const minutes = -Math.round(Temporal.Duration.from({ milliseconds: now - collision.editedAt }).total("minutes"));
|
|
42
|
+
const age = AGE_FORMATTER.format(minutes, "minute");
|
|
43
|
+
const answer = await $.ui.ask(`Another session edited ${path} ${age}. Edit it here too?`, {
|
|
44
|
+
header: "Ward",
|
|
45
|
+
options: WardAnswers,
|
|
46
|
+
});
|
|
47
|
+
if (answer === WardAnswer.Worktree)
|
|
48
|
+
return {
|
|
49
|
+
deny: `The person asked to move this work into a git worktree before editing ${path}: another session changed it ${age}. Enter a worktree, then carry on there.`,
|
|
50
|
+
};
|
|
51
|
+
else if (answer === WardAnswer.Cancel)
|
|
52
|
+
return { deny: `The person stopped this edit: another session changed ${path} ${age}.` };
|
|
53
|
+
else if (answer !== WardAnswer.Proceed) return { deny: `The person stopped this edit and said: ${answer}` };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const result = await proceed();
|
|
57
|
+
if (!result.deny && !result.isError) {
|
|
58
|
+
const records = getRecordsWithEdit(await readRecords($, recordsPath), path, {
|
|
59
|
+
editedAt: await $.clock.now(),
|
|
60
|
+
sessionId,
|
|
61
|
+
});
|
|
62
|
+
await $.fs.write(recordsPath, JSON.stringify(records));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Any failure lets the edit through, the question dismissed or the record unreadable alike: a guard that blocked on
|
|
69
|
+
// Its own failure would block every edit after it, and Cancel is the person's way to stop one. `next` is replay-safe
|
|
70
|
+
// Here, so an edit the hook had already made is not made twice
|
|
71
|
+
const letEditThrough = <E, R>(_$: EngineInterface, e: E, next: (e: E) => R): R => next(e);
|
|
72
|
+
|
|
73
|
+
export const registerWard = (on: On): void => {
|
|
74
|
+
// eslint-disable-next-line no-restricted-syntax -- The engine's registration handler, run when the hook rejects, not a promise
|
|
75
|
+
on("tool.call", { tool: "Edit" }, ($, e, next) => ward($, e.file_path, () => next(e))).catch(letEditThrough);
|
|
76
|
+
// eslint-disable-next-line no-restricted-syntax -- The engine's registration handler, run when the hook rejects, not a promise
|
|
77
|
+
on("tool.call", { tool: "Write" }, ($, e, next) => ward($, e.file_path, () => next(e))).catch(letEditThrough);
|
|
78
|
+
// eslint-disable-next-line no-restricted-syntax -- The engine's registration handler, run when the hook rejects, not a promise
|
|
79
|
+
on("tool.call", { tool: "NotebookEdit" }, ($, e, next) => ward($, e.notebook_path, () => next(e))).catch(
|
|
80
|
+
letEditThrough,
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MAX_WAYPOINTS, NO_WAYPOINTS_ANSWER } from "../constants";
|
|
2
|
+
|
|
3
|
+
const LIST_MARKER_REGEX = /^(?:[-*•]|\d+[.)])\s+/u;
|
|
4
|
+
|
|
5
|
+
// The fork answers in prose it was asked to keep to lines, so a list marker it added anyway is dropped rather than
|
|
6
|
+
// Sent back as part of the prompt, and an answer of none, or nothing, leaves no step
|
|
7
|
+
export const parseWaypoints = (answer: string): string[] =>
|
|
8
|
+
answer
|
|
9
|
+
.split("\n")
|
|
10
|
+
.map((line) => line.trim().replace(LIST_MARKER_REGEX, "").trim())
|
|
11
|
+
.filter((line) => line && line !== NO_WAYPOINTS_ANSWER)
|
|
12
|
+
.slice(0, MAX_WAYPOINTS);
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The plugin's state contract, the one self-contained file the engine validates the module's `$.state` keys against,
|
|
2
|
+
// So the value types the modules share are declared here too
|
|
3
|
+
export interface Commission {
|
|
4
|
+
goal: string;
|
|
5
|
+
openedAt: number;
|
|
6
|
+
tasks: CommissionTask[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CommissionTask {
|
|
10
|
+
id: string;
|
|
11
|
+
// oxlint-disable-next-line literal-union/no-string-literal-union -- The engine's own task statuses, as its task tools spell them
|
|
12
|
+
status: "completed" | "in_progress" | "pending";
|
|
13
|
+
subject: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Which mods are on, each switched by its own command and kept in the store as one record
|
|
17
|
+
export interface EnabledMods {
|
|
18
|
+
commission: boolean;
|
|
19
|
+
resin: boolean;
|
|
20
|
+
veil: boolean;
|
|
21
|
+
ward: boolean;
|
|
22
|
+
waypoints: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WardRecord {
|
|
26
|
+
editedAt: number;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare module "claude-code" {
|
|
31
|
+
interface PluginState {
|
|
32
|
+
"genshin-mods": {
|
|
33
|
+
commission: Commission;
|
|
34
|
+
enabledMods: EnabledMods;
|
|
35
|
+
isCommissionExpanded: boolean;
|
|
36
|
+
isHandingOff: boolean;
|
|
37
|
+
lastCacheRequestAt: number;
|
|
38
|
+
lastPrompt: string;
|
|
39
|
+
now: number;
|
|
40
|
+
waypoints: string[];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|