dsh-lowtide 0.1.2 → 0.2.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/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
- import { basename, dirname, isAbsolute, join, resolve } from "node:path";
2
+ import { chmodSync, createReadStream, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
4
4
  import { execFile } from "node:child_process";
5
5
  import { homedir } from "node:os";
6
6
  import { installModelSelection } from "@deepseek-ai/dsh-agent";
@@ -4659,7 +4659,11 @@ function superRefine(fn, params) {
4659
4659
  const GIT_TIMEOUT_MS = 3e3;
4660
4660
  function git(workspace, args) {
4661
4661
  return new Promise((resolve) => {
4662
- execFile("git", args, {
4662
+ execFile("git", [
4663
+ "-c",
4664
+ "core.fsmonitor=",
4665
+ ...args
4666
+ ], {
4663
4667
  cwd: workspace,
4664
4668
  timeout: GIT_TIMEOUT_MS,
4665
4669
  windowsHide: true
@@ -4822,7 +4826,11 @@ const taskSchema = object({
4822
4826
  chosenCandidateIndex: number().min(0).optional(),
4823
4827
  deferCount: number().optional(),
4824
4828
  lastError: string().optional(),
4825
- lastRun: taskRunSchema.optional()
4829
+ lastRun: taskRunSchema.optional(),
4830
+ /** Last in-place edit timestamp (edit keeps the task id/status). */
4831
+ editedAt: string().optional(),
4832
+ /** Number of in-place edits applied to this task. */
4833
+ editCount: number().int().min(0).optional()
4826
4834
  });
4827
4835
  const reportRowSchema = object({
4828
4836
  taskId: string(),
@@ -4897,11 +4905,16 @@ const batchSchema = object({
4897
4905
  const strictWindowSchema = windowSchema.extend({
4898
4906
  start: string().regex(HHMM, "时间须为 HH:MM(00:00–23:59)"),
4899
4907
  end: string().regex(HHMM, "时间须为 HH:MM(00:00–23:59)"),
4900
- tz: string().refine(isIanaTz, "非法时区").optional()
4908
+ tz: string().refine(isIanaTz, "非法时区").optional(),
4909
+ days: array(number().int().min(1).max(7)).optional(),
4910
+ multiplier: number().gt(0, "倍率必须大于 0").optional()
4901
4911
  });
4902
4912
  const strictBatchSchema = batchSchema.extend({
4903
4913
  window: string().regex(/^([01]\d|2[0-3]):[0-5]\d-([01]\d|2[0-3]):[0-5]\d$/, "窗口须为 HH:MM-HH:MM"),
4904
- tz: string().refine(isIanaTz, "非法时区").optional()
4914
+ tz: string().refine(isIanaTz, "非法时区").optional(),
4915
+ gateLeadMin: number().min(0).max(120),
4916
+ maxTasksPerNight: number().int().min(1),
4917
+ maxDurationMin: number().min(1)
4905
4918
  });
4906
4919
  const configSchema = object({
4907
4920
  autonomy: _enum([
@@ -4934,17 +4947,17 @@ const configUpdateSchema = object({
4934
4947
  windows: array(strictWindowSchema).optional(),
4935
4948
  prices: record(string(), object({
4936
4949
  peak: object({
4937
- input: number(),
4938
- inputCached: number(),
4939
- output: number()
4950
+ input: number().min(0),
4951
+ inputCached: number().min(0),
4952
+ output: number().min(0)
4940
4953
  }),
4941
4954
  off: object({
4942
- input: number(),
4943
- inputCached: number(),
4944
- output: number()
4955
+ input: number().min(0),
4956
+ inputCached: number().min(0),
4957
+ output: number().min(0)
4945
4958
  })
4946
4959
  })).optional(),
4947
- budgetDailyYuan: number().optional(),
4960
+ budgetDailyYuan: number().min(0).optional(),
4948
4961
  maxReportHistory: number().int().min(0).optional()
4949
4962
  });
4950
4963
  const stateSchema = object({
@@ -4985,21 +4998,25 @@ function convertLegacyState(node) {
4985
4998
  }
4986
4999
  return node;
4987
5000
  }
4988
- /** Hard cap for locked-file snapshots: bigger files are refused (streamed
4989
- * hashing would still work, but a multi-GB locked file is almost certainly
4990
- * a mistake and would stall the batch). */
4991
- const MAX_SNAPSHOT_BYTES = 1073741824;
5001
+ /** Hard cap for locked-file snapshots: bigger files are refused (pentest P8).
5002
+ * Hashing streams, but a multi-hundred-MB locked file is almost certainly a
5003
+ * mistake and would stall the batch. */
5004
+ const MAX_SNAPSHOT_BYTES = 67108864;
4992
5005
  /**
4993
5006
  * File snapshot: sha256 + size via a STREAM (readFileSync would load a
4994
- * multi-GB file fully into memory — Kimi review H3).
5007
+ * multi-GB file fully into memory — Kimi review H3). The size cap is checked
5008
+ * via stat BEFORE opening the stream so an oversized file is rejected without
5009
+ * reading a single byte.
4995
5010
  */
4996
5011
  async function snapshotFile(path) {
5012
+ const { size: statSize } = statSync(path);
5013
+ if (statSize > 67108864) throw new Error(`文件过大(>${Math.floor(MAX_SNAPSHOT_BYTES / 1024 / 1024)}MB),不适合作为锁定文件`);
4997
5014
  const hash = createHash("sha256");
4998
5015
  let size = 0;
4999
5016
  for await (const chunk of createReadStream(path)) {
5000
5017
  hash.update(chunk);
5001
5018
  size += chunk.length;
5002
- if (size > 1073741824) throw new Error(`文件过大(>${Math.floor(MAX_SNAPSHOT_BYTES / 1024 / 1024)}MB),不适合作为锁定文件`);
5019
+ if (size > 67108864) throw new Error(`文件过大(>${Math.floor(MAX_SNAPSHOT_BYTES / 1024 / 1024)}MB),不适合作为锁定文件`);
5003
5020
  }
5004
5021
  return {
5005
5022
  sha256: hash.digest("hex"),
@@ -5076,6 +5093,9 @@ var LowtideStore = class LowtideStore {
5076
5093
  rmSync(this.file, { force: true });
5077
5094
  renameSync(tmp, this.file);
5078
5095
  }
5096
+ if (process.platform !== "win32") try {
5097
+ chmodSync(this.file, 384);
5098
+ } catch {}
5079
5099
  } finally {
5080
5100
  try {
5081
5101
  rmSync(tmp, { force: true });
@@ -5150,6 +5170,26 @@ var LowtideStore = class LowtideStore {
5150
5170
  return task;
5151
5171
  });
5152
5172
  }
5173
+ /**
5174
+ * Edit a task IN PLACE: the id, createdAt, status and triage records are
5175
+ * untouched; every content field (prompt/files/workspace/gitRef/strategy/
5176
+ * model/estimates/…) is replaced from the validated patch, the stale
5177
+ * lastError is cleared, and the edit audit counters are bumped. The route
5178
+ * layer must guard statuses via canEdit() before calling this.
5179
+ */
5180
+ editTask(id, patch) {
5181
+ return this.mutate(() => {
5182
+ const task = this.state.tasks.find((t) => t.id === id);
5183
+ if (task === void 0) return void 0;
5184
+ const editedAt = (/* @__PURE__ */ new Date()).toISOString();
5185
+ const { id: _id, createdAt: _createdAt, status: _status, triagedAt: _triagedAt, triagedBy: _triagedBy, editedAt: _editedAt, editCount: _editCount, ...content } = patch;
5186
+ Object.assign(task, content);
5187
+ task.lastError = void 0;
5188
+ task.editedAt = editedAt;
5189
+ task.editCount = (task.editCount ?? 0) + 1;
5190
+ return task;
5191
+ });
5192
+ }
5153
5193
  recordRun(id, run, finalStatus) {
5154
5194
  return this.mutate(() => {
5155
5195
  const task = this.state.tasks.find((t) => t.id === id);
@@ -5289,6 +5329,7 @@ async function intake(input, defaultWorkspace, options) {
5289
5329
  ok: false,
5290
5330
  error: `工作区不存在:${workspace}`
5291
5331
  };
5332
+ const workspaceRoot = realpathSync(workspace);
5292
5333
  const files = [];
5293
5334
  for (const entry of data.files) {
5294
5335
  const raw = typeof entry === "string" ? entry : entry.path;
@@ -5297,6 +5338,11 @@ async function intake(input, defaultWorkspace, options) {
5297
5338
  ok: false,
5298
5339
  error: `文件不存在:${abs}`
5299
5340
  };
5341
+ const real = realpathSync(abs);
5342
+ if (real !== workspaceRoot && !real.startsWith(workspaceRoot + sep)) return {
5343
+ ok: false,
5344
+ error: `文件路径越界(须位于工作区内):${raw}`
5345
+ };
5300
5346
  try {
5301
5347
  const snap = await snapshotFile(abs);
5302
5348
  files.push({
@@ -5401,7 +5447,14 @@ async function listAvailableModels(ctx, prices = OFFICIAL_PRICES) {
5401
5447
  try {
5402
5448
  const info = await ctx.llm.resolveModelInfo(p.id, m.id);
5403
5449
  const efforts = info?.reasoning?.efforts;
5404
- if (Array.isArray(efforts) && efforts.length > 0) reasoningEfforts = efforts.map((e) => e.id);
5450
+ if (Array.isArray(efforts) && efforts.length > 0) reasoningEfforts = efforts.map((e) => {
5451
+ const { id, name, description } = e;
5452
+ return {
5453
+ id,
5454
+ name: name ?? id,
5455
+ ...description !== void 0 ? { description } : {}
5456
+ };
5457
+ });
5405
5458
  if (typeof info?.reasoning?.defaultEffort === "string") defaultReasoningEffort = info.reasoning.defaultEffort;
5406
5459
  } catch {}
5407
5460
  return {
@@ -6660,6 +6713,22 @@ function isTrustedApiRequest(headers) {
6660
6713
  //#endregion
6661
6714
  //#region src/state-machine.ts
6662
6715
  /**
6716
+ * Statuses whose content may be EDITED in place (edit keeps the status —
6717
+ * a pending-review task stays pending-review, a queued one stays queued).
6718
+ * deferred is included: it has not run yet, so editing it and waiting for
6719
+ * the next window is natural (otherwise the user would need restore → edit
6720
+ * → approve, three steps for one fix).
6721
+ */
6722
+ const EDITABLE_STATUSES = [
6723
+ "pending-review",
6724
+ "queued",
6725
+ "deferred"
6726
+ ];
6727
+ /** Whether a task in this status may be edited in place. */
6728
+ function canEdit(status) {
6729
+ return EDITABLE_STATUSES.includes(status);
6730
+ }
6731
+ /**
6663
6732
  * A transition is rejected unless the current status allows it — otherwise a
6664
6733
  * running task could be re-queued behind the agent's back and the persisted
6665
6734
  * state would fight the live execution.
@@ -6750,6 +6819,8 @@ function listWorkspaceSessions(limitPerWorkspace = 30) {
6750
6819
  //#region src/routes.ts
6751
6820
  /** 活跃的 SSE 客户端;每次状态变更或心跳时推送 state 事件(PLAN §5.3/§7.3)。 */
6752
6821
  const sseClients = /* @__PURE__ */ new Set();
6822
+ /** Hard cap on concurrent SSE connections (pentest P7). */
6823
+ const MAX_SSE_CLIENTS = 16;
6753
6824
  async function broadcastState(ctx, routes) {
6754
6825
  if (sseClients.size === 0) return;
6755
6826
  const frame = `event: state\ndata: ${JSON.stringify(await statePayload(ctx, routes))}\n\n`;
@@ -6761,6 +6832,15 @@ async function broadcastState(ctx, routes) {
6761
6832
  }
6762
6833
  const MAX_BODY_BYTES = 1048576;
6763
6834
  const BODY_TIMEOUT_MS = 15e3;
6835
+ /** Error carrying an HTTP status — the catch-all replies with it verbatim
6836
+ * (message is our own controlled copy) instead of a generic 500. */
6837
+ var HttpError = class extends Error {
6838
+ status;
6839
+ constructor(status, message) {
6840
+ super(message);
6841
+ this.status = status;
6842
+ }
6843
+ };
6764
6844
  function jsonBody(req) {
6765
6845
  return new Promise((resolve, reject) => {
6766
6846
  let raw = "";
@@ -6778,7 +6858,7 @@ function jsonBody(req) {
6778
6858
  if (settled) return;
6779
6859
  bytesReceived += chunk.length;
6780
6860
  if (bytesReceived > MAX_BODY_BYTES) {
6781
- fail(/* @__PURE__ */ new Error("请求体过大(>1MB)"));
6861
+ fail(new HttpError(413, "请求体过大(>1MB)"));
6782
6862
  req.destroy();
6783
6863
  return;
6784
6864
  }
@@ -6844,6 +6924,13 @@ function registerRoutes(ctx, routes) {
6844
6924
  return;
6845
6925
  }
6846
6926
  if (path === "/ds-lowtide/events" && req.method === "GET") {
6927
+ if (sseClients.size >= MAX_SSE_CLIENTS) {
6928
+ reply(res, 429, {
6929
+ ok: false,
6930
+ error: "事件流连接数已达上限"
6931
+ });
6932
+ return;
6933
+ }
6847
6934
  res.writeHead(200, {
6848
6935
  "content-type": "text/event-stream; charset=utf-8",
6849
6936
  "cache-control": "no-cache",
@@ -6854,6 +6941,9 @@ function registerRoutes(ctx, routes) {
6854
6941
  req.on("close", () => {
6855
6942
  sseClients.delete(res);
6856
6943
  });
6944
+ res.on("close", () => {
6945
+ sseClients.delete(res);
6946
+ });
6857
6947
  broadcastState(ctx, routes);
6858
6948
  return;
6859
6949
  }
@@ -7058,6 +7148,64 @@ function registerRoutes(ctx, routes) {
7058
7148
  reply(res, 200, { ok: true });
7059
7149
  return;
7060
7150
  }
7151
+ const editMatch = /^\/ds-lowtide\/tasks\/([^/]+)\/edit$/.exec(path);
7152
+ if (editMatch !== null && req.method === "POST") {
7153
+ const id = editMatch[1];
7154
+ const task = store.taskById(id);
7155
+ if (task === void 0) {
7156
+ reply(res, 404, {
7157
+ ok: false,
7158
+ error: "任务不存在"
7159
+ });
7160
+ return;
7161
+ }
7162
+ if (!canEdit(task.status)) {
7163
+ reply(res, 409, {
7164
+ ok: false,
7165
+ error: `任务状态 ${task.status} 不允许编辑`
7166
+ });
7167
+ return;
7168
+ }
7169
+ const body = await jsonBody(req);
7170
+ if (typeof body?.continuesFromSession === "string" && body.continuesFromSession !== "") {
7171
+ if (!/^[A-Za-z0-9._-]+$/.test(body.continuesFromSession)) {
7172
+ reply(res, 400, {
7173
+ ok: false,
7174
+ error: "会话标识不合法"
7175
+ });
7176
+ return;
7177
+ }
7178
+ }
7179
+ if (typeof body?.modelProvider === "string" && body.modelProvider !== "") {
7180
+ const knownProviders = ctx.llm?.listProviders() ?? [];
7181
+ if (knownProviders.length > 0 && !knownProviders.some((p) => p.id === body.modelProvider)) {
7182
+ reply(res, 400, {
7183
+ ok: false,
7184
+ error: `模型提供方不存在:${body.modelProvider}`
7185
+ });
7186
+ return;
7187
+ }
7188
+ }
7189
+ const result = await intake(body, process.cwd(), {
7190
+ autonomy: store.config.autonomy,
7191
+ modelId: typeof body.model === "string" && body.model !== "" ? body.model : ctx.agentDefaultModel.currentSelection().model,
7192
+ prices: store.config.prices
7193
+ });
7194
+ if (!result.ok || result.task === void 0) {
7195
+ reply(res, 400, {
7196
+ ok: false,
7197
+ error: result.error ?? "编辑失败"
7198
+ });
7199
+ return;
7200
+ }
7201
+ const edited = store.editTask(id, result.task);
7202
+ broadcastState(ctx, routes);
7203
+ reply(res, 200, {
7204
+ ok: true,
7205
+ task: edited
7206
+ });
7207
+ return;
7208
+ }
7061
7209
  const match = /^\/ds-lowtide\/tasks\/([^/]+)\/(approve|defer|drop|cancel|delete|retry|restore|choose-candidate)$/.exec(path);
7062
7210
  if (match !== null && req.method === "POST") {
7063
7211
  const [, id, action] = match;
@@ -7167,9 +7315,17 @@ function registerRoutes(ctx, routes) {
7167
7315
  error: `unknown route ${req.method} ${path}`
7168
7316
  });
7169
7317
  } catch (error) {
7318
+ if (error instanceof HttpError) {
7319
+ reply(res, error.status, {
7320
+ ok: false,
7321
+ error: error.message
7322
+ });
7323
+ return;
7324
+ }
7325
+ ctx.logger("lowtide").warn("request failed: %s", error instanceof Error ? error.message : String(error));
7170
7326
  reply(res, 500, {
7171
7327
  ok: false,
7172
- error: error instanceof Error ? error.message : String(error)
7328
+ error: "服务器内部错误"
7173
7329
  });
7174
7330
  }
7175
7331
  })();
@@ -34,6 +34,13 @@ export declare function submitTask(input: {
34
34
  /** Per-task autonomy override (new-task modal); absent = follow global. */
35
35
  autonomy?: 'l1' | 'l2' | 'l3';
36
36
  }): Promise<TaskResponse>;
37
+ /**
38
+ * Edit an existing task IN PLACE (status preserved — a pending-review task
39
+ * stays pending-review, a queued one stays queued). The request body is the
40
+ * same full form used by submitTask; the server re-runs intake and refreshes
41
+ * the content fields, keeping id/createdAt/status/triage records.
42
+ */
43
+ export declare function editTask(id: string, input: Parameters<typeof submitTask>[0]): Promise<TaskResponse>;
37
44
  export declare function triage(id: string, action: 'approve' | 'defer' | 'drop' | 'cancel'): Promise<unknown>;
38
45
  /** 采样任务的次日择优:记录用户选定的候选序号。 */
39
46
  export declare function chooseCandidate(id: string, index: number): Promise<{
@@ -133,7 +140,11 @@ export interface AvailableModel {
133
140
  name: string;
134
141
  priceKnown: boolean;
135
142
  inputModalities?: string[];
136
- reasoningEfforts?: string[];
143
+ reasoningEfforts?: ReadonlyArray<{
144
+ id: string;
145
+ name: string;
146
+ description?: string;
147
+ }>;
137
148
  defaultReasoningEffort?: string;
138
149
  }
139
150
  export interface AvailableProvider {
@@ -0,0 +1,10 @@
1
+ import { type HostTask } from '../store.ts';
2
+ import { type NsTranslate } from '../i18n.ts';
3
+ import { type AutonomyId } from './TaskForm.tsx';
4
+ export declare function EditTaskModal({ task, t, defaultAutonomy, onClose }: {
5
+ task: HostTask;
6
+ t: NsTranslate;
7
+ /** Global autonomy from the live state — only used when the task carries no override. */
8
+ defaultAutonomy: AutonomyId;
9
+ onClose: () => void;
10
+ }): React.JSX.Element;
@@ -1,7 +1,9 @@
1
1
  import { type HostTask } from '../store.ts';
2
2
  import { type NsTranslate } from '../i18n.ts';
3
- export declare function TaskDetail({ task, t, onClose }: {
3
+ export declare function TaskDetail({ task, t, onClose, onEdit }: {
4
4
  task: HostTask;
5
5
  t: NsTranslate;
6
6
  onClose: () => void;
7
+ /** Opens the in-place edit modal (wired when the status allows editing). */
8
+ onEdit?: (task: HostTask) => void;
7
9
  }): React.JSX.Element;
@@ -23,11 +23,20 @@ export type ReasoningId = 'follow' | 'off' | 'minimal' | 'low' | 'medium' | 'hig
23
23
  export type AutonomyId = 'l1' | 'l2' | 'l3';
24
24
  export type SessionModeId = 'new' | 'continue';
25
25
  export type TaskModelId = string;
26
+ export interface ReasoningEffortOption {
27
+ id: string;
28
+ /** Adapter-native label (e.g. "Low"/"High"); falls back to the raw id. */
29
+ name: string;
30
+ description?: string;
31
+ }
26
32
  export interface TaskFormModel {
27
33
  id: string;
28
34
  name: string;
35
+ /** Canonical provider id — this is what gets submitted as modelProvider. */
29
36
  provider: string;
30
- reasoningEfforts?: string[];
37
+ /** Human-friendly provider name for the optgroup label (defaults to the id). */
38
+ providerLabel?: string;
39
+ reasoningEfforts?: ReadonlyArray<ReasoningEffortOption>;
31
40
  defaultReasoningEffort?: string;
32
41
  }
33
42
  /** A dsh conversation stored under a workspace (from GET /sessions). */
@@ -1,7 +1,9 @@
1
1
  import { type HostTask } from '../store.ts';
2
2
  import { type NsTranslate } from '../i18n.ts';
3
- export declare function TaskRow({ task, t, onOpenDetail }: {
3
+ export declare function TaskRow({ task, t, onOpenDetail, onEdit }: {
4
4
  task: HostTask;
5
5
  t: NsTranslate;
6
6
  onOpenDetail: (task: HostTask) => void;
7
+ /** Opens the in-place edit modal (only wired for editable statuses). */
8
+ onEdit?: (task: HostTask) => void;
7
9
  }): React.JSX.Element;
@@ -51,11 +51,14 @@ declare const zh: {
51
51
  'empty.title': string;
52
52
  'empty.cta': string;
53
53
  'footer.approveAndRun': string;
54
+ 'footer.approveAndRunConfirm': string;
55
+ 'footer.approveAndRunConfirmShort': string;
54
56
  'footer.runNow': string;
55
57
  'action.approve': string;
56
58
  'action.defer': string;
57
59
  'action.drop': string;
58
60
  'action.retry': string;
61
+ 'action.edit': string;
59
62
  'action.delete': string;
60
63
  'action.deleteConfirm': string;
61
64
  'action.deleteConfirmShort': string;
@@ -70,6 +73,8 @@ declare const zh: {
70
73
  'toast.requeued': string;
71
74
  'toast.submitted': string;
72
75
  'toast.submitFailed': string;
76
+ 'toast.edited': string;
77
+ 'toast.editFailed': string;
73
78
  'toast.restored': string;
74
79
  'section.running': string;
75
80
  'section.done': string;
@@ -83,6 +88,8 @@ declare const zh: {
83
88
  'detail.triaged': string;
84
89
  'detail.triagedAuto': string;
85
90
  'detail.triagedUser': string;
91
+ 'detail.edited': string;
92
+ 'detail.editedCount': string;
86
93
  'detail.continuesFromSession': string;
87
94
  'detail.model': string;
88
95
  'detail.estimateKnown': string;
@@ -97,6 +104,9 @@ declare const zh: {
97
104
  'detail.fileCount': string;
98
105
  'modal.title': string;
99
106
  'modal.desc': string;
107
+ 'modal.editTitle': string;
108
+ 'modal.editDesc': string;
109
+ 'modal.saveEdit': string;
100
110
  'modal.cancel': string;
101
111
  'modal.submit': string;
102
112
  'modal.promptPlaceholderSingle': string;
@@ -155,13 +165,6 @@ declare const zh: {
155
165
  'strategy.sampling': string;
156
166
  'strategy.review': string;
157
167
  'reasoning.follow': string;
158
- 'reasoning.off': string;
159
- 'reasoning.minimal': string;
160
- 'reasoning.low': string;
161
- 'reasoning.medium': string;
162
- 'reasoning.high': string;
163
- 'reasoning.xhigh': string;
164
- 'reasoning.max': string;
165
168
  'strategy.singleHint': string;
166
169
  'strategy.iterativeHint': string;
167
170
  'strategy.samplingHint': string;
@@ -110,6 +110,10 @@ export interface HostTask {
110
110
  continuesFromSession?: string;
111
111
  chosenCandidateIndex?: number;
112
112
  lastError?: string;
113
+ /** Last in-place edit timestamp (edit keeps the task id/status). */
114
+ editedAt?: string;
115
+ /** Number of in-place edits applied to this task. */
116
+ editCount?: number;
113
117
  lastRun?: {
114
118
  at: string;
115
119
  status: string;
@@ -16,8 +16,12 @@ export interface AvailableModel {
16
16
  priceKnown: boolean;
17
17
  /** Adapter-declared input modalities (e.g. ["text", "image"]) — optional. */
18
18
  inputModalities?: string[];
19
- /** Supported reasoning effort ids (e.g. ["off","low","high","max"]). */
20
- reasoningEfforts?: string[];
19
+ /** Supported reasoning efforts with the adapter's native labels. */
20
+ reasoningEfforts?: ReadonlyArray<{
21
+ id: string;
22
+ name: string;
23
+ description?: string;
24
+ }>;
21
25
  /** The model's default reasoning effort id, when the adapter declares one. */
22
26
  defaultReasoningEffort?: string;
23
27
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Lowtide HTTP API (PLAN T1.3 / §7.3, Phase 1 subset) under /ds-lowtide.
3
- * The Host/Origin trust fence (T2.8) is not yet mounted — the server binds
3
+ * The Host/Origin trust fence (T2.8/B2) IS mounted — every request passes
4
+ * isTrustedApiRequest first (loopback Host + same-origin). The server binds
4
5
  * loopback only and the README deployment guidance (SSH tunnel) is Phase 4.
5
6
  */
6
7
  import type { Context } from '@deepseek-ai/cordis';
@@ -5,6 +5,16 @@
5
5
  */
6
6
  /** Triage actions accepted by the /tasks/:id/:action routes. */
7
7
  export type TriageAction = 'approve' | 'defer' | 'drop' | 'cancel' | 'retry' | 'delete' | 'restore' | 'choose-candidate';
8
+ /**
9
+ * Statuses whose content may be EDITED in place (edit keeps the status —
10
+ * a pending-review task stays pending-review, a queued one stays queued).
11
+ * deferred is included: it has not run yet, so editing it and waiting for
12
+ * the next window is natural (otherwise the user would need restore → edit
13
+ * → approve, three steps for one fix).
14
+ */
15
+ export declare const EDITABLE_STATUSES: readonly ["pending-review", "queued", "deferred"];
16
+ /** Whether a task in this status may be edited in place. */
17
+ export declare function canEdit(status: string): boolean;
8
18
  /**
9
19
  * A transition is rejected unless the current status allows it — otherwise a
10
20
  * running task could be re-queued behind the agent's back and the persisted
@@ -12,13 +12,13 @@ export declare const configUpdateSchema: z.ZodObject<{
12
12
  l3: "l3";
13
13
  }>>;
14
14
  batch: z.ZodOptional<z.ZodObject<{
15
- gateLeadMin: z.ZodOptional<z.ZodNumber>;
16
- maxTasksPerNight: z.ZodOptional<z.ZodNumber>;
17
- maxDurationMin: z.ZodOptional<z.ZodNumber>;
18
15
  paused: z.ZodOptional<z.ZodBoolean>;
19
16
  maxConcurrency: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
20
17
  window: z.ZodOptional<z.ZodString>;
21
18
  tz: z.ZodOptional<z.ZodOptional<z.ZodString>>;
19
+ gateLeadMin: z.ZodOptional<z.ZodNumber>;
20
+ maxTasksPerNight: z.ZodOptional<z.ZodNumber>;
21
+ maxDurationMin: z.ZodOptional<z.ZodNumber>;
22
22
  }, z.core.$strip>>;
23
23
  windows: z.ZodOptional<z.ZodArray<z.ZodObject<{
24
24
  id: z.ZodString;
@@ -28,11 +28,11 @@ export declare const configUpdateSchema: z.ZodObject<{
28
28
  off: "off";
29
29
  peak: "peak";
30
30
  }>;
31
- days: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
32
- multiplier: z.ZodOptional<z.ZodNumber>;
33
31
  start: z.ZodString;
34
32
  end: z.ZodString;
35
33
  tz: z.ZodOptional<z.ZodString>;
34
+ days: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
35
+ multiplier: z.ZodOptional<z.ZodNumber>;
36
36
  }, z.core.$strip>>>;
37
37
  prices: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
38
38
  peak: z.ZodObject<{
@@ -63,13 +63,15 @@ export interface StoreState {
63
63
  dismissedPeakDay?: string;
64
64
  }
65
65
  export declare function stateFilePath(): string;
66
- /** Hard cap for locked-file snapshots: bigger files are refused (streamed
67
- * hashing would still work, but a multi-GB locked file is almost certainly
68
- * a mistake and would stall the batch). */
66
+ /** Hard cap for locked-file snapshots: bigger files are refused (pentest P8).
67
+ * Hashing streams, but a multi-hundred-MB locked file is almost certainly a
68
+ * mistake and would stall the batch. */
69
69
  export declare const MAX_SNAPSHOT_BYTES: number;
70
70
  /**
71
71
  * File snapshot: sha256 + size via a STREAM (readFileSync would load a
72
- * multi-GB file fully into memory — Kimi review H3).
72
+ * multi-GB file fully into memory — Kimi review H3). The size cap is checked
73
+ * via stat BEFORE opening the stream so an oversized file is rejected without
74
+ * reading a single byte.
73
75
  */
74
76
  export declare function snapshotFile(path: string): Promise<{
75
77
  sha256: string;
@@ -102,6 +104,14 @@ export declare class LowtideStore {
102
104
  */
103
105
  deleteTask(id: string): boolean;
104
106
  setStatus(id: string, status: TaskStatus, patch?: Partial<Task>): Task | undefined;
107
+ /**
108
+ * Edit a task IN PLACE: the id, createdAt, status and triage records are
109
+ * untouched; every content field (prompt/files/workspace/gitRef/strategy/
110
+ * model/estimates/…) is replaced from the validated patch, the stale
111
+ * lastError is cleared, and the edit audit counters are bumped. The route
112
+ * layer must guard statuses via canEdit() before calling this.
113
+ */
114
+ editTask(id: string, patch: Partial<Task>): Task | undefined;
105
115
  recordRun(id: string, run: TaskRun, finalStatus: TaskStatus): Task | undefined;
106
116
  addSavings(savedYuan: number): void;
107
117
  ledgerToday(now: Date): LedgerDay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lowtide",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "lowtide: human-adjudicated off-peak batch task pipeline for dsh (peak/valley pricing aware)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -62,7 +62,7 @@
62
62
  "repository": {
63
63
  "type": "git",
64
64
  "url": "https://github.com/KelaoHu/dsh-lowtide",
65
- "directory": "packages/dsh"
65
+ "directory": "packages/dsh-lowtide"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@deepseek-ai/dsh-agent": "^0.1.0-rc.7",