@cloud411716/fancy-webnovel 1.0.22 → 1.0.24

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.
@@ -86,23 +86,20 @@ export function apply(ctx) {
86
86
  }
87
87
 
88
88
  if (!projectRoot) {
89
- notify(session, bootstrap.notify({ type: 'no_path' }));
90
- return { kind: 'success', text: '' };
89
+ return notify(session, 'error', bootstrap.notify({ type: 'no_path' }));
91
90
  }
92
91
 
93
92
  if (projectRoot === '.') {
94
93
  projectRoot = session.header?.cwd ?? process.cwd();
95
- notify(session, bootstrap.notify({ type: 'using_cwd', projectRoot }));
94
+ return notify(session, 'success', bootstrap.notify({ type: 'using_cwd', projectRoot }));
96
95
  }
97
96
 
98
97
  if (!isValidPath(projectRoot)) {
99
- notify(session, bootstrap.notify({ type: 'invalid_path' }));
100
- return { kind: 'success', text: '' };
98
+ return notify(session, 'error', bootstrap.notify({ type: 'invalid_path' }));
101
99
  }
102
100
 
103
101
  if (existsSync(join(projectRoot, '.fancy-deployed'))) {
104
- notify(session, bootstrap.notify({ type: 'already_initialized' }));
105
- return { kind: 'success', text: '' };
102
+ return notify(session, 'error', bootstrap.notify({ type: 'already_initialized' }));
106
103
  }
107
104
 
108
105
  // ---------- confirm ----------
@@ -120,20 +117,17 @@ export function apply(ctx) {
120
117
  const ans = confirm.answers[0];
121
118
  const chosen = ans?.selected?.[0] ?? ans?.custom;
122
119
  if (chosen !== '确认创建') {
123
- notify(session, bootstrap.notify({ type: 'cancelled' }));
124
- return { kind: 'success', text: '' };
120
+ return notify(session, 'error', bootstrap.notify({ type: 'cancelled' }));
125
121
  }
126
122
 
127
123
  // ---------- init (in-process, no subprocess) ----------
128
124
  const result = await initProject(projectRoot);
129
125
 
130
126
  if (result.ok) {
131
- notify(session, bootstrap.notify({ type: 'success' }));
127
+ return notify(session, 'success', bootstrap.notify({ type: 'success' }));
132
128
  } else {
133
- notify(session, bootstrap.notify({ type: 'error', err: result.error }));
129
+ return notify(session, 'error', bootstrap.notify({ type: 'error', err: result.error }));
134
130
  }
135
-
136
- return { kind: 'success', text: '' };
137
131
  },
138
132
  });
139
133
  }
@@ -128,12 +128,11 @@ export function apply(ctx) {
128
128
  // ---------- check project root ----------
129
129
  const projectRoot = session.header?.cwd ?? process.cwd();
130
130
  if (!existsSync(join(projectRoot, '.fancy-deployed'))) {
131
- notify(session, scan.notify({ type: 'not_initialized' }));
132
- return { kind: 'success', text: '' };
131
+ return notify(session, 'error', scan.notify({ type: 'not_initialized' }));
133
132
  }
134
133
 
135
134
  // ---------- platform selection ----------
136
- notify(session, scan.platformList());
135
+ notify(session, 'success', scan.platformList());
137
136
 
138
137
  const platformResult = await ctx.userQuestions.ask({
139
138
  questions: [scan.askPlatform()],
@@ -142,14 +141,12 @@ export function apply(ctx) {
142
141
  });
143
142
  const answer = platformResult.answers[0]?.custom?.trim();
144
143
  if (!answer) {
145
- notify(session, scan.notify({ type: 'cancelled' }));
146
- return { kind: 'success', text: '' };
144
+ return notify(session, 'error', scan.notify({ type: 'cancelled' }));
147
145
  }
148
146
  const numMatch = answer.match(/^(\d+)$/);
149
147
  const row = numMatch ? PLATFORM_TABLE.find(r => r[0] === numMatch[1]) : null;
150
148
  if (!row) {
151
- notify(session, scan.notify({ type: 'invalid_choice' }));
152
- return { kind: 'success', text: '' };
149
+ return notify(session, 'error', scan.notify({ type: 'invalid_choice' }));
153
150
  }
154
151
  const platform = row[1];
155
152
 
@@ -164,8 +161,7 @@ export function apply(ctx) {
164
161
 
165
162
  const rawChoices = selected.length > 0 ? selected : (custom ? [custom] : []);
166
163
  if (rawChoices.length === 0) {
167
- notify(session, scan.notify({ type: 'cancelled' }));
168
- return { kind: 'success', text: '' };
164
+ return notify(session, 'error', scan.notify({ type: 'cancelled' }));
169
165
  }
170
166
 
171
167
  const scraper = SCRAPERS[platform];
@@ -191,8 +187,7 @@ export function apply(ctx) {
191
187
  }
192
188
 
193
189
  if (rankEntries.length === 0) {
194
- notify(session, scan.notify({ type: 'invalid_choice' }));
195
- return { kind: 'success', text: '' };
190
+ return notify(session, 'error', scan.notify({ type: 'invalid_choice' }));
196
191
  }
197
192
 
198
193
  // ---------- in-process scraping (no subprocess) ----------
@@ -226,7 +221,7 @@ export function apply(ctx) {
226
221
 
227
222
  // ---------- output results ----------
228
223
  if (lastReceipt && totalFiles > 0) {
229
- notify(session, scan.notify({
224
+ notify(session, 'success', scan.notify({
230
225
  type: 'handover',
231
226
  platform,
232
227
  files: lastReceipt.scan_files,
@@ -247,7 +242,7 @@ export function apply(ctx) {
247
242
  const lines = failedRanks.map(({ rank, err }) => {
248
243
  return `• ${rank.label}:${err}`;
249
244
  });
250
- notify(session, `⚠️ 以下榜单采集失败(共 ${failedRanks.length} 项):\n${lines.join('\n')}`);
245
+ return notify(session, 'error', `⚠️ 以下榜单采集失败(共 ${failedRanks.length} 项):\n${lines.join('\n')}`);
251
246
  }
252
247
 
253
248
  return { kind: 'success', text: '' };
package/infra.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * infra.js — DSH Plugin Core Infrastructure
3
3
  *
4
4
  * Provides:
5
- * notify(session, text) — append a user-facing message (LLM-invisible)
5
+ * notify(session, text) — return error result shown as TUI toast + Web left-panel
6
6
  * llmFollowup(invocation,prompt) — hand a prompt to the LLM as a user message
7
7
  * StatusLine(session) — in-place updatable status bar via surfaceOp replace
8
8
  * scanProgress(ctx, phase, data) — emit structured scan progress events
@@ -12,8 +12,9 @@
12
12
  */
13
13
 
14
14
  // --------------------------------------------------------------------------
15
- // notify — append a text message visible to the user but invisible to LLM
15
+ // notify — return error result propagated through dsh-commands settleThrown()
16
16
  // --------------------------------------------------------------------------
17
+ //
17
18
 
18
19
  /** Strip ANSI escape sequences from a string (defensive, prevents TTY leak). */
19
20
  function stripAnsi(str) {
@@ -21,15 +22,15 @@ function stripAnsi(str) {
21
22
  }
22
23
 
23
24
  /**
24
- * @param {object} session - DSH Session object
25
+ * @param {object} session - DSH Session object (unused, kept for API compatibility)
26
+ * @param {'error'|'success'} kind
25
27
  * @param {string} text
28
+ * @returns {{ kind: 'error'|'success', text: string }} Result propagated through
29
+ * dsh-commands settleThrown() → command/done → channel.notify() (TUI toast)
30
+ * and command/done (Web left-panel with real commandId prefix)
26
31
  */
27
- export function notify(session, text) {
28
- session.append('command/done', {
29
- commandId: `fancy-notify-${Date.now()}`,
30
- kind: 'success',
31
- text: stripAnsi(text),
32
- });
32
+ export function notify(session, kind, text) {
33
+ return { kind, text: stripAnsi(text) };
33
34
  }
34
35
 
35
36
  // --------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {