@dench.com/cli 3.6.4-staging.377 → 3.6.5-staging.384

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
@@ -465,3 +465,19 @@ Commands that need to impersonate a specific agent (`dench memory`,
465
465
  (`dench signin`) — the unified API key is org-scoped and cannot speak
466
466
  as a single agent. Those commands return a clear "agent session
467
467
  required" error in API-key mode.
468
+
469
+ ### Focused workspace context
470
+
471
+ `dench context --instructions` reads explicit IDENTITY, RULES and TOOLS notes,
472
+ plus document availability/revisions. It does not load business profiles,
473
+ personal profiles or aggregate memory. Fetch only what the task needs:
474
+
475
+ ```sh
476
+ dench context --sections organisation,user,memory --json
477
+ ```
478
+
479
+ Section names are `identity`, `organisation`, `user`, `memory`, `rules`, and
480
+ `tools`. Multiple names use one query. The existing `organisation show`,
481
+ `user show`, and `mem show` commands use the same saved documents; reading never
482
+ fills profiles or writes memory. Personal USER context is unavailable to shared
483
+ channel sessions. `dench context --json` keeps its existing workspace overview.
package/agent-config.ts CHANGED
@@ -215,22 +215,16 @@ async function handleSimpleMagicFile(
215
215
  ): Promise<void> {
216
216
  const sub = args[0];
217
217
  if (!sub || sub === "show") {
218
- const config = await loadAgentConfig(ctx);
219
- const value =
220
- opts.field === "memoryAggregate"
221
- ? config.agentConfig.memoryAggregate
222
- : opts.field === "toolsNotes"
223
- ? config.agentConfig.toolsNotes
224
- : opts.field === "identity"
225
- ? config.agentConfig.identity
226
- : opts.field === "organisation"
227
- ? config.agentConfig.organisation
228
- : null;
229
- if (opts.perMember) {
230
- out(ctx, config.userProfile?.content ?? "(empty)");
231
- return;
232
- }
233
- out(ctx, value?.content ?? "(empty)");
218
+ const context = (await runQuery(
219
+ ctx,
220
+ makeFunctionReference<"query">("functions/agentConfig:workspaceContext"),
221
+ { sections: [opts.label] },
222
+ )) as { documents: Array<{ name: string; content?: string }> };
223
+ out(
224
+ ctx,
225
+ context.documents.find((document) => document.name === opts.label)
226
+ ?.content || "(empty)",
227
+ );
234
228
  return;
235
229
  }
236
230
  if (sub === "edit" || sub === "set") {
package/app-sdk.d.ts CHANGED
@@ -497,10 +497,17 @@ export interface ApiRequests {
497
497
  organizationId?: string;
498
498
  newOrganizationName?: string;
499
499
  };
500
+ /** Read selected scoped workspace documents and a compact context index without writes. — `dench context --sections` — GET /api/v1/context/sections */
501
+ "workspace.context.sections": {
502
+ organizationId?: string;
503
+ sections?: Array<"identity" | "organisation" | "user" | "memory" | "rules" | "tools">;
504
+ };
500
505
  /** Return the current Dench workspace context for the bearer. — `dench context` — GET /api/v1/context */
501
506
  "workspace.context": Record<string, unknown>;
502
507
  /** Return the current workspace's standing instructions for external agents. — `dench context --instructions` — GET /api/v1/context/instructions */
503
- "workspace.instructions": Record<string, unknown>;
508
+ "workspace.instructions": {
509
+ organizationId?: string;
510
+ };
504
511
  /** Return workspace and agent status. — `dench status` — GET /api/v1/status */
505
512
  "workspace.status": Record<string, unknown>;
506
513
  /** List agents visible in the workspace status payload. — `dench agents` — GET /api/v1/agents */
@@ -2172,6 +2179,116 @@ export interface ApiRequests {
2172
2179
  /** Identity id, sender email, or domain (deletes every sender on the domain). Permanent: re-adding requires re-verification. */
2173
2180
  identity: string;
2174
2181
  };
2182
+ /** Create an editable Dench email draft and synchronize its selected native mailbox asynchronously. Use a stable requestId for retries. — `dench email draft create` — POST /api/v1/email/drafts */
2183
+ "email.drafts.create": {
2184
+ organizationId?: string;
2185
+ threadId?: string;
2186
+ mailbox?: string;
2187
+ requestId: string;
2188
+ to?: {
2189
+ email: string;
2190
+ name?: string;
2191
+ }[];
2192
+ cc?: {
2193
+ email: string;
2194
+ name?: string;
2195
+ }[];
2196
+ bcc?: {
2197
+ email: string;
2198
+ name?: string;
2199
+ }[];
2200
+ subject?: string;
2201
+ htmlBody?: string;
2202
+ textBody?: string;
2203
+ attachments?: {
2204
+ storageId: string;
2205
+ name: string;
2206
+ contentType: string;
2207
+ size: number;
2208
+ }[];
2209
+ };
2210
+ /** Read an email draft, eligible senders and provider sync status. — `dench email draft show` — GET /api/v1/email/drafts/{draftId} */
2211
+ "email.drafts.get": {
2212
+ draftId: string;
2213
+ };
2214
+ /** List native mailboxes this caller may use. — `dench email draft senders` — GET /api/v1/email/drafts/senders */
2215
+ "email.drafts.senders": {
2216
+ organizationId?: string;
2217
+ };
2218
+ /** Save draft content using expectedRevision; sender changes require a new draft after provider binding. — `dench email draft update` — PATCH /api/v1/email/drafts/{draftId} */
2219
+ "email.drafts.update": {
2220
+ draftId: string;
2221
+ expectedRevision: number;
2222
+ patch: {
2223
+ mailboxAccountId?: string;
2224
+ to?: {
2225
+ email: string;
2226
+ name?: string;
2227
+ }[];
2228
+ cc?: {
2229
+ email: string;
2230
+ name?: string;
2231
+ }[];
2232
+ bcc?: {
2233
+ email: string;
2234
+ name?: string;
2235
+ }[];
2236
+ subject?: string;
2237
+ htmlBody?: string;
2238
+ textBody?: string;
2239
+ attachments?: {
2240
+ storageId: string;
2241
+ name: string;
2242
+ contentType: string;
2243
+ size: number;
2244
+ }[];
2245
+ };
2246
+ };
2247
+ /** Send the current Dench draft revision through its native mailbox. Repeated requests share a durable receipt. — `dench email draft send` — POST /api/v1/email/drafts/{draftId}/send */
2248
+ "email.drafts.send": {
2249
+ draftId: string;
2250
+ expectedRevision: number;
2251
+ requestId?: string;
2252
+ };
2253
+ /** Upload attachment bytes authorized against this draft before adding its storage reference. — `dench email draft attach` — POST /api/v1/email/drafts/{draftId}/attachments */
2254
+ "email.drafts.upload": {
2255
+ draftId: string;
2256
+ name: string;
2257
+ contentType: string;
2258
+ contentBase64: string;
2259
+ };
2260
+ /** Load the selected mailbox signature for explicit visible insertion. — `dench email draft signature` — GET /api/v1/email/drafts/{draftId}/signature */
2261
+ "email.drafts.signature": {
2262
+ draftId: string;
2263
+ };
2264
+ /** Send through a native Gmail or Outlook mailbox with a durable request receipt. Only use for an explicit send request. — `dench email send --mailbox` — POST /api/v1/email/native/send */
2265
+ "email.native.send": {
2266
+ organizationId?: string;
2267
+ threadId?: string;
2268
+ mailbox?: string;
2269
+ requestId: string;
2270
+ to?: {
2271
+ email: string;
2272
+ name?: string;
2273
+ }[];
2274
+ cc?: {
2275
+ email: string;
2276
+ name?: string;
2277
+ }[];
2278
+ bcc?: {
2279
+ email: string;
2280
+ name?: string;
2281
+ }[];
2282
+ subject?: string;
2283
+ htmlBody?: string;
2284
+ textBody?: string;
2285
+ attachments?: {
2286
+ storageId: string;
2287
+ name: string;
2288
+ contentType: string;
2289
+ size: number;
2290
+ }[];
2291
+ };
2175
2292
  /** Send one raw email (no campaign): to/cc/bcc, custom from-name and reply-to, optional reply threading via replyToMessageId. — `dench email send` — POST /api/v1/email/send */
2176
2293
  "email.send": {
2177
2294
  /** Verified sender mailbox. */
@@ -3017,17 +3134,25 @@ export interface ApiRequests {
3017
3134
  /** Create a tool OAuth connection link. Slack is in-house, never a third-party connection: for toolkit slack the CLI prints the first-party install URL (/api/slack/install?slug=<workspace>, org admin) instead of calling this endpoint. — `dench tool connect` — POST /api/v1/tools/connections */
3018
3135
  "tool.connect": {
3019
3136
  /** Toolkit slug, e.g. github, gmail, stripe. */
3020
- toolkit: string;
3137
+ toolkit?: string;
3138
+ toolkit_slug?: string;
3021
3139
  /** Optional OAuth callback URL. */
3022
3140
  callback_url?: string;
3141
+ /** Native OAuth return path within the workspace. */
3142
+ returnTo?: string;
3023
3143
  };
3024
3144
  /** Search for external tool actions. — `dench tool search` — POST /api/v1/tools/search */
3025
3145
  "tool.search": {
3026
- queries: {
3146
+ queries?: {
3027
3147
  /** Natural-language use case. */
3028
3148
  use_case: string;
3029
3149
  known_fields?: string;
3030
3150
  }[];
3151
+ query?: string;
3152
+ toolkit?: string;
3153
+ toolkit_slug?: string;
3154
+ limit?: number;
3155
+ important?: boolean;
3031
3156
  session?: {
3032
3157
  id?: string;
3033
3158
  generate_id?: boolean;
@@ -3045,6 +3170,8 @@ export interface ApiRequests {
3045
3170
  /** Tool arguments object. */
3046
3171
  arguments?: Record<string, unknown>;
3047
3172
  account?: string;
3173
+ connected_account_id?: string;
3174
+ approvalId?: string;
3048
3175
  };
3049
3176
  /** Disconnect an external tool account. — `dench tool disconnect` — DELETE /api/v1/tools/connections/{connectionId} */
3050
3177
  "tool.disconnect": {
@@ -3374,6 +3501,7 @@ export interface ApiResponses {
3374
3501
  sessionExpiresAt?: number;
3375
3502
  };
3376
3503
  };
3504
+ "workspace.context.sections": Record<string, unknown>;
3377
3505
  "workspace.context": {
3378
3506
  workspace: {
3379
3507
  id: string;
@@ -5319,6 +5447,54 @@ export interface ApiResponses {
5319
5447
  disabled: boolean;
5320
5448
  }[];
5321
5449
  };
5450
+ "email.drafts.create": {
5451
+ ok: boolean;
5452
+ kind: "email";
5453
+ draftId: string;
5454
+ syncStatus: string;
5455
+ revision: number;
5456
+ [key: string]: unknown;
5457
+ };
5458
+ "email.drafts.get": {
5459
+ ok: boolean;
5460
+ kind: "email";
5461
+ draftId: string;
5462
+ syncStatus: string;
5463
+ revision: number;
5464
+ [key: string]: unknown;
5465
+ };
5466
+ "email.drafts.senders": Record<string, unknown>[];
5467
+ "email.drafts.update": {
5468
+ ok: boolean;
5469
+ kind: "email";
5470
+ draftId: string;
5471
+ syncStatus: string;
5472
+ revision: number;
5473
+ [key: string]: unknown;
5474
+ };
5475
+ "email.drafts.send": {
5476
+ ok: boolean;
5477
+ kind: "email";
5478
+ draftId: string;
5479
+ syncStatus: string;
5480
+ revision: number;
5481
+ [key: string]: unknown;
5482
+ };
5483
+ "email.drafts.upload": {
5484
+ storageId: string;
5485
+ name: string;
5486
+ contentType: string;
5487
+ size: number;
5488
+ };
5489
+ "email.drafts.signature": Record<string, unknown>;
5490
+ "email.native.send": {
5491
+ ok: boolean;
5492
+ kind: "email";
5493
+ draftId: string;
5494
+ syncStatus: string;
5495
+ revision: number;
5496
+ [key: string]: unknown;
5497
+ };
5322
5498
  "email.send": {
5323
5499
  ok: boolean;
5324
5500
  /** Dench message id for `dench email message status`. */
@@ -6567,6 +6743,14 @@ export interface ApiResponses {
6567
6743
  /** OAuth URL the user opens to finish connecting. */
6568
6744
  redirect_url?: string;
6569
6745
  connection_id?: string;
6746
+ redirectUrl?: string;
6747
+ link?: string;
6748
+ artifact?: {
6749
+ kind: "connect";
6750
+ data: {
6751
+ toolkit: string;
6752
+ };
6753
+ };
6570
6754
  [key: string]: unknown;
6571
6755
  };
6572
6756
  "tool.search": {
@@ -6592,10 +6776,13 @@ export interface ApiResponses {
6592
6776
  /** Tool slug -> schema with gateway-added execution_ref for tool.run. */
6593
6777
  tool_schemas?: Record<string, Record<string, unknown>>;
6594
6778
  /** Tool-router session; reuse session.id for follow-up calls. */
6595
- session: {
6779
+ session?: {
6596
6780
  id: string;
6597
6781
  [key: string]: unknown;
6598
6782
  };
6783
+ items?: Record<string, unknown>[];
6784
+ nativeAvailable?: boolean;
6785
+ available?: boolean;
6599
6786
  execution_ref_version?: number;
6600
6787
  [key: string]: unknown;
6601
6788
  };
@@ -7810,6 +7997,22 @@ export type DenchApiTree = {
7810
7997
  /** Submit a campaign for approval or sending. (`dench email campaign submit`) */
7811
7998
  submit(args: Req<"email.campaign.submit">): Promise<Res<"email.campaign.submit">>;
7812
7999
  };
8000
+ drafts: {
8001
+ /** Create an editable Dench email draft and synchronize its selected native mailbox asynchronously. Use a stable requestId for retries. (`dench email draft create`) */
8002
+ create(args: Req<"email.drafts.create">): Promise<Res<"email.drafts.create">>;
8003
+ /** Read an email draft, eligible senders and provider sync status. (`dench email draft show`) */
8004
+ get(args: Req<"email.drafts.get">): Promise<Res<"email.drafts.get">>;
8005
+ /** Send the current Dench draft revision through its native mailbox. Repeated requests share a durable receipt. (`dench email draft send`) */
8006
+ send(args: Req<"email.drafts.send">): Promise<Res<"email.drafts.send">>;
8007
+ /** List native mailboxes this caller may use. (`dench email draft senders`) */
8008
+ senders(args?: Req<"email.drafts.senders">): Promise<Res<"email.drafts.senders">>;
8009
+ /** Load the selected mailbox signature for explicit visible insertion. (`dench email draft signature`) */
8010
+ signature(args: Req<"email.drafts.signature">): Promise<Res<"email.drafts.signature">>;
8011
+ /** Save draft content using expectedRevision; sender changes require a new draft after provider binding. (`dench email draft update`) */
8012
+ update(args: Req<"email.drafts.update">): Promise<Res<"email.drafts.update">>;
8013
+ /** Upload attachment bytes authorized against this draft before adding its storage reference. (`dench email draft attach`) */
8014
+ upload(args: Req<"email.drafts.upload">): Promise<Res<"email.drafts.upload">>;
8015
+ };
7813
8016
  identity: {
7814
8017
  /** Begin the full Dench sender verification flow for a sending identity. (`dench email identity verify`) */
7815
8018
  beginVerification(args: Req<"email.identity.beginVerification">): Promise<Res<"email.identity.beginVerification">>;
@@ -7838,6 +8041,10 @@ export type DenchApiTree = {
7838
8041
  /** List recent raw email messages for the workspace. (`dench email message list`) */
7839
8042
  list(args?: Req<"email.message.list">): Promise<Res<"email.message.list">>;
7840
8043
  };
8044
+ native: {
8045
+ /** Send through a native Gmail or Outlook mailbox with a durable request receipt. Only use for an explicit send request. (`dench email send --mailbox`) */
8046
+ send(args: Req<"email.native.send">): Promise<Res<"email.native.send">>;
8047
+ };
7841
8048
  /** Send one raw email (no campaign): to/cc/bcc, custom from-name and reply-to, optional reply threading via replyToMessageId. (`dench email send`) */
7842
8049
  send(args: Req<"email.send">): Promise<Res<"email.send">>;
7843
8050
  sequence: {
@@ -8126,8 +8333,13 @@ export type DenchApiTree = {
8126
8333
  /** List artifacts for the authenticated workspace. (`dench artifacts`) */
8127
8334
  list(args?: Req<"workspace.artifacts.list">): Promise<Res<"workspace.artifacts.list">>;
8128
8335
  };
8129
- /** Return the current Dench workspace context for the bearer. (`dench context`) */
8130
- context(args?: Req<"workspace.context">): Promise<Res<"workspace.context">>;
8336
+ context: {
8337
+ /** Return the current Dench workspace context for the bearer. (`dench context`) */
8338
+ (args?: Req<"workspace.context">): Promise<Res<"workspace.context">>;
8339
+ $call(args?: Req<"workspace.context">): Promise<Res<"workspace.context">>;
8340
+ /** Read selected scoped workspace documents and a compact context index without writes. (`dench context --sections`) */
8341
+ sections(args?: Req<"workspace.context.sections">): Promise<Res<"workspace.context.sections">>;
8342
+ };
8131
8343
  /** Return the current workspace's standing instructions for external agents. (`dench context --instructions`) */
8132
8344
  instructions(args?: Req<"workspace.instructions">): Promise<Res<"workspace.instructions">>;
8133
8345
  /** Return workspace and agent status. (`dench status`) */
@@ -8555,6 +8767,22 @@ export interface DenchCampaigns {
8555
8767
  }
8556
8768
 
8557
8769
  export interface DenchEmail {
8770
+ /** Create a native mailbox draft with a stable request receipt. Permission: `email:write`. Wraps `email.drafts.create`. */
8771
+ createDraft(draft: Req<"email.drafts.create">): Promise<Res<"email.drafts.create">>;
8772
+ /** Read a native email draft and sync status. Permission: `email:read`. Wraps `email.drafts.get`. */
8773
+ draft(draftId: string): Promise<Res<"email.drafts.get">>;
8774
+ /** Save the next email draft revision. Permission: `email:write`. Wraps `email.drafts.update`. */
8775
+ updateDraft(input: Req<"email.drafts.update">): Promise<Res<"email.drafts.update">>;
8776
+ /** Send the frozen native email draft revision. Permission: `email:write`. Wraps `email.drafts.send`. */
8777
+ sendDraft(input: Req<"email.drafts.send">): Promise<Res<"email.drafts.send">>;
8778
+ /** List eligible native mailboxes. Permission: `email:read`. Wraps `email.drafts.senders`. */
8779
+ senders(opts?: Req<"email.drafts.senders">): Promise<Res<"email.drafts.senders">>;
8780
+ /** Upload attachment bytes for a native draft. Permission: `email:write`. Wraps `email.drafts.upload`. */
8781
+ uploadAttachment(input: Req<"email.drafts.upload">): Promise<Res<"email.drafts.upload">>;
8782
+ /** Load the selected mailbox signature for visible insertion. Permission: `email:read`. Wraps `email.drafts.signature`. */
8783
+ signature(draftId: string): Promise<Res<"email.drafts.signature">>;
8784
+ /** Explicitly send through a native Gmail or Outlook mailbox. Permission: `email:write`. Wraps `email.native.send`. */
8785
+ sendFromMailbox(message: Req<"email.native.send">): Promise<Res<"email.native.send">>;
8558
8786
  /** Send one email from a verified identity. Permission: `email:write`. Wraps `email.send`. */
8559
8787
  send(message: Req<"email.send">): Promise<Res<"email.send">>;
8560
8788
  /** Sent messages. Permission: `email:read`. Wraps `email.message.list`. */
package/dench.ts CHANGED
@@ -32,7 +32,6 @@ import { cliVersion } from "./lib/cli-version";
32
32
  import { denchConfigDirectory } from "./lib/config-path.mjs";
33
33
  import { resolveOrganizationBySelector } from "./lib/organizationSelector";
34
34
  import { backendErrorText } from "./lib/public-error";
35
- import { normalizeUnipileToolkitSlug } from "./lib/unipile-toolkits";
36
35
  import { formatApprovalOpenMessage, openUrl } from "./openUrl";
37
36
  import {
38
37
  explicitSessionKeyInput,
@@ -176,6 +175,9 @@ const api = {
176
175
  ),
177
176
  },
178
177
  agentConfig: {
178
+ workspaceContext: makeFunctionReference<"query">(
179
+ "functions/agentConfig:workspaceContext",
180
+ ),
179
181
  workspaceInstructions: makeFunctionReference<"query">(
180
182
  "functions/agentConfig:workspaceInstructions",
181
183
  ),
@@ -465,6 +467,7 @@ Usage:
465
467
  dench logout [session-key-or-workspace-slug] [--session <key-or-scope>] [--host <host>] [--all] [--json]
466
468
  dench backend [show|set|clear] [<production|staging|local|<url>>] [--json]
467
469
  dench context [--instructions] [--json]
470
+ dench context --sections organisation,user,memory [--json]
468
471
  dench instructions [--json]
469
472
  dench status [--mine|--self] [--json]
470
473
  dench memory search "query" [--limit 8] [--json]
@@ -742,6 +745,7 @@ function contextHelp() {
742
745
 
743
746
  Usage:
744
747
  dench context [--instructions] [--json]
748
+ dench context --sections organisation,user,memory [--json]
745
749
  dench instructions [--json]
746
750
 
747
751
  Shows the current workspace, current agent, assigned tasks, pending approvals
@@ -3222,19 +3226,22 @@ function formatContext(context: JsonRecord) {
3222
3226
 
3223
3227
  async function buildWorkspaceInstructionsContext(
3224
3228
  runtime: Awaited<ReturnType<typeof getRuntime>>,
3229
+ sections?: string[],
3225
3230
  ) {
3226
3231
  if (runtime.mode === "dev") {
3227
3232
  return (await runtime.client.query(
3228
3233
  api.functions.agentConfig.devWorkspaceInstructions,
3229
- runtime.workspaceArgs,
3234
+ { ...runtime.workspaceArgs, ...(sections ? { sections } : {}) },
3230
3235
  )) as JsonRecord;
3231
3236
  }
3232
3237
  if (runtime.mode !== "session" && runtime.mode !== "apiKey") {
3233
3238
  throw loginRequiredError("dench context --instructions");
3234
3239
  }
3235
3240
  return (await runtime.client.query(
3236
- api.functions.agentConfig.workspaceInstructions,
3237
- { sessionToken: runtime.sessionToken },
3241
+ sections
3242
+ ? api.functions.agentConfig.workspaceContext
3243
+ : api.functions.agentConfig.workspaceInstructions,
3244
+ { sessionToken: runtime.sessionToken, ...(sections ? { sections } : {}) },
3238
3245
  )) as JsonRecord;
3239
3246
  }
3240
3247
 
@@ -4801,7 +4808,14 @@ async function main() {
4801
4808
  | Awaited<ReturnType<typeof resolveGatewayCommandAuth>>
4802
4809
  | undefined;
4803
4810
  try {
4804
- gatewayAuth = await resolveGatewayCommandAuth(runtime, "dench email");
4811
+ if (
4812
+ subArgs[0] !== "draft" &&
4813
+ !subArgs.some(
4814
+ (arg) => arg === "--mailbox" || arg.startsWith("--mailbox="),
4815
+ )
4816
+ ) {
4817
+ gatewayAuth = await resolveGatewayCommandAuth(runtime, "dench email");
4818
+ }
4805
4819
  } catch {
4806
4820
  gatewayAuth = undefined;
4807
4821
  }
@@ -4882,35 +4896,16 @@ async function main() {
4882
4896
  if (argsIndex !== -1) parseJson(filteredSubArgs[argsIndex + 1]);
4883
4897
  }
4884
4898
  const runtime = await getRuntime();
4885
- const isSlackConnect =
4886
- sub === "connect" &&
4887
- ["slack", "slackbot"].includes(
4888
- (filteredSubArgs[1] ?? "").trim().toLowerCase(),
4889
- );
4890
- const isUnipileCommand =
4891
- (sub === "connect" || sub === "status") &&
4892
- normalizeUnipileToolkitSlug(filteredSubArgs[1] ?? "") !== null;
4893
- let gatewayAuth: GatewayCommandAuth | null = null;
4894
- let gatewayAuthError: string | undefined;
4895
- if (!isSlackConnect && !isUnipileCommand) {
4896
- try {
4897
- gatewayAuth = await resolveGatewayCommandAuth(runtime, "dench tool");
4898
- } catch (error) {
4899
- if (sub !== "status") throw error;
4900
- gatewayAuthError = gatewayAuthFailureReason(error);
4901
- }
4902
- }
4903
4899
  await runToolCommand({
4904
4900
  args: filteredSubArgs,
4905
4901
  jsonOutput: json,
4906
- gatewayAuthError,
4907
- ...(gatewayAuth
4908
- ? {
4909
- bearerToken: gatewayAuth.bearerToken,
4910
- gatewayBaseUrl: gatewayAuth.gatewayBaseUrl,
4911
- gatewayHeaders: gatewayAuth.gatewayHeaders,
4912
- }
4913
- : {}),
4902
+ resolveGatewayAuth: async () => {
4903
+ try {
4904
+ return await resolveGatewayCommandAuth(runtime, "dench tool");
4905
+ } catch (error) {
4906
+ return { gatewayAuthError: gatewayAuthFailureReason(error) };
4907
+ }
4908
+ },
4914
4909
  ...unipileQueryAuth(runtime),
4915
4910
  ...(runtime.mode !== "dev"
4916
4911
  ? {
@@ -5261,6 +5256,44 @@ async function main() {
5261
5256
  return;
5262
5257
  }
5263
5258
 
5259
+ if (command === "context" && args.includes("--sections")) {
5260
+ const raw = args[args.indexOf("--sections") + 1];
5261
+ const sections = raw
5262
+ ?.split(",")
5263
+ .map((section) => section.trim().toLowerCase())
5264
+ .filter(Boolean);
5265
+ const allowed = [
5266
+ "identity",
5267
+ "organisation",
5268
+ "user",
5269
+ "memory",
5270
+ "rules",
5271
+ "tools",
5272
+ ];
5273
+ if (
5274
+ !sections?.length ||
5275
+ sections.some((section) => !allowed.includes(section))
5276
+ )
5277
+ throw new Error(
5278
+ `Usage: dench context --sections ${allowed.join(",")} [--json]`,
5279
+ );
5280
+ const context = await buildWorkspaceInstructionsContext(runtime, [
5281
+ ...new Set(sections),
5282
+ ]);
5283
+ const documents = Array.isArray(context.documents)
5284
+ ? (context.documents as Array<{ name: string; content?: string }>)
5285
+ : [];
5286
+ print(
5287
+ json
5288
+ ? context
5289
+ : documents
5290
+ .filter((doc) => doc.content !== undefined)
5291
+ .map((doc) => `## ${doc.name}\n${doc.content || "(empty)"}`)
5292
+ .join("\n\n"),
5293
+ );
5294
+ return;
5295
+ }
5296
+
5264
5297
  if (command === "context" && args.includes("--instructions")) {
5265
5298
  const instructions = await buildWorkspaceInstructionsContext(runtime);
5266
5299
  print(