iit-mcp-autotask 0.63.12 → 0.63.13
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/capabilities.json +2 -2
- package/dist/access/write-env.js +8 -0
- package/dist/policy.d.ts +5 -1
- package/dist/policy.js +17 -2
- package/dist/tools/catalog-data.d.ts +1 -1
- package/dist/tools/catalog-data.js +1 -1
- package/dist/tools/meta.js +44 -12
- package/dist/tools/write/apply.d.ts +0 -3
- package/dist/tools/write/apply.js +6 -4
- package/dist/tools/write/common.d.ts +3 -1
- package/dist/tools/write/common.js +2 -0
- package/dist/tools/write/facts.d.ts +1 -1
- package/dist/tools/write/facts.js +10 -1
- package/dist/tools/write/outcome.d.ts +1 -1
- package/dist/tools/write/outcome.js +23 -8
- package/dist/tools/write/preview.js +9 -9
- package/dist/tools/write/snapshot.js +23 -6
- package/dist/write/evaluate.d.ts +4 -3
- package/dist/write/evaluate.js +11 -6
- package/package.json +2 -2
- package/server.json +2 -2
package/capabilities.json
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"id": "autotask.platform.catalog",
|
|
77
|
-
"description": "Find the exact operation key for anything without a dedicated tool: ranked search (q) over the 1,
|
|
77
|
+
"description": "Find the exact operation key for anything without a dedicated tool: ranked search (q) over the 1,357 registry operations, with effect and whether this deployment serves it. No vendor call.",
|
|
78
78
|
"mcpPrimitive": "tool",
|
|
79
79
|
"toolName": "autotask_catalog",
|
|
80
80
|
"type": "read",
|
|
@@ -480,7 +480,7 @@
|
|
|
480
480
|
"autotask_describe",
|
|
481
481
|
"autotask_read"
|
|
482
482
|
],
|
|
483
|
-
"backingRegistryOperations":
|
|
483
|
+
"backingRegistryOperations": 1357,
|
|
484
484
|
"note": "autotask_catalog finds the exact operation key (ranked search), autotask_describe serves its contract, autotask_read runs any effect=read key. Writes go through the operator profile (autotask_write then autotask_apply); authenticate.* is never served."
|
|
485
485
|
},
|
|
486
486
|
"schemas": {}
|
package/dist/access/write-env.js
CHANGED
|
@@ -155,6 +155,14 @@ export function resolveWritePolicy(env) {
|
|
|
155
155
|
dedupProblems.push(`${op}: the sales order query cannot establish exact order-parent duplicates; remove this AUTOTASK_DEDUP entry and use explicit scoped create`);
|
|
156
156
|
continue;
|
|
157
157
|
}
|
|
158
|
+
if (op === 'expense_report_attachments.create') {
|
|
159
|
+
dedupProblems.push(`${op}: report queries can include expense item attachments and cannot establish exact report-parent duplicates; remove this AUTOTASK_DEDUP entry and use explicit scoped create`);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (op === 'resource_attachments.create') {
|
|
163
|
+
dedupProblems.push(`${op}: the resource query cannot establish exact resource-parent duplicates; remove this AUTOTASK_DEDUP entry and use explicit scoped create`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
158
166
|
if (!fields.every((f) => FIELD.test(f))) {
|
|
159
167
|
dedupProblems.push(`${op}: each field must be a plain field name joined by +`);
|
|
160
168
|
continue;
|
package/dist/policy.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ import { AutotaskConfigError } from 'node-autotask';
|
|
|
22
22
|
import type { CapabilityRecord } from 'node-autotask/capabilities';
|
|
23
23
|
import type { Config } from './config/schema.js';
|
|
24
24
|
import type { Logger } from './logger.js';
|
|
25
|
+
import type { Reason } from './tools/reasons.js';
|
|
26
|
+
import type { RunScope } from './write/evaluate.js';
|
|
25
27
|
/** `write` and `destructive` are effects the read surface never dispatches. */
|
|
26
28
|
export declare function isWriteEffect(record: CapabilityRecord): boolean;
|
|
27
29
|
/**
|
|
@@ -31,11 +33,13 @@ export declare function isWriteEffect(record: CapabilityRecord): boolean;
|
|
|
31
33
|
export declare const CREDENTIAL_RESOURCES: readonly ["authenticate"];
|
|
32
34
|
/** Does `operation` sit on a credential-minting resource? */
|
|
33
35
|
export declare function isSecretOperation(operation: string): boolean;
|
|
36
|
+
export declare function isStaffAttachmentWrite(operation: string): boolean;
|
|
37
|
+
export declare function staffAttachmentScopeReason(operation: string, runScope: RunScope | undefined): Reason | undefined;
|
|
34
38
|
/**
|
|
35
39
|
* The one-line reason `operation` is refused (for a catalog row or `describe`), or `null` when this
|
|
36
40
|
* deployment serves it. `writable` is the set of write operations the operator policy lists.
|
|
37
41
|
*/
|
|
38
|
-
export declare function refusalReason(operation: string, record: CapabilityRecord | undefined, config: Config, writable?: ReadonlySet<string
|
|
42
|
+
export declare function refusalReason(operation: string, record: CapabilityRecord | undefined, config: Config, writable?: ReadonlySet<string>, runScope?: RunScope): string | null;
|
|
39
43
|
/** The `POLICY_DENIED` error: deployment policy is fixed for the life of the process, so the
|
|
40
44
|
* model is told no argument it can choose will satisfy the gate (a `CONFIG_ERROR` here would
|
|
41
45
|
* invite the futile retry the policy-aware catalog exists to prevent). */
|
package/dist/policy.js
CHANGED
|
@@ -32,11 +32,23 @@ export const CREDENTIAL_RESOURCES = ['authenticate'];
|
|
|
32
32
|
export function isSecretOperation(operation) {
|
|
33
33
|
return CREDENTIAL_RESOURCES.some((resource) => operation.startsWith(`${resource}.`));
|
|
34
34
|
}
|
|
35
|
+
export function isStaffAttachmentWrite(operation) {
|
|
36
|
+
return /^(expense_report|resource)_attachments\.(create|delete)$/.test(operation);
|
|
37
|
+
}
|
|
38
|
+
export function staffAttachmentScopeReason(operation, runScope) {
|
|
39
|
+
if (!isStaffAttachmentWrite(operation) || (runScope !== undefined && 'all' in runScope)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
code: 'TARGET_NOT_IN_SCOPE',
|
|
44
|
+
detail: `${operation} requires a run scope of {"all":true} because the parent does not establish company ownership`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
35
47
|
/**
|
|
36
48
|
* The one-line reason `operation` is refused (for a catalog row or `describe`), or `null` when this
|
|
37
49
|
* deployment serves it. `writable` is the set of write operations the operator policy lists.
|
|
38
50
|
*/
|
|
39
|
-
export function refusalReason(operation, record, config, writable = new Set()) {
|
|
51
|
+
export function refusalReason(operation, record, config, writable = new Set(), runScope) {
|
|
40
52
|
if (isSecretOperation(operation))
|
|
41
53
|
return 'refused: credential-minting operation (never served)';
|
|
42
54
|
if (record === undefined)
|
|
@@ -45,7 +57,10 @@ export function refusalReason(operation, record, config, writable = new Set()) {
|
|
|
45
57
|
return null;
|
|
46
58
|
if (config.AUTOTASK_PROFILE !== 'operator')
|
|
47
59
|
return 'refused: profile readonly serves reads only';
|
|
48
|
-
|
|
60
|
+
if (!writable.has(operation))
|
|
61
|
+
return 'refused: not admitted by the effective write policy (unlisted writes are read-only)';
|
|
62
|
+
const scope = staffAttachmentScopeReason(operation, runScope);
|
|
63
|
+
return scope === undefined ? null : `refused: ${scope.detail}`;
|
|
49
64
|
}
|
|
50
65
|
/** The `POLICY_DENIED` error: deployment policy is fixed for the life of the process, so the
|
|
51
66
|
* model is told no argument it can choose will satisfy the gate (a `CONFIG_ERROR` here would
|
|
@@ -107,7 +107,7 @@ export declare function sdkCacheOptions(cache: 'on' | 'off'): Pick<AutotaskConfi
|
|
|
107
107
|
* fails the boot (or the CI test) instead of quietly shipping a tool surface that no longer
|
|
108
108
|
* describes the SDK behind it.
|
|
109
109
|
*/
|
|
110
|
-
export declare const BUILT_AGAINST_PLAN_HASH = "
|
|
110
|
+
export declare const BUILT_AGAINST_PLAN_HASH = "d758816a699191e3da784f70f8ebe1f37ea9458aaf528241770f7bac94ba6ede";
|
|
111
111
|
/**
|
|
112
112
|
* Fail fast when the installed SDK's plan has moved out from under this surface.
|
|
113
113
|
* Called at boot (main.ts) and safe to call repeatedly (pure comparison).
|
|
@@ -187,7 +187,7 @@ export function sdkCacheOptions(cache) {
|
|
|
187
187
|
* fails the boot (or the CI test) instead of quietly shipping a tool surface that no longer
|
|
188
188
|
* describes the SDK behind it.
|
|
189
189
|
*/
|
|
190
|
-
export const BUILT_AGAINST_PLAN_HASH = '
|
|
190
|
+
export const BUILT_AGAINST_PLAN_HASH = 'd758816a699191e3da784f70f8ebe1f37ea9458aaf528241770f7bac94ba6ede';
|
|
191
191
|
/**
|
|
192
192
|
* Fail fast when the installed SDK's plan has moved out from under this surface.
|
|
193
193
|
* Called at boot (main.ts) and safe to call repeatedly (pure comparison).
|
package/dist/tools/meta.js
CHANGED
|
@@ -27,14 +27,14 @@ import {} from './context/types.js';
|
|
|
27
27
|
import { abortedAnswer, FIELD_CATALOG_MAX_BYTES, InputInvalidError, readOneItem, requestSecrets } from './dispatch.js';
|
|
28
28
|
import { zoneClock } from './clock.js';
|
|
29
29
|
import { typedErrorPayload } from './results/errors.js';
|
|
30
|
-
import { markResult, sanitiseVendorOutput } from './results/untrusted.js';
|
|
31
|
-
import { errorEnvelope, ok } from './results/envelope.js';
|
|
30
|
+
import { markResult, sanitiseVendorOutput, UNTRUSTED_TEXT_CAP } from './results/untrusted.js';
|
|
31
|
+
import { errorEnvelope, ok, TRUNCATION_MARKER } from './results/envelope.js';
|
|
32
32
|
import { compileBm25 } from './rank.js';
|
|
33
33
|
import { playbooksFor } from './guide.js';
|
|
34
34
|
import { FIELD_INFO_EXPENSIVE, fieldLookupCall, udfCatalogCall } from './field-pointer.js';
|
|
35
35
|
import { SERVER_NAME, SERVER_VERSION } from './server-version.js';
|
|
36
36
|
import { CATALOG_INPUT, DESCRIBE_INPUT, AR_AGING_INPUT, WIP_HOURS_INPUT, NON_CHARGEABLE_WORK_INPUT, COMPANY_FULL_PROFILE_INPUT, CONFIGURATION_ITEM_PROFILE_INPUT, CONTACT_FULL_PROFILE_INPUT, CONTRACT_FULL_PROFILE_INPUT, INVOICE_GET_INPUT, PORTFOLIO_MARGIN_INPUT, RECURRING_REVENUE_INPUT, REVENUE_ROLLUP_INPUT, PROJECT_GET_CONTEXT_INPUT, QUERY_INPUT, QUOTE_GET_INPUT, RESOLVE_INPUT, RESOURCE_WORKLOAD_INPUT, SERVICE_CALL_FULL_PROFILE_INPUT, TICKET_FULL_CONTEXT_INPUT, QUERY_LIMIT, READ_INPUT, TENANT_STATUS_INPUT, TENANT_STATUS_PARTS, readIgnoredKeys, closedInput, } from './schemas.js';
|
|
37
|
-
import { refusalReason } from '../policy.js';
|
|
37
|
+
import { isStaffAttachmentWrite, refusalReason } from '../policy.js';
|
|
38
38
|
/** Static registry search metadata; vendor reads and per-deployment boosts never enter this index. */
|
|
39
39
|
const CATALOG_INDEX = compileBm25(CATALOG.catalog.map((r) => `${r.operation} ${r.operation.replace(/[._]/g, ' ')} ${toolForOp(r.operation) ?? ''} ${r.purpose ?? ''}`));
|
|
40
40
|
/** `autotask_catalog`: the filtered, ranked, paged registry rows with this deployment's verdicts. */
|
|
@@ -69,7 +69,7 @@ export function buildCatalog(ctx) {
|
|
|
69
69
|
});
|
|
70
70
|
// Only rows this deployment refuses for their EFFECT (writes) are hidden by default;
|
|
71
71
|
// read refusals (credential-minting) stay visible with their policyReason.
|
|
72
|
-
const verdicts = matched.map((r) => ({ r, reason: refusalReason(r.operation, ctx.record(r.operation), ctx.config, ctx.writable) }));
|
|
72
|
+
const verdicts = matched.map((r) => ({ r, reason: refusalReason(r.operation, ctx.record(r.operation), ctx.config, ctx.writable, ctx.write?.runScope) }));
|
|
73
73
|
const isHidden = (v) => v.reason !== null && v.r.effect !== 'read';
|
|
74
74
|
const hiddenRefused = verdicts.filter(isHidden).length;
|
|
75
75
|
const hiddenRows = matched.filter((r) => !shown(r)).length;
|
|
@@ -244,7 +244,7 @@ export function buildDescribe(ctx) {
|
|
|
244
244
|
purpose: r?.purpose ?? null,
|
|
245
245
|
effect: r?.effect ?? ctx.record(k).effect,
|
|
246
246
|
requiredArgs: r?.requiredArgs ?? [],
|
|
247
|
-
reachable: (r?.reachable ?? true) && refusalReason(k, ctx.record(k), ctx.config, ctx.writable) === null,
|
|
247
|
+
reachable: (r?.reachable ?? true) && refusalReason(k, ctx.record(k), ctx.config, ctx.writable, ctx.write?.runScope) === null,
|
|
248
248
|
};
|
|
249
249
|
});
|
|
250
250
|
return ok(`"${operation}" serves ${keys.length} registry keys; pass one as operation for its full record.`, {
|
|
@@ -350,6 +350,12 @@ async function guidanceFor(ctx, rec, reachable) {
|
|
|
350
350
|
note: 'Args are [sourceId, toTicketId]; nothing else can be changed. The record is created on the target ticket and the original deleted (new id, new create date and creator; notifications may fire). AUTOTASK_WRITE must list this operation; a company or contract change needs a person to confirm it. Previews write nothing.',
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
|
+
if (op === 'delete' && rec.effect === 'destructive' && isStaffAttachmentWrite(rec.id)) {
|
|
354
|
+
return {
|
|
355
|
+
example: `autotask_write {operation:"${rec.id}", args:[<parentId>, <id>]}`,
|
|
356
|
+
note: "Use positive safe integer JSON numbers for both IDs. After reviewing the preview, pass its plan and the approval's operation, targets and summary to autotask_apply_destructive.",
|
|
357
|
+
};
|
|
358
|
+
}
|
|
353
359
|
if (rec.effect !== 'write' || (op !== 'create' && op !== 'update'))
|
|
354
360
|
return undefined;
|
|
355
361
|
let required;
|
|
@@ -409,6 +415,10 @@ async function guidanceFor(ctx, rec, reachable) {
|
|
|
409
415
|
const caveats = caveatNotes(rec.metadata?.caveats);
|
|
410
416
|
// a create the SDK marks unsatisfiable for any input gets no example to copy
|
|
411
417
|
const unsatisfiable = op === 'create' && facts?.blocker?.unsatisfiableViaApi === true;
|
|
418
|
+
const staffFileCreate = op === 'create' && isStaffAttachmentWrite(rec.id);
|
|
419
|
+
const example = staffFileCreate
|
|
420
|
+
? `autotask_write {operation:"${rec.id}", args:[<parentId>,{attachmentType:"FILE_ATTACHMENT",title:"Supporting note",fullPath:"note.txt",publish:<active numeric value from getFieldInfo>,data:"bm90ZQ=="}]}`
|
|
421
|
+
: `autotask_write {operation:"${rec.id}", args:${JSON.stringify(exampleArgs)}}`;
|
|
412
422
|
return {
|
|
413
423
|
requiredFields: required ?? 'unavailable',
|
|
414
424
|
...(requiredFrom !== undefined ? { requiredFieldsFrom: requiredFrom } : {}),
|
|
@@ -416,7 +426,7 @@ async function guidanceFor(ctx, rec, reachable) {
|
|
|
416
426
|
readOnlyFields: readOnly ?? 'unavailable',
|
|
417
427
|
...(required === undefined ? { fieldsNote: `field metadata could not be read; call autotask_read {operation:"operations.fieldCatalog", args:[{resources:["${rec.resource}"]}]}` } : {}),
|
|
418
428
|
...(conditional !== undefined ? { requiredFieldsConditional: conditional } : {}),
|
|
419
|
-
...(unsatisfiable ? { createUnsatisfiableViaApi: true } : {
|
|
429
|
+
...(unsatisfiable ? { createUnsatisfiableViaApi: true } : { ...(staffFileCreate ? {} : { exampleArgs }), example }),
|
|
420
430
|
note: `${op === 'create' ? 'Required fields can be wider than the vendor marks (see the playbooks).' : `Update args are [${argNames.map(name => name === 'data' ? '{fields}' : name).join(', ')}]; send only the fields to change.`} Previews write nothing.`,
|
|
421
431
|
...(caveats.length > 0 ? { caveats } : {}),
|
|
422
432
|
...(constraints.length > 0 ? { constraints } : {}),
|
|
@@ -501,17 +511,39 @@ function servedUsage(rec) {
|
|
|
501
511
|
const u = rec.metadata?.usage;
|
|
502
512
|
if (typeof u !== 'string')
|
|
503
513
|
return undefined;
|
|
514
|
+
if (rec.id === 'expense_report_attachments.get' || rec.id === 'resource_attachments.get') {
|
|
515
|
+
return `${u} Inline data, if present, is subject to the ${UNTRUSTED_TEXT_CAP}-character text cap. The ${TRUNCATION_MARKER} marker inside the data wrapper identifies an incomplete value. textCapped applies to the whole response.`;
|
|
516
|
+
}
|
|
504
517
|
// the read-back is one `<resource>.get`: a create with no get in the registry answers `data.record: null`
|
|
505
518
|
return u.includes(CREATE_USAGE_FALSE) && recordById(`${rec.resource}.get`) !== undefined ? u.replace(CREATE_USAGE_FALSE, CREATE_USAGE_TRUE) : u;
|
|
506
519
|
}
|
|
507
|
-
|
|
520
|
+
function staffAttachmentArgs(rec) {
|
|
521
|
+
if (!isStaffAttachmentWrite(rec.id))
|
|
522
|
+
return undefined;
|
|
523
|
+
return rec.operation === 'delete'
|
|
524
|
+
? 'parentId and id each require a positive safe integer JSON number.'
|
|
525
|
+
: 'parentId requires a positive safe integer JSON number. data is the attachment payload.';
|
|
526
|
+
}
|
|
527
|
+
/** Served record: caveats projected, MCP argument restrictions applied and the SDK's own test list dropped. */
|
|
508
528
|
function servedRecord(rec) {
|
|
509
529
|
const projected = { ...projectCaveats(rec) };
|
|
510
530
|
delete projected.tests;
|
|
511
531
|
const md = projected.metadata;
|
|
512
532
|
const usage = servedUsage(rec);
|
|
513
|
-
|
|
514
|
-
|
|
533
|
+
if (usage !== undefined && usage !== md?.usage)
|
|
534
|
+
projected.metadata = { ...md, usage };
|
|
535
|
+
const args = staffAttachmentArgs(rec);
|
|
536
|
+
if (args !== undefined) {
|
|
537
|
+
const schema = { ...rec.inputSchema };
|
|
538
|
+
for (const key of ['parentId', 'id']) {
|
|
539
|
+
const descriptor = schema[key];
|
|
540
|
+
if (descriptor !== undefined)
|
|
541
|
+
schema[key] = { ...descriptor, type: 'number', description: `${key} requires a positive safe integer JSON number.` };
|
|
542
|
+
}
|
|
543
|
+
projected.inputSchema = schema;
|
|
544
|
+
projected.metadata = { ...projected.metadata, args };
|
|
545
|
+
}
|
|
546
|
+
return projected;
|
|
515
547
|
}
|
|
516
548
|
/** The per-field caps of a describe summary (characters): purpose, args and usage only, about 2 KB in all (#197). */
|
|
517
549
|
const SUMMARY_CAPS = { purpose: 500, args: 600, usage: 400 };
|
|
@@ -527,7 +559,7 @@ function capText(text, max, name, cut) {
|
|
|
527
559
|
/** `autotask_describe {summary: true}`: the registry's purpose, args and usage text and the verdict; no examples, errors, tests or playbooks. */
|
|
528
560
|
function summariseRecord(ctx, operation, viaTool) {
|
|
529
561
|
const rec = ctx.record(operation);
|
|
530
|
-
const reason = refusalReason(operation, rec, ctx.config, ctx.writable);
|
|
562
|
+
const reason = refusalReason(operation, rec, ctx.config, ctx.writable, ctx.write?.runScope);
|
|
531
563
|
const md = (rec.metadata ?? {});
|
|
532
564
|
const row = CATALOG.catalog.find((r) => r.operation === operation);
|
|
533
565
|
const text = (v) => (typeof v === 'string' ? v : '');
|
|
@@ -538,7 +570,7 @@ function summariseRecord(ctx, operation, viaTool) {
|
|
|
538
570
|
...(tool !== undefined ? { tool, ...toolServed(ctx, tool) } : {}),
|
|
539
571
|
purpose: capText(text(md.purpose) || text(row?.purpose), SUMMARY_CAPS.purpose, 'purpose', cut),
|
|
540
572
|
requiredArgs: row?.requiredArgs ?? [],
|
|
541
|
-
args: capText(text(md.args), SUMMARY_CAPS.args, 'args', cut),
|
|
573
|
+
args: capText(staffAttachmentArgs(rec) ?? text(md.args), SUMMARY_CAPS.args, 'args', cut),
|
|
542
574
|
usage: capText(text(servedUsage(rec)), SUMMARY_CAPS.usage, 'usage', cut),
|
|
543
575
|
reachable: reason === null,
|
|
544
576
|
why_not: reason,
|
|
@@ -573,7 +605,7 @@ async function describeRecord(ctx, operation, viaTool, summary = false, full = f
|
|
|
573
605
|
if (summary)
|
|
574
606
|
return summariseRecord(ctx, operation, viaTool);
|
|
575
607
|
const rec = ctx.record(operation);
|
|
576
|
-
const reason = refusalReason(operation, rec, ctx.config, ctx.writable);
|
|
608
|
+
const reason = refusalReason(operation, rec, ctx.config, ctx.writable, ctx.write?.runScope);
|
|
577
609
|
const guidance = await guidanceFor(ctx, rec, reason === null);
|
|
578
610
|
const names = paramNames(operation, rec);
|
|
579
611
|
const cut = [];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { BuiltTool } from '../surface.js';
|
|
2
2
|
import type { ToolContext } from '../context/types.js';
|
|
3
3
|
import type { WriteMode } from '../../access/write-env.js';
|
|
4
|
-
import { type PlanRecord } from '../../write/store.js';
|
|
5
4
|
/**
|
|
6
5
|
* Who approved the planHash (`approverId` in the ledger and audit, #302): `elicitation` (the person answered
|
|
7
6
|
* the stdio form), `session:<grantId>` (a stdio grant the person chose earlier), `policy:unattended` (a stdio
|
|
@@ -33,8 +32,6 @@ interface MissStore<E> {
|
|
|
33
32
|
* answer instead of letting a replay quietly answer plain ok.
|
|
34
33
|
*/
|
|
35
34
|
export declare function recordMiss<E>(store: MissStore<E>, entry: E, attempts?: number, waitMs?: number): Promise<boolean>;
|
|
36
|
-
/** The apply tool for a plan: a plan that hits a hard rule applies only through the destructive one (#302). */
|
|
37
|
-
export declare const applyToolFor: (plan: Pick<PlanRecord, "decision">) => "autotask_apply" | "autotask_apply_destructive";
|
|
38
35
|
/** Build an apply tool (`destructive`: autotask_apply_destructive); human confirmation happens outside the apply lock. */
|
|
39
36
|
export declare function buildApply(ctx: ToolContext, destructive?: boolean): BuiltTool;
|
|
40
37
|
export {};
|
|
@@ -20,7 +20,8 @@ import { canonicalJson, planHashOf } from '../../write/canonical.js';
|
|
|
20
20
|
import { dedupFor, evaluate, pinAudit, PIN_RULE } from '../../write/evaluate.js';
|
|
21
21
|
import { writeShape } from '../../write/hard-rules.js';
|
|
22
22
|
import { COOLDOWN_MINUTES } from '../../write/store.js';
|
|
23
|
-
import {
|
|
23
|
+
import { staffAttachmentScopeReason } from '../../policy.js';
|
|
24
|
+
import { Cancelled, tenantIdentity, answer, applyToolFor, reason } from './common.js';
|
|
24
25
|
import { SHAPE_ARGS, parseArgs } from './parse.js';
|
|
25
26
|
import { ci } from './payload.js';
|
|
26
27
|
import { getIds, takeSnapshot } from './snapshot.js';
|
|
@@ -373,7 +374,7 @@ async function respond(a, r) {
|
|
|
373
374
|
const { ctx, store, plan } = a;
|
|
374
375
|
const { record, shape, entry, error, moveResult, callResult } = r;
|
|
375
376
|
if (entry.state !== 'succeeded') {
|
|
376
|
-
const data = error === undefined ? {} : { error: honestError(typedErrorPayload(error, ctx.correlationId, requestSecrets(ctx)),
|
|
377
|
+
const data = error === undefined ? {} : { error: honestError(typedErrorPayload(error, ctx.correlationId, requestSecrets(ctx)), entry) };
|
|
377
378
|
return outcomeAnswer(plan, entry, { replayed: false, data });
|
|
378
379
|
}
|
|
379
380
|
if (shape === 'move')
|
|
@@ -446,8 +447,6 @@ async function respond(a, r) {
|
|
|
446
447
|
}
|
|
447
448
|
return outcomeAnswer(plan, entry, { replayed: false });
|
|
448
449
|
}
|
|
449
|
-
/** The apply tool for a plan: a plan that hits a hard rule applies only through the destructive one (#302). */
|
|
450
|
-
export const applyToolFor = (plan) => plan.decision === 'gate' ? 'autotask_apply_destructive' : 'autotask_apply';
|
|
451
450
|
/** Build an apply tool (`destructive`: autotask_apply_destructive); human confirmation happens outside the apply lock. */
|
|
452
451
|
export function buildApply(ctx, destructive = false) {
|
|
453
452
|
const tool = destructive ? 'autotask_apply_destructive' : 'autotask_apply';
|
|
@@ -478,6 +477,9 @@ export function buildApply(ctx, destructive = false) {
|
|
|
478
477
|
if (readBack === 'time_entry_verification_v1' && plan.op !== 'time_entries.create') {
|
|
479
478
|
return refused('error', 'supply_input', reason('INPUT_INVALID', 'readBack time_entry_verification_v1 requires time_entries.create', 'readBack'), plan);
|
|
480
479
|
}
|
|
480
|
+
const scopeRefusal = staffAttachmentScopeReason(plan.op, w.runScope);
|
|
481
|
+
if (scopeRefusal !== undefined)
|
|
482
|
+
return refused('denied', 'stop', scopeRefusal, plan);
|
|
481
483
|
// Who approves (#302). HTTP: the client or gateway did, so the server never asks. stdio: the
|
|
482
484
|
// mode decides; a person's answer runs over the LOADED plan and OUTSIDE the apply lock (it must
|
|
483
485
|
// never hold it). A ledger hit that ends the apply (a replay) answers in execute() without asking;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import type { ToolContext, WriteDeps } from '../context/types.js';
|
|
3
3
|
import { type ToolReturn } from '../results/envelope.js';
|
|
4
4
|
import type { NextAction, Reason, ReasonCode, Status } from '../reasons.js';
|
|
5
|
-
import type { TenantIdentity } from '../../write/store.js';
|
|
5
|
+
import type { PlanRecord, TenantIdentity } from '../../write/store.js';
|
|
6
|
+
/** The apply tool for a plan: a plan that hits a hard rule applies only through the destructive one (#302). */
|
|
7
|
+
export declare const applyToolFor: (plan: Pick<PlanRecord, "decision">) => "autotask_apply" | "autotask_apply_destructive";
|
|
6
8
|
/** Thrown inside a snapshot when the MCP request was cancelled before a read settled. */
|
|
7
9
|
export declare class Cancelled extends Error {
|
|
8
10
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { envelopeResult } from '../results/envelope.js';
|
|
2
|
+
/** The apply tool for a plan: a plan that hits a hard rule applies only through the destructive one (#302). */
|
|
3
|
+
export const applyToolFor = (plan) => plan.decision === 'gate' ? 'autotask_apply_destructive' : 'autotask_apply';
|
|
2
4
|
/** Thrown inside a snapshot when the MCP request was cancelled before a read settled. */
|
|
3
5
|
export class Cancelled extends Error {
|
|
4
6
|
}
|
|
@@ -6,7 +6,7 @@ import type { WriteShape } from '../../write/hard-rules.js';
|
|
|
6
6
|
import type { StateStore } from '../../write/store.js';
|
|
7
7
|
import { type ParsedArgs } from './parse.js';
|
|
8
8
|
import type { Snapshot } from './snapshot.js';
|
|
9
|
-
/** The refusal for a write whose
|
|
9
|
+
/** The refusal for a write whose required scope references could not be verified. */
|
|
10
10
|
export declare function unresolvedReason(refs: string[]): Reason;
|
|
11
11
|
/** Field name (lower case) -> catalog type, as the preview's one cached field-catalog read reports it. */
|
|
12
12
|
export type FieldTypes = ReadonlyMap<string, string>;
|
|
@@ -4,8 +4,17 @@ import { reason } from './common.js';
|
|
|
4
4
|
import { targetKeyOf } from './parse.js';
|
|
5
5
|
import { ci } from './payload.js';
|
|
6
6
|
import { INSTANT } from './snapshot.js';
|
|
7
|
-
/** The refusal for a write whose
|
|
7
|
+
/** The refusal for a write whose required scope references could not be verified. */
|
|
8
8
|
export function unresolvedReason(refs) {
|
|
9
|
+
if (refs.includes('expense_report_attachments.expenseReportID')) {
|
|
10
|
+
return reason('TARGET_NOT_IN_SCOPE', 'could not verify the selected expense report from current records');
|
|
11
|
+
}
|
|
12
|
+
if (refs.includes('resource_attachments.resourceID')) {
|
|
13
|
+
return reason('TARGET_NOT_IN_SCOPE', 'could not verify the selected resource from current records');
|
|
14
|
+
}
|
|
15
|
+
if (refs.includes('expense_report_attachments.expenseItemID')) {
|
|
16
|
+
return reason('TARGET_NOT_IN_SCOPE', `could not verify from current records that the expense item belongs to the selected report (${refs.join(', ')})`);
|
|
17
|
+
}
|
|
9
18
|
return reason('TARGET_NOT_IN_SCOPE', `the company behind ${refs.join(', ')} could not be established from a live record; a write whose company cannot be established is refused`);
|
|
10
19
|
}
|
|
11
20
|
// ---------------------------------------------------------------------------
|
|
@@ -7,7 +7,7 @@ import { type LedgerEntry, type PlanRecord } from '../../write/store.js';
|
|
|
7
7
|
* deterministic business-rule rejection, and an unknown outcome must never be re-sent. Only a
|
|
8
8
|
* genuinely retryable failure keeps the SDK's hint.
|
|
9
9
|
*/
|
|
10
|
-
export declare function honestError(payload: Record<string, unknown>,
|
|
10
|
+
export declare function honestError(payload: Record<string, unknown>, entry: LedgerEntry): Record<string, unknown>;
|
|
11
11
|
/** The cap on the vendor refusal text a failed ledger line keeps. */
|
|
12
12
|
export declare const VENDOR_MESSAGE_CAP = 300;
|
|
13
13
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { COOLDOWN_MINUTES } from '../../write/store.js';
|
|
2
|
-
import { answer, reason } from './common.js';
|
|
2
|
+
import { answer, applyToolFor, reason } from './common.js';
|
|
3
3
|
import { scrubSecrets } from '../results/errors.js';
|
|
4
4
|
import { cleanUntrustedText, stripUnsafeChars } from '../results/untrusted.js';
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
@@ -11,12 +11,13 @@ import { cleanUntrustedText, stripUnsafeChars } from '../results/untrusted.js';
|
|
|
11
11
|
* deterministic business-rule rejection, and an unknown outcome must never be re-sent. Only a
|
|
12
12
|
* genuinely retryable failure keeps the SDK's hint.
|
|
13
13
|
*/
|
|
14
|
-
export function honestError(payload,
|
|
14
|
+
export function honestError(payload, entry) {
|
|
15
15
|
if (entry.outcome?.retryable === true)
|
|
16
16
|
return { ...payload, nextAction: 'retry' };
|
|
17
17
|
if (entry.state === 'unknown')
|
|
18
18
|
return { ...payload, retryable: false, nextAction: 'stop', suggestedAction: 'The write may have landed: read the record to verify; do not re-send.' };
|
|
19
|
-
|
|
19
|
+
// The typed payload has already bounded and scrubbed these vendor messages.
|
|
20
|
+
const errors = payload.vendorError?.errors;
|
|
20
21
|
const said = Array.isArray(errors) ? errors.filter((e) => typeof e === 'string').slice(0, 3).map((e) => e.slice(0, 200)) : [];
|
|
21
22
|
return { ...payload, retryable: false, nextAction: 'stop', suggestedAction: refusedAction(said.join('; ')) };
|
|
22
23
|
}
|
|
@@ -75,14 +76,28 @@ export function outcomeAnswer(plan, entry, extra) {
|
|
|
75
76
|
return answer('ok', 'proceed', [], { ...base, result }, { ...meta, summary: extra.summary ?? `${plan.op} succeeded${extra.replayed ? ' (recorded outcome replayed; nothing was sent again)' : ''}.` });
|
|
76
77
|
}
|
|
77
78
|
if (entry.state === 'failed') {
|
|
78
|
-
const
|
|
79
|
+
const forbidden = entry.outcome?.httpStatus === 403;
|
|
80
|
+
const retryable = !forbidden && entry.outcome?.retryable === true;
|
|
79
81
|
const code = retryable && entry.outcome?.code?.startsWith('RATE_LIMITED') === true ? 'RATE_LIMITED' : 'WRITE_FAILED';
|
|
80
82
|
// a replayed refusal answers the recorded vendor text the way the fresh failure did (data.error.suggestedAction)
|
|
81
83
|
const said = entry.outcome?.vendorMessage;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
let data = base;
|
|
85
|
+
if (forbidden) {
|
|
86
|
+
// Both the fresh response and replay use the recorded permission classification and safe advice.
|
|
87
|
+
data = {
|
|
88
|
+
...base,
|
|
89
|
+
error: {
|
|
90
|
+
error: true, code: 'FORBIDDEN', httpStatus: 403, retryable: false, nextAction: 'stop',
|
|
91
|
+
message: 'Autotask denied permission for this write.',
|
|
92
|
+
suggestedAction: 'Check that the integration has permission for this operation. An identical approval replays this refusal.',
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else if (extra.replayed && !retryable && said !== undefined && !('error' in base)) {
|
|
97
|
+
data = { ...base, error: { error: true, code: entry.outcome?.code ?? 'WRITE_FAILED', ...(entry.outcome?.httpStatus !== undefined ? { httpStatus: entry.outcome.httpStatus } : {}), retryable: false, nextAction: 'stop', suggestedAction: refusedAction(said) } };
|
|
98
|
+
}
|
|
99
|
+
const failureCode = forbidden ? 'FORBIDDEN' : entry.outcome?.code ?? 'error';
|
|
100
|
+
return answer('error', retryable ? 'retry' : 'stop', [reason(code, `${plan.op} failed (${failureCode}${entry.outcome?.httpStatus !== undefined ? `, HTTP ${entry.outcome.httpStatus}` : ''}); nothing was written${retryable ? `; after the wait call ${applyToolFor(plan)} with this same plan handle (${plan.handle}); do not preview again` : ''}`)], data, { ...meta, retryable });
|
|
86
101
|
}
|
|
87
102
|
if (entry.outcome?.code === 'MOVE_PARTIAL' || entry.outcome?.code === 'MOVE_UNKNOWN') {
|
|
88
103
|
const ids = `source ${String(entry.outcome.sourceId)}${entry.outcome.newId !== undefined ? `, new ${String(entry.outcome.newId)}` : ''}`;
|
|
@@ -8,10 +8,10 @@ import { cleanUntrustedText, markResult } from '../results/untrusted.js';
|
|
|
8
8
|
import { assertOperationPermitted } from '../../policy.js';
|
|
9
9
|
import { WRITE_INPUT, closedInput } from '../schemas.js';
|
|
10
10
|
import { planHashOf } from '../../write/canonical.js';
|
|
11
|
-
import {
|
|
11
|
+
import { dedupFor, evaluate, pinAudit, writeScopeReason } from '../../write/evaluate.js';
|
|
12
12
|
import { hardRuleFor, writeShape } from '../../write/hard-rules.js';
|
|
13
13
|
import { PLAN_TTL_MS } from '../../write/store.js';
|
|
14
|
-
import { Cancelled, writeDeps, tenantIdentity, answer, reason } from './common.js';
|
|
14
|
+
import { Cancelled, writeDeps, tenantIdentity, answer, applyToolFor, reason } from './common.js';
|
|
15
15
|
import { parseArgs } from './parse.js';
|
|
16
16
|
import { honestImpact } from './payload.js';
|
|
17
17
|
import { drainReads, readWasAborted } from './concurrent.js';
|
|
@@ -20,7 +20,7 @@ import { catalogFindings, pairFindings } from './checks.js';
|
|
|
20
20
|
import { unresolvedReason, markedDiff, deriveFacts } from './facts.js';
|
|
21
21
|
import { UDF_CAPABLE } from '../catalog-data.js';
|
|
22
22
|
import { udfPreviewWarning } from '../write-guidance.js';
|
|
23
|
-
import {
|
|
23
|
+
import { approverFor } from './apply.js';
|
|
24
24
|
import { creatorIdentity, impersonatedContext, validateImpersonation } from './impersonation.js';
|
|
25
25
|
/**
|
|
26
26
|
* The generic `call` shape has no field-level snapshot (issue #191): no vendor reads establish what the
|
|
@@ -165,7 +165,7 @@ function evaluatePreview(r, a, snap, dry, resource, types) {
|
|
|
165
165
|
const attribution = typeof contact === 'number'
|
|
166
166
|
? `Requested contact author ${contact}, subject to Autotask validation${resourceIdentity === undefined ? '' : `. Request uses ${resourceIdentity}`}`
|
|
167
167
|
: `Creator: ${resourceIdentity ?? 'API user'}`;
|
|
168
|
-
const fileAttachment = ['configuration_item_attachments.create', 'configuration_item_note_attachments.create', 'contract_note_attachments.create', 'project_attachments.create', 'project_note_attachments.create', 'sales_order_attachments.create', 'task_attachments.create', 'task_note_attachments.create'].includes(op);
|
|
168
|
+
const fileAttachment = ['configuration_item_attachments.create', 'configuration_item_note_attachments.create', 'contract_note_attachments.create', 'expense_report_attachments.create', 'project_attachments.create', 'project_note_attachments.create', 'resource_attachments.create', 'sales_order_attachments.create', 'task_attachments.create', 'task_note_attachments.create'].includes(op);
|
|
169
169
|
const base64 = fileAttachment && parsed.data?.attachmentType === 'FILE_ATTACHMENT' ? parsed.data.data : undefined;
|
|
170
170
|
const file = typeof base64 === 'string'
|
|
171
171
|
? { bytes: Buffer.byteLength(base64, 'base64'), sha256: createHash('sha256').update(base64, 'base64').digest('hex') }
|
|
@@ -273,11 +273,11 @@ async function execute(ctx, args, signal, ownerTenantId) {
|
|
|
273
273
|
if ('code' in parsed)
|
|
274
274
|
return answer('error', 'supply_input', [parsed], { operation: op });
|
|
275
275
|
const a = { record, shape, parsed, rule };
|
|
276
|
-
//
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
audit('deny', [
|
|
280
|
-
return answer('denied', 'stop', [
|
|
276
|
+
// Reject operations whose company scope cannot admit any target before reading vendor records.
|
|
277
|
+
const scopeRefusal = writeScopeReason(op, hard.hazards, w.runScope);
|
|
278
|
+
if (scopeRefusal !== undefined) {
|
|
279
|
+
audit('deny', [scopeRefusal], undefined, parsed.targets);
|
|
280
|
+
return answer('denied', 'stop', [scopeRefusal], { operation: op, targets: parsed.targets });
|
|
281
281
|
}
|
|
282
282
|
const identityRefusal = await validateImpersonation(ctx, args.impersonationResourceId, signal);
|
|
283
283
|
if (identityRefusal !== undefined)
|
|
@@ -80,7 +80,9 @@ function createReader(ctx, targetKey, signal, operation) {
|
|
|
80
80
|
const projectNoteAttachment = operation === 'project_note_attachments.create' || operation === 'project_note_attachments.delete';
|
|
81
81
|
const contractNoteAttachment = operation === 'contract_note_attachments.create' || operation === 'contract_note_attachments.delete';
|
|
82
82
|
const salesOrderAttachment = operation === 'sales_order_attachments.create' || operation === 'sales_order_attachments.delete';
|
|
83
|
-
const
|
|
83
|
+
const expenseReportAttachment = operation === 'expense_report_attachments.create' || operation === 'expense_report_attachments.delete';
|
|
84
|
+
const resourceAttachment = operation === 'resource_attachments.create' || operation === 'resource_attachments.delete';
|
|
85
|
+
const strictAttachment = expenseReportAttachment || resourceAttachment || salesOrderAttachment || taskAttachment || assetAttachment || assetNoteAttachment || projectAttachment || projectNoteAttachment || contractNoteAttachment || operation === 'task_note_attachments.create' || operation === 'task_note_attachments.delete';
|
|
84
86
|
// The write's own TARGET record is hashed in full (an update/delete must notice any change to it);
|
|
85
87
|
// a record that is only REFERENCED (the ticket a time entry is logged on) is hashed by its stable
|
|
86
88
|
// facts only, so a volatile stamp the first of two outstanding writes moves (lastActivityDate,
|
|
@@ -114,10 +116,18 @@ function createReader(ctx, targetKey, signal, operation) {
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
reads[key] = v;
|
|
117
|
-
|
|
119
|
+
if (expenseReportAttachment && resource === 'expense_items') {
|
|
120
|
+
hashed[key] = { id: ci(model, 'id'), expenseReportID: ci(model, 'expenseReportID') };
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
hashed[key] = key === targetKey ? v : stableFacts(v);
|
|
124
|
+
}
|
|
118
125
|
if (salesOrderAttachment && resource === 'sales_orders') {
|
|
119
126
|
hashed[`${key}:opportunity`] = ci(model, 'opportunityID');
|
|
120
127
|
}
|
|
128
|
+
if (expenseReportAttachment && resource === 'expense_reports') {
|
|
129
|
+
hashed[`${key}:staff`] = { submitterID: ci(model, 'submitterID'), approverID: ci(model, 'approverID') };
|
|
130
|
+
}
|
|
121
131
|
return model;
|
|
122
132
|
})();
|
|
123
133
|
pending.set(key, request);
|
|
@@ -195,6 +205,9 @@ function createReader(ctx, targetKey, signal, operation) {
|
|
|
195
205
|
if (projectAttachment && !payload && resource === 'project_attachments') {
|
|
196
206
|
refs.push(['projectNoteID', 'project_notes']);
|
|
197
207
|
}
|
|
208
|
+
const reportAttachmentOrigin = expenseReportAttachment && !payload && resource === 'expense_report_attachments';
|
|
209
|
+
if (reportAttachmentOrigin)
|
|
210
|
+
refs.push(['expenseItemID', 'expense_items']);
|
|
198
211
|
const orderOrigin = salesOrderAttachment && !payload && resource === 'sales_orders';
|
|
199
212
|
if (orderOrigin || (salesOrderAttachment && !payload && resource === 'sales_order_attachments')) {
|
|
200
213
|
refs.push(['opportunityID', 'opportunities']);
|
|
@@ -218,7 +231,8 @@ function createReader(ctx, targetKey, signal, operation) {
|
|
|
218
231
|
const target = await get(res, ids);
|
|
219
232
|
const wrongTask = resource === 'task_predecessors' && res === 'tasks' && ci(target, 'id') !== value;
|
|
220
233
|
const wrongOrigin = attachmentOrigin && (res === 'task_notes' || res === 'time_entries') && ci(target, 'taskID') !== ci(rec, 'taskID');
|
|
221
|
-
|
|
234
|
+
const wrongReport = reportAttachmentOrigin && res === 'expense_items' && ci(target, 'expenseReportID') !== ci(rec, 'expenseReportID');
|
|
235
|
+
read = wrongTask || wrongOrigin || wrongReport ? { kind: 'missing' } : { kind: 'record', record: target };
|
|
222
236
|
}
|
|
223
237
|
}
|
|
224
238
|
}
|
|
@@ -232,9 +246,12 @@ function createReader(ctx, targetKey, signal, operation) {
|
|
|
232
246
|
// so independent subtrees can drain without changing that error order.
|
|
233
247
|
if (children.some(child => child.read.kind === 'error'))
|
|
234
248
|
return { kind: 'record', resource, record: rec, payload, children };
|
|
235
|
-
const descendants = await drainReads(children.map(child =>
|
|
236
|
-
|
|
237
|
-
|
|
249
|
+
const descendants = await drainReads(children.map(child => {
|
|
250
|
+
// The verified expense item's report binding is its only contribution to the snapshot.
|
|
251
|
+
if (child.read.kind !== 'record' || (expenseReportAttachment && child.resource === 'expense_items'))
|
|
252
|
+
return Promise.resolve(undefined);
|
|
253
|
+
return acquireAnchor(child.resource, child.read.record, depth + 1, false);
|
|
254
|
+
}));
|
|
238
255
|
return { kind: 'record', resource, record: rec, payload, children: children.map((child, index) => ({ ...child, tree: descendants[index] })) };
|
|
239
256
|
}
|
|
240
257
|
catch (error) {
|
package/dist/write/evaluate.d.ts
CHANGED
|
@@ -77,8 +77,9 @@ export declare function matchesPin(submitter: unknown, pin: number): boolean;
|
|
|
77
77
|
/**
|
|
78
78
|
* Issue #377: an account-wide operation (hazard `account_wide`, the SDK's `metadata.accountWide`: tenant
|
|
79
79
|
* configuration such as UDF definitions and their list items) writes a record that belongs to no company, so
|
|
80
|
-
* a company run scope can never admit it, whatever the payload or parent.
|
|
81
|
-
*
|
|
80
|
+
* a company run scope can never admit it, whatever the payload or parent. Staff and reimbursement attachments
|
|
81
|
+
* also lack a company owner, even when incidental associations mention companies. Refuse these operations before
|
|
82
|
+
* any preview read and on every apply evaluation unless the run scope permits the entire account.
|
|
82
83
|
*/
|
|
83
|
-
export declare function
|
|
84
|
+
export declare function writeScopeReason(op: string, hazards: readonly Hazard[], runScope: RunScope | undefined): Reason | undefined;
|
|
84
85
|
export declare function evaluate(loaded: LoadedPolicy, facts: WriteFacts, runScope: RunScope | undefined, counters: Counters): Decision;
|
package/dist/write/evaluate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { hardRuleFor } from './hard-rules.js';
|
|
2
2
|
import { recordById } from '../tools/catalog-data.js';
|
|
3
3
|
import { cleanUntrustedText } from '../tools/results/untrusted.js';
|
|
4
|
+
import { staffAttachmentScopeReason } from '../policy.js';
|
|
4
5
|
/** The only operation the submitter pin can admit. */
|
|
5
6
|
export const PIN_OP = 'expense_reports.create';
|
|
6
7
|
/** The audit rule id of every pin allow and deny. */
|
|
@@ -44,10 +45,14 @@ function pinAdmits(loaded, facts) {
|
|
|
44
45
|
/**
|
|
45
46
|
* Issue #377: an account-wide operation (hazard `account_wide`, the SDK's `metadata.accountWide`: tenant
|
|
46
47
|
* configuration such as UDF definitions and their list items) writes a record that belongs to no company, so
|
|
47
|
-
* a company run scope can never admit it, whatever the payload or parent.
|
|
48
|
-
*
|
|
48
|
+
* a company run scope can never admit it, whatever the payload or parent. Staff and reimbursement attachments
|
|
49
|
+
* also lack a company owner, even when incidental associations mention companies. Refuse these operations before
|
|
50
|
+
* any preview read and on every apply evaluation unless the run scope permits the entire account.
|
|
49
51
|
*/
|
|
50
|
-
export function
|
|
52
|
+
export function writeScopeReason(op, hazards, runScope) {
|
|
53
|
+
const staffAttachment = staffAttachmentScopeReason(op, runScope);
|
|
54
|
+
if (staffAttachment !== undefined)
|
|
55
|
+
return staffAttachment;
|
|
51
56
|
if (runScope === undefined || !('companyIds' in runScope) || !hazards.includes('account_wide'))
|
|
52
57
|
return undefined;
|
|
53
58
|
return {
|
|
@@ -72,9 +77,9 @@ export function evaluate(loaded, facts, runScope, counters) {
|
|
|
72
77
|
return deny('OP_NOT_ALLOWED', `AUTOTASK_WRITE denies ${facts.op}`, hard.hazards);
|
|
73
78
|
if (runScope === undefined)
|
|
74
79
|
return deny('TARGET_NOT_IN_SCOPE', 'this principal has no run scope', hard.hazards);
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
return { decision: 'deny', reasons: [
|
|
80
|
+
const scopeRefusal = writeScopeReason(facts.op, hard.hazards, runScope);
|
|
81
|
+
if (scopeRefusal !== undefined)
|
|
82
|
+
return { decision: 'deny', reasons: [scopeRefusal], hazards: hard.hazards };
|
|
78
83
|
let pinned = false;
|
|
79
84
|
if (!inScope(facts, runScope)) {
|
|
80
85
|
// The pin only ever replaces a missing company: an anchored payload (companyIds non-empty) keeps the normal path.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iit-mcp-autotask",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.13",
|
|
4
4
|
"description": "MCP server for the Autotask (Datto) PSA domain, built on the node-autotask SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Max Soukhomlinov",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@modelcontextprotocol/server": "^2.2.0",
|
|
57
|
-
"node-autotask": "0.
|
|
57
|
+
"node-autotask": "0.83.0",
|
|
58
58
|
"zod": "^4.6.7"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
package/server.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iit-mcp-autotask",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.13",
|
|
4
4
|
"description": "MCP server for the Autotask (Datto) PSA API, powered by the node-autotask SDK",
|
|
5
5
|
"mcpProtocolBaseline": "2026-07-28",
|
|
6
6
|
"legacyProtocolFallback": "2025-11-25",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"capabilitiesManifest": "capabilities.json",
|
|
63
63
|
"sdk": {
|
|
64
64
|
"package": "node-autotask",
|
|
65
|
-
"versionRange": "0.
|
|
65
|
+
"versionRange": "0.83.0"
|
|
66
66
|
},
|
|
67
67
|
"vendorExtensions": false,
|
|
68
68
|
"credentialModelNote": "per-request; server-held under stdio or, on HTTP, only behind AUTOTASK_HTTP_AUTH=tokens; operator plans and the ledger are keyed by principal and tenant id, never by credential, and an apply authenticates the request credential and restores the plan's per-write impersonation"
|