@method-ai-hq/sdk 0.14.5 → 0.14.6

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  MIT-licensed JavaScript API and the `method` CLI. Source and releases: https://github.com/method-ai-hq/method-sdk
4
4
 
5
5
  ```sh
6
- npm install https://github.com/method-ai-hq/method-sdk/releases/download/v0.14.5/method-ai-hq-sdk-0.14.5.tgz
6
+ npm install https://github.com/method-ai-hq/method-sdk/releases/download/v0.14.6/method-ai-hq-sdk-0.14.6.tgz
7
7
  npx method --version
8
8
  ```
9
9
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@method-ai-hq/sdk",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "description": "Build and run reusable .method files with checked steps and saved results.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -5,7 +5,7 @@ export declare const designProcedure = "# Choose the design\n\n| Requirement | S
5
5
  /** The full check rules; in concepts. */
6
6
  export declare const checkRules = "# Checks\n\nAdd a check only when it catches a concrete failure that matters to the result. Output types and the runtime already validate shapes; do not repeat them. Do not check wording, headings, keywords, lengths, or counts unless the task requires them: \"write accurate prose\" is not a reason to match strings.\n\nUse the simplest check that proves the fact: a built-in equals, count, present, or file check, a script, or an agent check. Local file writes need no check: the runtime observes files connections itself. A change to a service, an API, email, or a browser that sends needs an effect that reads the result back, because a receipt or a 200 status shows only that the request was accepted. Use a built-in observer (http, sqlite, file) when one fits. When a change cannot or need not be observed, such as a browser step that only reads, write no_effect_reason instead.\n\nExisting checks and tests are implementation choices, not user requirements. Remove a check that is unnecessary, repeats other validation, or enforces a requirement that nobody asked for. Delete the tests and instructions that exist only for it, and do not replace it. Do not change useful output only to satisfy a check.\n";
7
7
  /** The rules that make a first Method work quickly. They come before every other part of the guide. */
8
- export declare const firstMethodRules = "# Build a Method\n\n1. **Sign in first.** Run `method status`. If it is not signed in, run `method login` and let the user approve in the browser. Signed in, model and classification steps need no keys, each run saves a version when the file changed, and runs appear on the dashboard.\n2. **Each model or classifier request is its own step**: `call`, `agent`, or `classify`, with its prompt in the Method, so the user can change one prompt, run again, and compare. A script never calls a model API. When the user already has code that does the work, keep its fixed logic as `run` steps and move each prompt and rubric into its own step; do not wrap the code. \"The same thing\" means the same behavior in steps. If a request cannot become a step because Method lacks a feature, tell the user what is missing.\n3. **Show the design, then build it in the same turn.** Show each step with its type, purpose, and output, and a table of the prompts and rubrics in the user's existing work, each with the step that holds it. Do not wait for approval unless the user asked to approve first. Ask only for information that you cannot find and that would change the design.\n4. **Run early and often.** Write the first steps, validate, run, then add the next steps. Fix errors. Fix each warning, or accept it with the user's reason. Never add a check only to remove a warning. A new run reuses every step whose definition and inputs did not change, so each run executes only what changed. `--rerun STEP` runs a step again anyway; `--fresh` runs every step.\n5. **Keep the inputs of the existing code.** If the code takes an ID and looks up the record, the Method takes the same ID and looks it up the same way.\n6. **Use the defaults without asking.** Model steps use the account's hosted models and `classify` uses Method's classifier, so no model or classifier keys are needed. To keep the model that existing code uses, add `models: {writer: provider/model}` to the Method and use `model: writer` in the steps (or `model: provider/model` on the step); it needs no key. Keep the models that the Method or the existing code names: when a model step fails, show the error and ask before you change its model. Run records go to the user's account. When the user asks that run data stay on this computer or not be uploaded, set `run_data: device`: the run's inputs, outputs, and files stay here, and the account keeps only each step's status and timing. Model steps still send each step's input to the model to answer it; nothing is kept. Tell the user that in one line, then run again.\n7. **Keys stay out of chat.** Declare each key that a script needs under `secrets:` with its purpose; every script of the Method receives all of its declared secrets. Run `method secret find` in the Method's folder: it lists the key files nearby and the names in each, never the values, and prints the import command. Run that command and tell the user which file each key came from: the key stays on this computer, so there is nothing to ask. If it finds nothing, ask the user to run `method secret set NAME`, which opens a private form in their browser. Never open, print, or search a key file (`cat`, `grep`, an editor), including Method's own secret store, and never ask for a value in chat: the values would go into the chat. When a run says Method's model credit is used up, run `method config model-key` yourself: it takes the user's own OpenRouter key from the one nearby key file that holds it, or opens a private form for it. Then run again.\n8. **Choose a sample yourself** from the user's data, and check that it has the sources the Method needs. Ask only when there is no good sample.\n9. **Iterate.** After a good run, show the result and the dashboard link, and ask what to change. Change the step and run again. Show only results that a run made: never write or edit a result by hand, and fix a wrong result in the Method, not in the data it reads. If you cannot run, say so.\n10. **Publish** with `method publish FILE --reason TEXT` when the user wants to share or schedule a version. It runs the Method's cases first.\n11. **Talk about the work, not about Method.** Unless the user asks, do not mention Method's versions, formats, settings files, or other internal files, and do not ask the user about them, about models, or about which saved version to use. Method updates itself and converts older Method files when it runs them. When the user asks whether a Method works, or asks you to make it work, run it with the inputs of a recent run and show the result and the dashboard link in a few sentences. Say that it works only after a run completed.\n12. **One file for each Method.** Change and run a Method in its own file. Do not copy it to a temporary or other folder to change it: Method does not run or save the copy while the Method's file exists, and names that file.\n13. **Questions in a run are for the user.** When a run stops with `needs_input`, ask the user its `question` in plain words, wait for the answer, and continue the run with it as the output says. Never answer it yourself.\n\nWhen a run fails, read its `fix` and `diagnostics`, change the step, and run again.\n";
8
+ export declare const firstMethodRules = "# Build a Method\n\n1. **Sign in first.** Run `method status`. If it is not signed in, run `method login` and let the user approve in the browser. Signed in, model and classification steps need no keys, each run saves a version when the file changed, and runs appear on the dashboard.\n2. **Each model or classifier request is its own step**: `call`, `agent`, or `classify`, with its prompt in the Method, so the user can change one prompt, run again, and compare. A script never calls a model API. When the user already has code that does the work, keep its fixed logic as `run` steps and move each prompt and rubric into its own step; do not wrap the code. \"The same thing\" means the same behavior in steps. If a request cannot become a step because Method lacks a feature, tell the user what is missing.\n3. **Show the design, then build it in the same turn.** Show each step with its type, purpose, and output, and a table of the prompts and rubrics in the user's existing work, each with the step that holds it. Do not wait for approval unless the user asked to approve first. Ask only for information that you cannot find and that would change the design.\n4. **Run early and often.** Write the first steps, validate, run, then add the next steps. Fix errors. Fix each warning, or accept it with the user's reason. Never add a check only to remove a warning. A new run reuses every step whose definition and inputs did not change, so each run executes only what changed. `--rerun STEP` runs a step again anyway; `--fresh` runs every step.\n5. **Keep the inputs of the existing code.** If the code takes an ID and looks up the record, the Method takes the same ID and looks it up the same way.\n6. **Use the defaults without asking.** Model steps use the account's hosted models and `classify` uses Method's classifier, so no model or classifier keys are needed. To keep the model that existing code uses, add `models: {writer: provider/model}` to the Method and use `model: writer` in the steps (or `model: provider/model` on the step); it needs no key. Keep the models that the Method or the existing code names: when a model step fails, show the error and ask before you change its model. Run records go to the user's account. When the user asks that run data stay on this computer or not be uploaded, set `run_data: device`: the run's inputs, outputs, and files stay here, and the account keeps only each step's status and timing. Model steps still send each step's input to the model to answer it; nothing is kept. Tell the user that in one line, then run again.\n7. **Keys stay out of chat.** Declare each key that a script needs under `secrets:` with its purpose; every script of the Method receives all of its declared secrets. Run `method secret find` in the Method's folder: it lists the key files nearby and the names in each, never the values, and prints the import command. Run that command and tell the user which file each key came from: the key stays on this computer, so there is nothing to ask. If it finds nothing, ask the user to run `method secret set NAME`, which opens a private form in their browser. Never open, print, or search a key file (`cat`, `grep`, an editor), including Method's own secret store, and never ask for a value in chat: the values would go into the chat. When a run says Method's model credit is used up, run `method config model-key` yourself: it takes the user's own OpenRouter key from the one nearby key file that holds it, or opens a private form for it. Then run again.\n8. **Choose a sample yourself** from the user's data, and check that it has the sources the Method needs. Ask only when there is no good sample.\n9. **Iterate.** `method run` prints a `dashboard` link when the run starts and again with its result. Give the user the link as soon as the run starts. After a good run, show the result and the link, and ask what to change. Change the step and run again. Show only results that a run made: never write or edit a result by hand, and fix a wrong result in the Method, not in the data it reads. If you cannot run, say so.\n10. **Publish** with `method publish FILE --reason TEXT` when the user wants to share or schedule a version. It runs the Method's cases first.\n11. **Talk about the work, not about Method.** Unless the user asks, do not mention Method's versions, formats, settings files, or other internal files, and do not ask the user about them, about models, or about which saved version to use. Method updates itself and converts older Method files when it runs them. When the user asks whether a Method works, or asks you to make it work, run it with the inputs of a recent run and show the result and the dashboard link in a few sentences. Say that it works only after a run completed.\n12. **One file for each Method.** Change and run a Method in its own file. Do not copy it to a temporary or other folder to change it: Method does not run or save the copy while the Method's file exists, and names that file.\n13. **Questions in a run are for the user.** When a run stops with `needs_input`, ask the user its `question` in plain words, wait for the answer, and continue the run with it as the output says. Never answer it yourself.\n\nWhen a run fails, read its `fix` and `diagnostics`, change the step, and run again.\n";
9
9
  /** How to write the prompt inside a call, agent, or classify step. */
10
10
  export declare const promptRules = "# Write each prompt\n\n- **One task per prompt.** If a prompt says \"then\" or has several jobs, make several steps.\n- **Say what to do.** Leave out background that does not change the output.\n- **Show 1 to 3 examples of good output.** Take them from the user's work: examples in an existing prompt, a past output that the user approved, or the first run that the user accepts. Pass a long example as an input, not as text in the prompt.\n- **Put the output shape in `out`**, not in the prompt.\n- **Say what to do when the input does not have the answer**, for example \"leave due empty\". For classify, add an option such as `unclear`.\n\nBefore:\n\n```text\nYou are an expert support analyst with years of experience. Our company values clear\ncommunication. Read the tickets, decide which ones are urgent, write a summary, and\nreturn JSON with a \"summary\" key. Make it good.\n```\n\nAfter (urgency is a classify step before this one; the shape is in `out`):\n\n```text\nWrite a five-sentence summary of this week's support tickets for the team.\nStart with the high-urgency tickets. Quote no customer names.\nWrite it in the style of this summary from an earlier week:\n\n{{example}}\n```\n";
11
11
  /** Enough of the format to write a Method without reading the JSON schema. */
@@ -37,7 +37,7 @@ export const firstMethodRules = `# Build a Method
37
37
  6. **Use the defaults without asking.** Model steps use the account's hosted models and \`classify\` uses Method's classifier, so no model or classifier keys are needed. To keep the model that existing code uses, add \`models: {writer: provider/model}\` to the Method and use \`model: writer\` in the steps (or \`model: provider/model\` on the step); it needs no key. Keep the models that the Method or the existing code names: when a model step fails, show the error and ask before you change its model. Run records go to the user's account. When the user asks that run data stay on this computer or not be uploaded, set \`run_data: device\`: the run's inputs, outputs, and files stay here, and the account keeps only each step's status and timing. Model steps still send each step's input to the model to answer it; nothing is kept. Tell the user that in one line, then run again.
38
38
  7. **Keys stay out of chat.** Declare each key that a script needs under \`secrets:\` with its purpose; every script of the Method receives all of its declared secrets. Run \`method secret find\` in the Method's folder: it lists the key files nearby and the names in each, never the values, and prints the import command. Run that command and tell the user which file each key came from: the key stays on this computer, so there is nothing to ask. If it finds nothing, ask the user to run \`method secret set NAME\`, which opens a private form in their browser. Never open, print, or search a key file (\`cat\`, \`grep\`, an editor), including Method's own secret store, and never ask for a value in chat: the values would go into the chat. When a run says Method's model credit is used up, run \`method config model-key\` yourself: it takes the user's own OpenRouter key from the one nearby key file that holds it, or opens a private form for it. Then run again.
39
39
  8. **Choose a sample yourself** from the user's data, and check that it has the sources the Method needs. Ask only when there is no good sample.
40
- 9. **Iterate.** After a good run, show the result and the dashboard link, and ask what to change. Change the step and run again. Show only results that a run made: never write or edit a result by hand, and fix a wrong result in the Method, not in the data it reads. If you cannot run, say so.
40
+ 9. **Iterate.** \`method run\` prints a \`dashboard\` link when the run starts and again with its result. Give the user the link as soon as the run starts. After a good run, show the result and the link, and ask what to change. Change the step and run again. Show only results that a run made: never write or edit a result by hand, and fix a wrong result in the Method, not in the data it reads. If you cannot run, say so.
41
41
  10. **Publish** with \`method publish FILE --reason TEXT\` when the user wants to share or schedule a version. It runs the Method's cases first.
42
42
  11. **Talk about the work, not about Method.** Unless the user asks, do not mention Method's versions, formats, settings files, or other internal files, and do not ask the user about them, about models, or about which saved version to use. Method updates itself and converts older Method files when it runs them. When the user asks whether a Method works, or asks you to make it work, run it with the inputs of a recent run and show the result and the dashboard link in a few sentences. Say that it works only after a run completed.
43
43
  12. **One file for each Method.** Change and run a Method in its own file. Do not copy it to a temporary or other folder to change it: Method does not run or save the copy while the Method's file exists, and names that file.
@@ -145,7 +145,7 @@ export async function runCurrentFile(file, flags, syncFactory, onEvent, client =
145
145
  });
146
146
  runFailed = !['completed', 'unconfirmed'].includes(result.status);
147
147
  const synced = await sync?.finish();
148
- let display = synced ? { ...result, dashboard_sync: synced } : result;
148
+ let display = synced ? { ...result, dashboard: sync.dashboard, dashboard_sync: synced } : result;
149
149
  // A run that waits for a person shows the question itself, so the agent can ask the user and pass on the answer.
150
150
  const question = result.status === 'needs_input' ? (await import('./worker.js')).lastQuestion(authoringPath(flags['run-dir'])) : null;
151
151
  if (question)
@@ -82,7 +82,9 @@ async function accountSync(path, flags) {
82
82
  return undefined;
83
83
  }
84
84
  const version = await prepareVersion(client, outbox, path);
85
- return { client, outbox, version, sync: () => new Sync(client, runDir, version.method_id, version.version_id, undefined, method.run_data === "device", outbox) };
85
+ // A run started by the run worker keeps the ID that its start line linked to.
86
+ const identity = join(runDir, "run-id.json"), runId = existsSync(identity) ? JSON.parse(readFileSync(identity, "utf8")).id : undefined;
87
+ return { client, outbox, version, sync: () => new Sync(client, runDir, version.method_id, version.version_id, runId, method.run_data === "device", outbox) };
86
88
  }
87
89
  catch (error) {
88
90
  // A copy of a Method that is saved from another file must not run: the change belongs in that file.
@@ -13,7 +13,7 @@ export const commandHelp = {
13
13
  "new-id": { usage: "method new-id FILE", purpose: "Make a copied Method file a new Method.", arguments: "Writes a new id: line. A copy that keeps its id: saves to the same Method.", result: "JSON with file and method_id.", errors: "Missing file.", example: "method new-id copy.method" },
14
14
  bind: { usage: "method bind FILE_OR_ID NAME (--file FOLDER | --connection URL) [--upload]", purpose: "Save a named input location or connection.", arguments: "Default: this computer only, in ~/.config/method/computer.json under the Method's ID (a FILE gets its id: line). A folder named NAME beside the Method needs no binding. --upload saves only the selected input folder or connection URL in the account. It never scans your disk. Keep credentials in the service's normal sign-in store.", result: "Saved binding and scope.", errors: "Missing input, invalid name, or unsafe path.", example: "method bind METHOD_ID prepared_day --file day-records --upload", remote: true },
15
15
  state: { usage: "method state ID [--enable --file state.json | --release RUN_ID]", purpose: "Read or explicitly enable shared account state.", arguments: "Accepted state updates use revision checks. Inspect a stopped run's external actions before releasing its ownership.", result: "Current revision, value, and owner run.", errors: "Concurrent ownership or stale revision. Existing state is never silently overwritten.", example: "method state METHOD_ID --enable --file initial-state.json", remote: true },
16
- wait: { usage: "method wait RUN_DIRECTORY", purpose: "Reconnect to the same local worker.", arguments: "Use the directory returned by run. Closing this output connection leaves the worker active.", result: "Live output and final worker status.", errors: "Stopped process or missing run.", example: "method wait .runs/example" },
16
+ wait: { usage: "method wait RUN_DIRECTORY", purpose: "Reconnect to the same local worker.", arguments: "Use the directory returned by run. Closing this output connection leaves the worker active.", result: "Live output, then the final worker status with the dashboard link of a synced run.", errors: "Stopped process or missing run.", example: "method wait .runs/example" },
17
17
  'run-status': { usage: "method run-status RUN_DIRECTORY", purpose: "Read worker status without waiting.", arguments: "Local run directory.", result: "Worker status and whether its process is active.", errors: "Unreadable run directory.", example: "method run-status .runs/example" },
18
18
  cancel: { usage: "method cancel RUN_DIRECTORY", purpose: "Stop a local run process.", arguments: "Inspect uncertain external actions before any explicit retry.", result: "Cancellation request. The checkpoint remains available.", errors: "Unreadable run directory.", example: "method cancel .runs/example" },
19
19
  progress: { usage: "method progress --message TEXT [--completed N --total N --unit NAME] [--child NAME]\nmethod progress --codex --child NAME", purpose: "Report public progress from a running script or relay a child Codex JSON stream.", arguments: "METHOD_PROGRESS_FD is supplied by the executor. --codex reads JSON lines from stdin; --message sends one message. Do not include secrets or source contents.", result: "Writes to the separate progress pipe. No stdout output. No-op outside a Method process.", errors: "Invalid arguments. Malformed Codex events are ignored.", example: "method progress --message 'Rendered 12 of 40 pages' --completed 12 --total 40 --unit pages" },
@@ -65,7 +65,7 @@ export const commandHelp = {
65
65
  --fresh: run every step; reuse nothing.
66
66
  --human FILE: answers for ask steps, as {steps: {"STEP": {outputs: {...}}}} (STEP:ITERATION, counted from 0, for a step with each or repeat).
67
67
  --verbose: print runtime events.
68
- Use method doctor to check the installed Node and configured tools.`, result: "Progress and final status text; local result.json and run evidence; dashboard run link when synced. The runtime executes the method's declared scripts, calls, agents, and checks. Executes trusted local processes; changes declarations do not enforce permissions. Runs exit 0 on completion, 1 on failure, 2 when human input is needed, and 3 when an observer could not confirm an external change (unconfirmed).", errors: "Missing inputs/access, failed check, timeout, unsafe resume/version mismatch, upload failure. See recovery. Never retry a business write without inspecting its saved changes.", example: "method run wf_example --version v_example --inputs inputs.json", remote: true },
68
+ Use method doctor to check the installed Node and configured tools.`, result: "When signed in, the start line and the final result have dashboard: the link to the run's page; give it to the user when the run starts. Progress and final status text; local result.json and run evidence. The runtime executes the method's declared scripts, calls, agents, and checks. Executes trusted local processes; changes declarations do not enforce permissions. Runs exit 0 on completion, 1 on failure, 2 when human input is needed, and 3 when an observer could not confirm an external change (unconfirmed).", errors: "Missing inputs/access, failed check, timeout, unsafe resume/version mismatch, upload failure. See recovery. Never retry a business write without inspecting its saved changes.", example: "method run wf_example --version v_example --inputs inputs.json", remote: true },
69
69
  observe: { usage: "method observe [RUN_DIRECTORY...] [--pending ROOT]...", purpose: "Make the effect observations that are due for finished runs.", arguments: "Without directories, checks runs with open effects under .method-runs and the Method cache. Runs only observers and judges; never repeats an action. Schedule it, for example hourly, so late evidence such as a bounce reaches the run.", result: "JSON with each run's new verdicts, status, and next observation time. A synced run whose status changed is uploaded again.", errors: "Locked run, changed bundle, or a missing observer credential.", example: "method observe --pending .method-runs" },
70
70
  test: { usage: "method test FILE [--case ID]... [--baseline OLD_FILE] [--new ID]... [--cases DIR] [--agent codex|claude]", purpose: "Replay recorded cases against this version of a Method. Every case must pass.", arguments: "Cases are in cases/ beside the Method. Unchanged steps return their recorded outputs; changed steps run; files connections are scratch folders, so a changed step that writes files runs safely. A changed step that asks a person or acts on a service makes the case unverifiable. --baseline also runs each case on the old version, to show what the change fixed or broke.", result: "JSON report with a verdict per case and passed:true when no case blocks the change. Exit 0 or 1.", errors: "Unknown case, invalid Method, or setup errors.", example: "method test task.method --baseline task-before.method --new bounce-reported" },
71
71
  case: { usage: "method case new|retire|list FILE ...", purpose: "Keep a correction as a recorded case that every later version must pass.", arguments: "Use method help case new, method help case retire, or method help case list.", result: "See the subcommand.", errors: "Unknown action. Choose new, retire, or list.", example: "method help case new" },
@@ -154,7 +154,7 @@ What this example shows:
154
154
 
155
155
  \`\`\`sh
156
156
  method validate tickets.method
157
- method run tickets.method --inputs inputs.json # prints the version and dashboard links
157
+ method run tickets.method --inputs inputs.json # prints the run's dashboard link at the start and with the result
158
158
  # change the summary prompt, then:
159
159
  method run tickets.method --inputs inputs.json # reuses read, urgency and join; runs summary
160
160
  \`\`\`
@@ -17,6 +17,8 @@ export declare class MethodSync {
17
17
  readonly outbox: Outbox;
18
18
  constructor(client: MethodClient, directory: string, workflowId: string, versionId: string, runId?: string, device?: boolean, outbox?: Outbox);
19
19
  get device(): boolean;
20
+ /** The run's dashboard page. Before the first record arrives, the page waits for it. */
21
+ get dashboard(): string;
20
22
  private get item();
21
23
  private save;
22
24
  private upload;
@@ -39,6 +41,8 @@ export declare class MethodSync {
39
41
  /** Send the final local record of a run. Never runs business actions. */
40
42
  static retry(directory: string, client?: MethodClient): Promise<void>;
41
43
  }
44
+ /** The dashboard page of the run in a run folder, when the run is linked to an account. */
45
+ export declare function runDashboard(directory: string): string | undefined;
42
46
  /**
43
47
  * The organization setting "Keep run content on devices". When it cannot be read, the run's content stays on this
44
48
  * computer: the server would refuse the content anyway when the setting is on.
@@ -62,6 +62,10 @@ export class MethodSync {
62
62
  get device() {
63
63
  return this.state.device === true;
64
64
  }
65
+ /** The run's dashboard page. Before the first record arrives, the page waits for it. */
66
+ get dashboard() {
67
+ return dashboardUrl(this.state);
68
+ }
65
69
  get item() {
66
70
  return { kind: "run", server: this.client.server, run_dir: this.directory, version_id: this.state.version_id, pid: process.pid };
67
71
  }
@@ -99,8 +103,6 @@ export class MethodSync {
99
103
  }
100
104
  async send(payload) {
101
105
  const result = await retryTransfer(() => this.client.request(`/api/cli/runs/${this.state.id}`, "PUT", payload, true, { stallMs: 60_000 }));
102
- if (!this.state.dashboard_id)
103
- process.stderr.write(`Dashboard: ${this.client.server}/runs/${result.id}\n`);
104
106
  this.state.dashboard_id = result.id;
105
107
  this.save();
106
108
  this.warned = false;
@@ -267,6 +269,15 @@ export class MethodSync {
267
269
  sync.outbox.remove(sync.item);
268
270
  }
269
271
  }
272
+ /** The dashboard page of a run: its saved ID, or before the first record, the ID that this computer gave it. */
273
+ function dashboardUrl(state) {
274
+ return `${state.server}/runs/${state.dashboard_id ?? state.id}`;
275
+ }
276
+ /** The dashboard page of the run in a run folder, when the run is linked to an account. */
277
+ export function runDashboard(directory) {
278
+ const path = join(directory, "method-sync.json");
279
+ return existsSync(path) ? dashboardUrl(SyncSchema.parse(JSON.parse(readFileSync(path, "utf8")))) : undefined;
280
+ }
270
281
  async function retryTransfer(send) {
271
282
  for (let attempt = 0;; attempt++)
272
283
  try {
@@ -41,7 +41,15 @@ async function dispatchRunWorker(args, flags, extra = []) {
41
41
  const workerArgs = [...args.filter(arg => arg !== '--background'), ...extra];
42
42
  if (!flags['run-dir'])
43
43
  workerArgs.push('--run-dir', directory);
44
- await startRunWorker(workerArgs, directory, flags.background);
44
+ // A new run of a signed-in computer is synced; a resumed run keeps the link that it has.
45
+ let server;
46
+ try {
47
+ const client = new MethodClient(flags.server);
48
+ if (!flags.resume && client.token())
49
+ server = client.server;
50
+ }
51
+ catch { /* Not signed in to this server. */ }
52
+ await startRunWorker(workerArgs, directory, flags.background, server);
45
53
  return true;
46
54
  }
47
55
  export async function methodMain(args = process.argv.slice(2), clientFactory = server => new MethodClient(server)) {
@@ -52,7 +52,7 @@ export async function runSaved(saved, flags, client) {
52
52
  setupEvents.push({ at: new Date().toISOString(), type: 'setup_started' });
53
53
  writePrivateJson(setupFile, setupEvents);
54
54
  await sync.start(saved.workflow, inputs, {});
55
- process.stderr.write(`Local run: ${directory}\n`);
55
+ process.stderr.write(`Local run: ${directory}\nDashboard: ${sync.dashboard}\n`);
56
56
  let acquired = false, started = false, revision = 0;
57
57
  const statePath = `/api/cli/methods/${encodeURIComponent(saved.workflow_id)}/state`;
58
58
  try {
@@ -1,4 +1,5 @@
1
- export declare function startRunWorker(args: string[], directory: string, background?: boolean): Promise<void>;
1
+ /** server: the signed-in Method server, so that the start line links to the run's dashboard page. */
2
+ export declare function startRunWorker(args: string[], directory: string, background?: boolean, server?: string): Promise<void>;
2
3
  export declare function workerAlive(directory: string): boolean;
3
4
  export declare function waitForRun(directory: string): Promise<any>;
4
5
  export declare function cancelRun(directory: string): {
@@ -4,7 +4,9 @@ import { existsSync, mkdirSync, openSync, closeSync, readFileSync, rmSync, write
4
4
  import { resolve, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { writePrivateJson } from './files.js';
7
- export async function startRunWorker(args, directory, background = false) {
7
+ import { runDashboard } from './method-sync.js';
8
+ /** server: the signed-in Method server, so that the start line links to the run's dashboard page. */
9
+ export async function startRunWorker(args, directory, background = false, server) {
8
10
  directory = resolve(directory);
9
11
  mkdirSync(directory, { recursive: true, mode: 0o700 });
10
12
  const file = join(directory, 'worker-request.json'), status = join(directory, 'worker.json');
@@ -47,7 +49,8 @@ export async function startRunWorker(args, directory, background = false) {
47
49
  await new Promise((yes, no) => { child.once('spawn', yes); child.once('error', no); });
48
50
  child.unref();
49
51
  // The child owns its status record after startup. Do not overwrite a fast completion.
50
- process.stdout.write(JSON.stringify({ status: 'started', run_id: runId, run_dir: directory, wait: `method wait ${JSON.stringify(directory)}`, cancel: `method cancel ${JSON.stringify(directory)}` }) + '\n');
52
+ const dashboard = runDashboard(directory) ?? (server ? `${server}/runs/${runId}` : undefined);
53
+ process.stdout.write(JSON.stringify({ status: 'started', run_id: runId, ...(dashboard ? { dashboard } : {}), run_dir: directory, wait: `method wait ${JSON.stringify(directory)}`, cancel: `method cancel ${JSON.stringify(directory)}` }) + '\n');
51
54
  const startupDeadline = Date.now() + 30_000;
52
55
  while (!existsSync(status)) {
53
56
  if (Date.now() > startupDeadline)
@@ -107,13 +110,14 @@ export async function waitForRun(directory) {
107
110
  const file = join(directory, 'worker.json');
108
111
  if (existsSync(file)) {
109
112
  const status = JSON.parse(readFileSync(file, 'utf8'));
113
+ const dashboard = runDashboard(directory), link = dashboard ? { dashboard } : {};
110
114
  if (status.status !== 'running') {
111
115
  process.exitCode = status.exit_code ?? 1;
112
- return status;
116
+ return { ...status, ...link };
113
117
  }
114
118
  if (!workerAlive(directory)) {
115
119
  process.exitCode = 1;
116
- return { status: 'interrupted', run_dir: directory, message: 'The worker stopped. Inspect its run record before resuming.' };
120
+ return { status: 'interrupted', run_dir: directory, ...link, message: 'The worker stopped. Inspect its run record before resuming.' };
117
121
  }
118
122
  }
119
123
  if (!existsSync(file) && Date.now() > deadline)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@method-ai-hq/sdk",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "description": "Build and run reusable .method files with checked steps and saved results.",
5
5
  "license": "MIT",
6
6
  "type": "module",