dsh-foreman 0.3.2 → 0.3.3

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/CHANGELOG.md CHANGED
@@ -6,6 +6,28 @@
6
6
 
7
7
  本项目自己的版本从 `0.1.0` 开始。
8
8
 
9
+ ## 0.3.3 — 2026-11-08
10
+
11
+ ### 改进:派单时直接告诉设备「你就是那台机器」
12
+
13
+ 人在 hub 上写「看看宿舍电脑上的项目结构」。「宿舍电脑」就是收到这条任务的那台机器,但**派单文本里
14
+ 没有一句话说明这件事**——设备收到的只有标题和请求原文。
15
+
16
+ 于是模型每次都要先花不少步数去比对设备名、列目录、找自己在哪儿,确认之后才真正开始干活。
17
+
18
+ 现在每张派单的开头多了一段:
19
+
20
+ ```
21
+ ## Where this job runs
22
+
23
+ You are the device **宿舍电脑** (id `pc`) working in `F:\dsh`. When the request names this machine —
24
+ "宿舍电脑", or "this computer", "here", "the machine you are on" — it means you, and the files are
25
+ already under that directory. Do not go looking for another machine.
26
+ ```
27
+
28
+ 只把**登记的设备名**当作别名。目录的最后一段通常是项目名(`shop`),把它说成机器别名会让模型
29
+ 搞不清那是项目还是主机。
30
+
9
31
  ## 0.3.2 — 2026-11-08
10
32
 
11
33
  ### 修复:派单文本没有说要回报
package/lib/index.js CHANGED
@@ -9629,6 +9629,16 @@ function attachmentSection(names) {
9629
9629
  * wrote a complete answer, and never called `foreman_report`, so the hub sat at `running` with no report forever and
9630
9630
  * a person saw a job that never finished. The tool exists, but nothing told the model it was required or final.
9631
9631
  */
9632
+ /**
9633
+ * Where this job is running, stated so the device never has to deduce that the request referred to itself.
9634
+ *
9635
+ * A person at the hub writes about their machines by name ("the dorm computer", "my laptop"). The device that receives
9636
+ * that sentence IS one of those machines, but nothing in the text said which one, so the model spent its first steps
9637
+ * comparing names, listing directories and looking for itself. This is one line that ends that.
9638
+ */
9639
+ function locationSection(device) {
9640
+ return `\n## Where this job runs\n\nYou are the device **${device.name}** (id \`${device.id}\`) working in \`${device.directory}\`. When the request names this machine — "${device.name}", or "this computer", "here", "the machine you are on" — it means you, and the files are already under that directory. Do not go looking for another machine.\n`;
9641
+ }
9632
9642
  const REPORT_SECTION = [
9633
9643
  "\n## Reporting back\n",
9634
9644
  "\nWhen you have finished, call `foreman_report` — that tool is how this job reaches the person who asked, and ",
@@ -9654,9 +9664,11 @@ function renderForDevice(input) {
9654
9664
  }
9655
9665
  const scope = scopeOf(ticket);
9656
9666
  const request = trigger?.text?.trim() ?? "";
9667
+ const location = input.device === void 0 ? "" : locationSection(input.device);
9657
9668
  return {
9658
9669
  text: [
9659
9670
  `# ${ticket.title}`,
9671
+ location,
9660
9672
  scope === "" ? "" : `\n${scope}\n`,
9661
9673
  request === "" ? "" : `\n## The request as it was written\n\n${request}\n`,
9662
9674
  attachmentSection(attachments.map((attachment) => attachment.name ?? attachment.id)),
@@ -9812,7 +9824,11 @@ var ForemanExecutor = class {
9812
9824
  }));
9813
9825
  }
9814
9826
  assignFrame(ticket, assignment, deviceId, directory) {
9815
- const rendered = this.render(ticket);
9827
+ const device = this.input.deviceOf?.(deviceId);
9828
+ const rendered = this.render(ticket, device === void 0 ? void 0 : {
9829
+ ...device,
9830
+ directory
9831
+ });
9816
9832
  return {
9817
9833
  v: 1,
9818
9834
  type: "assign",
@@ -9829,11 +9845,12 @@ var ForemanExecutor = class {
9829
9845
  * The task as the device reads it. Rendered on the hub because the device has none of the hub's resources; the
9830
9846
  * device directory rides on the frame, not in the text.
9831
9847
  */
9832
- render(ticket) {
9848
+ render(ticket, device) {
9833
9849
  return renderForDevice({
9834
9850
  ticket,
9835
9851
  ...(this.input.triggerOf ?? (() => ({})))(ticket),
9836
- readAttachment: this.input.readAttachment ?? (() => Buffer.alloc(0))
9852
+ readAttachment: this.input.readAttachment ?? (() => Buffer.alloc(0)),
9853
+ ...device === void 0 ? {} : { device }
9837
9854
  });
9838
9855
  }
9839
9856
  /** Append work to the send chain, keeping the chain alive after a failure. */
@@ -11924,6 +11941,13 @@ var Runtime = class extends Service {
11924
11941
  local: executor,
11925
11942
  readAttachment: (id) => readFileSync(attachmentPath(id)),
11926
11943
  triggerOf: (ticket) => ({ trigger: store.triggers.get(ticket.origin.triggerId) }),
11944
+ deviceOf: (id) => {
11945
+ const device = this.devices.get(id);
11946
+ return device === void 0 ? void 0 : {
11947
+ id: device.id,
11948
+ name: device.name
11949
+ };
11950
+ },
11927
11951
  engine: () => this.engine,
11928
11952
  transport: { send: (deviceId, frame) => this.hub?.send(deviceId, frame) ?? Promise.reject(/* @__PURE__ */ new Error(`the foreman hub is not listening, so ${deviceId} cannot be reached`)) },
11929
11953
  log: (text) => ctx.logger.warn("dsh-foreman: %s", text)
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-foreman",
3
3
  "author": "niechao136",
4
4
  "license": "MIT",
5
- "version": "0.3.2",
5
+ "version": "0.3.3",
6
6
  "description": "dsh-foreman:主 loop 在多设备上派单的 DSH bundle:需求来自本机操作者的主会话而不是 GitHub/飞书,每个工作区各有一条主会话,主会话只负责路由,真正的活儿派给 Worker 在该工作区目录里执行。",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",