@xi4z/dsh-utils 0.0.0-stage → 0.5.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 +21 -0
- package/README.md +576 -2
- package/client.js +2330 -0
- package/cordis.patch.yml +101 -0
- package/icon.svg +21 -0
- package/lib/index.d.ts +69 -0
- package/lib/index.js +865 -0
- package/lib/index.js.map +1 -0
- package/lib/ui-host.d.ts +96 -0
- package/lib/ui-host.js +970 -0
- package/lib/ui-host.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +124 -3
- package/packages/approval-policy/lib/index.d.ts +297 -0
- package/packages/approval-policy/lib/index.js +425 -0
- package/packages/approval-policy/lib/index.js.map +1 -0
- package/packages/approval-policy/locale/en.json +6 -0
- package/packages/approval-policy/locale/zh.json +6 -0
- package/packages/notify/lib/index.d.ts +290 -0
- package/packages/notify/lib/index.js +915 -0
- package/packages/notify/lib/index.js.map +1 -0
- package/packages/notify/locale/en.json +6 -0
- package/packages/notify/locale/zh.json +6 -0
- package/packages/skill-panel/lib/index.d.ts +49 -0
- package/packages/skill-panel/lib/index.js +420 -0
- package/packages/skill-panel/lib/index.js.map +1 -0
- package/packages/skill-panel/locale/en.json +6 -0
- package/packages/skill-panel/locale/zh.json +6 -0
- package/packages/utils-agents/lib/git.d.ts +87 -0
- package/packages/utils-agents/lib/git.js +403 -0
- package/packages/utils-agents/lib/git.js.map +1 -0
- package/packages/utils-agents/lib/global-repo.d.ts +57 -0
- package/packages/utils-agents/lib/global-repo.js +301 -0
- package/packages/utils-agents/lib/global-repo.js.map +1 -0
- package/packages/utils-agents/lib/index.d.ts +80 -0
- package/packages/utils-agents/lib/index.js +435 -0
- package/packages/utils-agents/lib/index.js.map +1 -0
- package/packages/utils-agents/lib/legacy.d.ts +30 -0
- package/packages/utils-agents/lib/legacy.js +141 -0
- package/packages/utils-agents/lib/legacy.js.map +1 -0
- package/packages/utils-agents/lib/native.d.ts +74 -0
- package/packages/utils-agents/lib/native.js +232 -0
- package/packages/utils-agents/lib/native.js.map +1 -0
- package/packages/utils-agents/lib/presets.d.ts +34 -0
- package/packages/utils-agents/lib/presets.js +312 -0
- package/packages/utils-agents/lib/presets.js.map +1 -0
- package/packages/utils-agents/lib/shared.d.ts +105 -0
- package/packages/utils-agents/lib/shared.js +507 -0
- package/packages/utils-agents/lib/shared.js.map +1 -0
- package/packages/utils-agents/lib/update.d.ts +129 -0
- package/packages/utils-agents/lib/update.js +507 -0
- package/packages/utils-agents/lib/update.js.map +1 -0
- package/packages/utils-agents/lib/util.d.ts +215 -0
- package/packages/utils-agents/lib/util.js +475 -0
- package/packages/utils-agents/lib/util.js.map +1 -0
- package/packages/utils-agents/locale/en.json +6 -0
- package/packages/utils-agents/locale/zh.json +6 -0
- package/skills/dsh-approval-policy-config/SKILL.md +96 -0
- package/src/index.ts +933 -0
- package/src/ui-host.ts +1073 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dsh-utils` notify component: push a message through a Gotify gateway when a
|
|
3
|
+
* session finishes a turn, or when the agent is blocked on an approval or a
|
|
4
|
+
* question.
|
|
5
|
+
*
|
|
6
|
+
* The gateway is addressed by URL, so the component works from any machine that
|
|
7
|
+
* can reach it over the internet: one device token, one app token, no local
|
|
8
|
+
* NapCat/OneBot service required. Every message carries the sending device's
|
|
9
|
+
* name so multiple machines sharing one gateway stay distinguishable.
|
|
10
|
+
*
|
|
11
|
+
* Wiring (all read from the session log, never from a waterfall the root
|
|
12
|
+
* context cannot receive):
|
|
13
|
+
*
|
|
14
|
+
* session/event -> accumulate the finished turn's reason + final assistant text
|
|
15
|
+
* agent/status -> the idle edge is the moment the whole task is done
|
|
16
|
+
* tool/call -> ask_user_question / exit_plan_mode is the "parked waiting
|
|
17
|
+
* for a human" signal, debounced; tool/result cancels it
|
|
18
|
+
* approval/asked -> the agent is blocked on a yes/no decision, debounced;
|
|
19
|
+
* approval/decided (auto-decided) cancels it
|
|
20
|
+
*
|
|
21
|
+
* Delivery is plain `fetch` to `POST {gotifyUrl}/message`; no WebSocket, no
|
|
22
|
+
* heartbeat, no extra dependency. The legacy OneBot path is kept for
|
|
23
|
+
* compatibility but Gotify is the default outlet.
|
|
24
|
+
*
|
|
25
|
+
* The bundle mounts this component under the entry id `dsh-notify`
|
|
26
|
+
* (`dsh-utils/notify`); that entry id is also its settings namespace, so the
|
|
27
|
+
* browser half renders a live configuration page for it. Every Config field is
|
|
28
|
+
* volatile: the component re-reads the values on each event, so a save in the
|
|
29
|
+
* settings page takes effect without a restart.
|
|
30
|
+
*
|
|
31
|
+
* Ported from `@local/dsh-plugin-qq-notify` 0.2.0 — same message
|
|
32
|
+
* templates, same environment overrides (`DSH_QQ_NOTIFY_*`), same delivery
|
|
33
|
+
* semantics — with the settings schema, live config reads, and the
|
|
34
|
+
* `dsh-utils` bundle wiring added.
|
|
35
|
+
*
|
|
36
|
+
* @module dsh-utils/notify
|
|
37
|
+
*/
|
|
38
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
39
|
+
import z from '@deepseek-ai/schemastery';
|
|
40
|
+
export declare const name = "dsh-notify";
|
|
41
|
+
export declare const inject: string[];
|
|
42
|
+
/** Turn-end reasons a deployment may subscribe to. */
|
|
43
|
+
export declare const NOTIFY_REASONS: readonly ["completed", "error", "aborted", "blocked"];
|
|
44
|
+
export type NotifyReason = (typeof NOTIFY_REASONS)[number];
|
|
45
|
+
/** One delivery target: an independent gateway credential / series. */
|
|
46
|
+
export interface NotifyTarget {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly url: string;
|
|
49
|
+
readonly token: string;
|
|
50
|
+
readonly priority: number;
|
|
51
|
+
readonly devices: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Settings-page schema. Every key is volatile: the Loader hands `apply` live
|
|
55
|
+
* references and the component re-reads them on use, so the configuration page
|
|
56
|
+
* writes take effect immediately.
|
|
57
|
+
*/
|
|
58
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
59
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
60
|
+
transport: z<"gotify" | "onebot", "gotify" | "onebot", "volatile-defined">;
|
|
61
|
+
endpoint: z<string, string, "volatile-defined">;
|
|
62
|
+
token: z<string, string, "volatile-defined">;
|
|
63
|
+
targetType: z<"private" | "group", "private" | "group", "volatile-defined">;
|
|
64
|
+
targetId: z<string, string, "volatile-defined">;
|
|
65
|
+
gotifyUrl: z<string, string, "volatile-defined">;
|
|
66
|
+
gotifyToken: z<string, string, "volatile-defined">;
|
|
67
|
+
gotifyPriority: z<number, number, "volatile-defined">;
|
|
68
|
+
gotifyHeaders: z<any, any, "volatile-defined">;
|
|
69
|
+
targets: z<any, any, "volatile-defined">;
|
|
70
|
+
deviceName: z<string, string, "volatile-defined">;
|
|
71
|
+
deviceLabel: z<string, string, "volatile-defined">;
|
|
72
|
+
deviceInTitle: z<boolean, boolean, "volatile-defined">;
|
|
73
|
+
notifyOnReasons: z<NoInfer<("completed" | "error" | "aborted" | "blocked")[]>, NoInfer<("completed" | "error" | "aborted" | "blocked")[]>, "volatile-defined">;
|
|
74
|
+
notifyOnApproval: z<boolean, boolean, "volatile-defined">;
|
|
75
|
+
notifyOnQuestion: z<boolean, boolean, "volatile-defined">;
|
|
76
|
+
questionDelayMs: z<number, number, "volatile-defined">;
|
|
77
|
+
approvalDelayMs: z<number, number, "volatile-defined">;
|
|
78
|
+
includeSubagents: z<boolean, boolean, "volatile-defined">;
|
|
79
|
+
summaryChars: z<number, number, "volatile-defined">;
|
|
80
|
+
timeoutMs: z<number, number, "volatile-defined">;
|
|
81
|
+
dryRun: z<boolean, boolean, "volatile-defined">;
|
|
82
|
+
traceFile: z<string, string, "volatile-defined">;
|
|
83
|
+
template: z<string, string, "volatile-defined">;
|
|
84
|
+
questionTemplate: z<string, string, "volatile-defined">;
|
|
85
|
+
approvalTemplate: z<string, string, "volatile-defined">;
|
|
86
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
87
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
88
|
+
transport: z<"gotify" | "onebot", "gotify" | "onebot", "volatile-defined">;
|
|
89
|
+
endpoint: z<string, string, "volatile-defined">;
|
|
90
|
+
token: z<string, string, "volatile-defined">;
|
|
91
|
+
targetType: z<"private" | "group", "private" | "group", "volatile-defined">;
|
|
92
|
+
targetId: z<string, string, "volatile-defined">;
|
|
93
|
+
gotifyUrl: z<string, string, "volatile-defined">;
|
|
94
|
+
gotifyToken: z<string, string, "volatile-defined">;
|
|
95
|
+
gotifyPriority: z<number, number, "volatile-defined">;
|
|
96
|
+
gotifyHeaders: z<any, any, "volatile-defined">;
|
|
97
|
+
targets: z<any, any, "volatile-defined">;
|
|
98
|
+
deviceName: z<string, string, "volatile-defined">;
|
|
99
|
+
deviceLabel: z<string, string, "volatile-defined">;
|
|
100
|
+
deviceInTitle: z<boolean, boolean, "volatile-defined">;
|
|
101
|
+
notifyOnReasons: z<NoInfer<("completed" | "error" | "aborted" | "blocked")[]>, NoInfer<("completed" | "error" | "aborted" | "blocked")[]>, "volatile-defined">;
|
|
102
|
+
notifyOnApproval: z<boolean, boolean, "volatile-defined">;
|
|
103
|
+
notifyOnQuestion: z<boolean, boolean, "volatile-defined">;
|
|
104
|
+
questionDelayMs: z<number, number, "volatile-defined">;
|
|
105
|
+
approvalDelayMs: z<number, number, "volatile-defined">;
|
|
106
|
+
includeSubagents: z<boolean, boolean, "volatile-defined">;
|
|
107
|
+
summaryChars: z<number, number, "volatile-defined">;
|
|
108
|
+
timeoutMs: z<number, number, "volatile-defined">;
|
|
109
|
+
dryRun: z<boolean, boolean, "volatile-defined">;
|
|
110
|
+
traceFile: z<string, string, "volatile-defined">;
|
|
111
|
+
template: z<string, string, "volatile-defined">;
|
|
112
|
+
questionTemplate: z<string, string, "volatile-defined">;
|
|
113
|
+
approvalTemplate: z<string, string, "volatile-defined">;
|
|
114
|
+
}>>, "plain">;
|
|
115
|
+
/** Volatile Config fields arrive as live references; `.get()` snapshots. */
|
|
116
|
+
interface VolatileRef<T> {
|
|
117
|
+
get(): T;
|
|
118
|
+
}
|
|
119
|
+
/** One setting as the Loader supplies it: a live reference, or a plain value in tests. */
|
|
120
|
+
type MaybeRef<T> = T | VolatileRef<T>;
|
|
121
|
+
/** The runtime shape `apply` receives (every field volatile, every field optional). */
|
|
122
|
+
export interface NotifyConfig {
|
|
123
|
+
readonly enabled?: MaybeRef<boolean>;
|
|
124
|
+
readonly transport?: MaybeRef<string>;
|
|
125
|
+
readonly endpoint?: MaybeRef<string>;
|
|
126
|
+
readonly token?: MaybeRef<string>;
|
|
127
|
+
readonly targetType?: MaybeRef<string>;
|
|
128
|
+
readonly targetId?: MaybeRef<string>;
|
|
129
|
+
readonly gotifyUrl?: MaybeRef<string>;
|
|
130
|
+
readonly gotifyToken?: MaybeRef<string>;
|
|
131
|
+
readonly gotifyPriority?: MaybeRef<number>;
|
|
132
|
+
readonly gotifyHeaders?: MaybeRef<unknown>;
|
|
133
|
+
readonly targets?: MaybeRef<unknown>;
|
|
134
|
+
readonly deviceName?: MaybeRef<string>;
|
|
135
|
+
readonly deviceLabel?: MaybeRef<string>;
|
|
136
|
+
readonly deviceInTitle?: MaybeRef<boolean>;
|
|
137
|
+
readonly notifyOnReasons?: MaybeRef<readonly string[]>;
|
|
138
|
+
readonly notifyOnApproval?: MaybeRef<boolean>;
|
|
139
|
+
readonly notifyOnQuestion?: MaybeRef<boolean>;
|
|
140
|
+
readonly questionDelayMs?: MaybeRef<number>;
|
|
141
|
+
readonly approvalDelayMs?: MaybeRef<number>;
|
|
142
|
+
readonly includeSubagents?: MaybeRef<boolean>;
|
|
143
|
+
readonly summaryChars?: MaybeRef<number>;
|
|
144
|
+
readonly timeoutMs?: MaybeRef<number>;
|
|
145
|
+
readonly dryRun?: MaybeRef<boolean>;
|
|
146
|
+
readonly traceFile?: MaybeRef<string>;
|
|
147
|
+
readonly template?: MaybeRef<string>;
|
|
148
|
+
readonly questionTemplate?: MaybeRef<string>;
|
|
149
|
+
readonly approvalTemplate?: MaybeRef<string>;
|
|
150
|
+
}
|
|
151
|
+
/** Normalized options with every default applied. */
|
|
152
|
+
interface Options {
|
|
153
|
+
enabled: boolean;
|
|
154
|
+
transport: 'gotify' | 'onebot';
|
|
155
|
+
endpoint: string;
|
|
156
|
+
token: string;
|
|
157
|
+
targetType: 'private' | 'group';
|
|
158
|
+
targetId: string;
|
|
159
|
+
gotifyUrl: string;
|
|
160
|
+
gotifyToken: string;
|
|
161
|
+
gotifyPriority: number;
|
|
162
|
+
gotifyHeaders: Readonly<Record<string, string>>;
|
|
163
|
+
targets: readonly NotifyTarget[];
|
|
164
|
+
deviceName: string;
|
|
165
|
+
deviceLabel: string;
|
|
166
|
+
deviceInTitle: boolean;
|
|
167
|
+
notifyOnReasons: readonly NotifyReason[];
|
|
168
|
+
notifyOnApproval: boolean;
|
|
169
|
+
notifyOnQuestion: boolean;
|
|
170
|
+
questionDelayMs: number;
|
|
171
|
+
approvalDelayMs: number;
|
|
172
|
+
includeSubagents: boolean;
|
|
173
|
+
summaryChars: number;
|
|
174
|
+
timeoutMs: number;
|
|
175
|
+
dryRun: boolean;
|
|
176
|
+
traceFile: string;
|
|
177
|
+
template: string;
|
|
178
|
+
questionTemplate: string;
|
|
179
|
+
approvalTemplate: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Expand `${NAME}` and `${NAME:-fallback}` references against the process
|
|
183
|
+
* environment, so a deployment can keep gateway secrets outside the patch file.
|
|
184
|
+
* An unset or blank variable expands to the fallback (or to ''), leaving the
|
|
185
|
+
* target without a token instead of sending the literal reference.
|
|
186
|
+
*/
|
|
187
|
+
export declare function expandEnv(value: unknown): string;
|
|
188
|
+
/** Keep only string/number request headers; ignore everything else. */
|
|
189
|
+
export declare function normalizeHeaders(raw: unknown): Record<string, string>;
|
|
190
|
+
/**
|
|
191
|
+
* Normalize `targets` into a predictable list; bad entries are dropped.
|
|
192
|
+
* A target with only one of url/token is kept so delivery can warn about the
|
|
193
|
+
* exact target name instead of silently disappearing.
|
|
194
|
+
*/
|
|
195
|
+
export declare function normalizeTargets(raw: unknown, fallbackPriority?: number): NotifyTarget[];
|
|
196
|
+
/** A target with no `devices` list applies everywhere; otherwise match name or label. */
|
|
197
|
+
export declare function targetMatchesDevice(target: NotifyTarget, cfg: Pick<Options, 'deviceName' | 'deviceLabel'>): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Resolve the live Config into one concrete option set: defaults, then the
|
|
200
|
+
* settings values, then the environment overrides (so a deployment can keep
|
|
201
|
+
* secrets out of the patch file).
|
|
202
|
+
*/
|
|
203
|
+
export declare function normalizeOptions(config: NotifyConfig | undefined): Options;
|
|
204
|
+
/**
|
|
205
|
+
* Turn assistant Markdown into a short plain-text snippet for the gateway.
|
|
206
|
+
*
|
|
207
|
+
* Fenced code blocks are dropped entirely (they are long and unreadable once
|
|
208
|
+
* flattened); inline code keeps its text; emphasis markers, headings, list
|
|
209
|
+
* bullets, table pipes and HTML tags are removed. Single underscores are left
|
|
210
|
+
* alone so `session_id` survives. The result is then cut at `limit`, preferring
|
|
211
|
+
* a sentence boundary when one is reasonably close to the end.
|
|
212
|
+
*/
|
|
213
|
+
export declare function plain(text: unknown, limit?: number): string;
|
|
214
|
+
/** One question parsed out of an `ask_user_question` tool call. */
|
|
215
|
+
export interface ParsedQuestion {
|
|
216
|
+
readonly question: string;
|
|
217
|
+
readonly detail?: string;
|
|
218
|
+
readonly header?: string;
|
|
219
|
+
readonly options: readonly string[];
|
|
220
|
+
}
|
|
221
|
+
/** Parse `ask_user_question` tool arguments defensively (older logs, odd providers). */
|
|
222
|
+
export declare function parseQuestions(raw: unknown): ParsedQuestion[];
|
|
223
|
+
/** Parse `exit_plan_mode` tool arguments into the reviewed plan text. */
|
|
224
|
+
export declare function parsePlan(raw: unknown): string | undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Fill a template. A line containing only a label whose value is empty
|
|
227
|
+
* (`目录: ` / `回复: `) is dropped, so one template serves every outcome.
|
|
228
|
+
*/
|
|
229
|
+
export declare function fill(template: string, values: Readonly<Record<string, unknown>>): string;
|
|
230
|
+
/** Default turn-end template. */
|
|
231
|
+
export declare const DEFAULT_TEMPLATE: string;
|
|
232
|
+
/** Default question template. */
|
|
233
|
+
export declare const DEFAULT_QUESTION_TEMPLATE: string;
|
|
234
|
+
/** Default approval template. */
|
|
235
|
+
export declare const DEFAULT_APPROVAL_TEMPLATE: string;
|
|
236
|
+
/** Inputs for a turn-end message. */
|
|
237
|
+
export interface TurnMessageInput {
|
|
238
|
+
readonly sessionId: unknown;
|
|
239
|
+
readonly cwd?: string;
|
|
240
|
+
readonly reason?: string;
|
|
241
|
+
readonly error?: string;
|
|
242
|
+
readonly reply?: string;
|
|
243
|
+
readonly summaryChars?: number;
|
|
244
|
+
readonly template?: string;
|
|
245
|
+
readonly device?: string;
|
|
246
|
+
readonly host?: string;
|
|
247
|
+
}
|
|
248
|
+
/** Compact body of a turn-completion message. */
|
|
249
|
+
export declare function renderMessage(input: TurnMessageInput): string;
|
|
250
|
+
/** Inputs for a question-request message. */
|
|
251
|
+
export interface QuestionMessageInput {
|
|
252
|
+
readonly sessionId: unknown;
|
|
253
|
+
readonly cwd?: string;
|
|
254
|
+
readonly question?: string;
|
|
255
|
+
readonly detail?: string;
|
|
256
|
+
readonly options?: string;
|
|
257
|
+
readonly template?: string;
|
|
258
|
+
readonly device?: string;
|
|
259
|
+
readonly host?: string;
|
|
260
|
+
}
|
|
261
|
+
/** Compact body of a question-request message (the agent is blocked on you). */
|
|
262
|
+
export declare function renderQuestionMessage(input: QuestionMessageInput): string;
|
|
263
|
+
/** Inputs for an approval-request message. */
|
|
264
|
+
export interface ApprovalMessageInput {
|
|
265
|
+
readonly sessionId: unknown;
|
|
266
|
+
readonly cwd?: string;
|
|
267
|
+
readonly toolName?: string;
|
|
268
|
+
readonly reason?: string;
|
|
269
|
+
readonly template?: string;
|
|
270
|
+
readonly device?: string;
|
|
271
|
+
readonly host?: string;
|
|
272
|
+
}
|
|
273
|
+
/** Compact body of an approval-request message. */
|
|
274
|
+
export declare function renderApprovalMessage(input: ApprovalMessageInput): string;
|
|
275
|
+
/** The OneBot endpoint slice `callAction` needs. */
|
|
276
|
+
export interface OneBotEndpoint {
|
|
277
|
+
readonly endpoint: string;
|
|
278
|
+
readonly token: string;
|
|
279
|
+
readonly timeoutMs: number;
|
|
280
|
+
}
|
|
281
|
+
/** POST one OneBot 11 action; throws on transport failure or a non-ok retcode. */
|
|
282
|
+
export declare function callAction(cfg: OneBotEndpoint, action: string, body: unknown): Promise<unknown>;
|
|
283
|
+
/**
|
|
284
|
+
* Activate the component.
|
|
285
|
+
* @param ctx - host Cordis context.
|
|
286
|
+
* @param config - row config from cordis.patch.yml or the settings document;
|
|
287
|
+
* volatile fields arrive as live references.
|
|
288
|
+
*/
|
|
289
|
+
export declare function apply(ctx: Context, config?: NotifyConfig): void;
|
|
290
|
+
export {};
|