@uncarved/jade 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +279 -278
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/session.js +16 -3
  5. package/dist/session.js.map +1 -1
  6. package/package.json +3 -3
  7. package/plugins/mentions/candidates.ts +14 -0
  8. package/plugins/mentions/index.ts +2 -2
  9. package/plugins/models/configure.ts +61 -3
  10. package/plugins/models/index.ts +62 -5
  11. package/plugins/models/plugin.json +1 -1
  12. package/plugins/models/provider.ts +55 -9
  13. package/plugins/models/saved.ts +1 -1
  14. package/plugins/prompts/index.ts +0 -0
  15. package/plugins/schedule/index.ts +3 -1
  16. package/plugins/screenshot/browser.ts +1 -1
  17. package/plugins/shell/index.ts +8 -4
  18. package/plugins/shell/plugin.json +2 -1
  19. package/plugins/shell/shell.ts +33 -7
  20. package/plugins/steer/index.ts +1 -1
  21. package/plugins/todo/index.ts +6 -10
  22. package/plugins/tui/frontend.ts +6 -2
  23. package/plugins/tui/markdown.ts +10 -8
  24. package/plugins/tui/mentions.ts +10 -0
  25. package/plugins/tui/transcript.ts +14 -17
  26. package/plugins/tui/tui.ts +13 -12
  27. package/plugins/tui/width.ts +240 -0
  28. package/plugins/undo/checkpoint.ts +3 -1
  29. package/plugins/undo/index.ts +132 -22
  30. package/plugins/undo/plugin.json +1 -0
  31. package/plugins/undo/snapshot.ts +87 -14
  32. package/plugins-dist/mentions/candidates.js +6 -0
  33. package/plugins-dist/mentions/index.js +2 -2
  34. package/plugins-dist/models/configure.js +51 -2
  35. package/plugins-dist/models/index.js +58 -4
  36. package/plugins-dist/models/plugin.json +2 -1
  37. package/plugins-dist/models/provider.js +43 -8
  38. package/plugins-dist/models/saved.js +1 -1
  39. package/plugins-dist/prompts/index.js +6 -1
  40. package/plugins-dist/schedule/index.js +1 -0
  41. package/plugins-dist/screenshot/browser.js +1 -1
  42. package/plugins-dist/shell/index.js +12 -10
  43. package/plugins-dist/shell/plugin.json +2 -1
  44. package/plugins-dist/shell/shell.js +21 -7
  45. package/plugins-dist/steer/index.js +1 -1
  46. package/plugins-dist/todo/index.js +3 -8
  47. package/plugins-dist/tui/frontend.js +5 -2
  48. package/plugins-dist/tui/markdown.js +11 -9
  49. package/plugins-dist/tui/mentions.js +6 -0
  50. package/plugins-dist/tui/transcript.js +9 -12
  51. package/plugins-dist/tui/tui.js +10 -9
  52. package/plugins-dist/tui/width.js +219 -0
  53. package/plugins-dist/undo/checkpoint.js +3 -1
  54. package/plugins-dist/undo/index.js +111 -15
  55. package/plugins-dist/undo/plugin.json +3 -0
  56. package/plugins-dist/undo/snapshot.js +62 -11
  57. package/src/api.ts +1 -1
  58. package/src/session.ts +13 -3
package/src/api.ts CHANGED
@@ -5,7 +5,7 @@ import type { PluginLayer } from "@uncarved/jade-api";
5
5
  export * from "@uncarved/jade-api";
6
6
 
7
7
  /** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明。和 @uncarved/jade-api 的版本一致 */
8
- export const API_VERSION = "1.3.0";
8
+ export const API_VERSION = "1.5.0";
9
9
 
10
10
  /** 来源层级,后面的层级更高(3.3) */
11
11
  export const LAYERS: readonly PluginLayer[] = ["bundled", "user", "project"];
package/src/session.ts CHANGED
@@ -267,7 +267,8 @@ class LiveSession implements Session {
267
267
  if (this.#left) return Promise.reject(this.#left);
268
268
  return new Promise((resolve, reject) => {
269
269
  this.#queue.push({ run, resolve, reject });
270
- this.#kick();
270
+ // session() 执行期间(Runtime 还没建)排进来的等 attach 再开始
271
+ if (this.#attached) this.#kick();
271
272
  });
272
273
  }
273
274
 
@@ -311,7 +312,7 @@ class LiveSession implements Session {
311
312
  this.#plugins = plugins;
312
313
  this.#use(rt);
313
314
  this.#attached = true;
314
- if (this.#after.length > 0) this.#kick();
315
+ if (this.#queue.length > 0 || this.#after.length > 0) this.#kick();
315
316
  }
316
317
 
317
318
  /** 换上一个 Runtime:通知从它转给订阅者。插件的回调以插件身份执行;出错只报告 */
@@ -379,7 +380,8 @@ class LiveSession implements Session {
379
380
  }
380
381
 
381
382
  abort(reason?: unknown): void {
382
- this.rt.abort(reason);
383
+ // Runtime 还没建(session() 执行期间、打开失败时):没有在跑的
384
+ this.rt?.abort(reason);
383
385
  // 停在等待人工审批时内核没有在跑,信号结束不了这一轮
384
386
  if (this.#turn) {
385
387
  this.#turn.stop = { reason };
@@ -497,6 +499,8 @@ export class Sessions implements SessionManager {
497
499
  ? await Runtime.resume({ store, provider, plugins, sessionId: s.id })
498
500
  : await Runtime.create({ store, provider, plugins, sessionId: s.id });
499
501
  } catch (e) {
502
+ // session() 里排进来的输入不会再执行了
503
+ s.leave();
500
504
  await this.#closeParts(s);
501
505
  throw e;
502
506
  }
@@ -587,6 +591,7 @@ export class Sessions implements SessionManager {
587
591
  for (const p of host.active()) if (p.module.session) await this.#join(s, p);
588
592
  rt = await Runtime.create({ store: s.store, provider, plugins: kernelPlugins(), sessionId: s.id, parent: child.ref });
589
593
  } catch (e) {
594
+ s.leave();
590
595
  await this.#closeParts(s);
591
596
  release();
592
597
  throw e;
@@ -761,6 +766,11 @@ export class Sessions implements SessionManager {
761
766
  if (!s.rt) throw new Error(`plugin ${id}: the session's state is not available while session() runs`);
762
767
  return s.rt.state;
763
768
  },
769
+ phase: () => {
770
+ if (scope.closed) throw new StaleContext(id);
771
+ if (!s.rt) throw new Error(`plugin ${id}: the session's phase is not available while session() runs`);
772
+ return s.rt.phase;
773
+ },
764
774
  subscribe: (fn) => {
765
775
  if (scope.closed) throw new StaleContext(id);
766
776
  const off = s.watch(fn, owner);