Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/33345-sweep-refusal-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/spec': patch
'@objectstack/metadata-protocol': patch
'@objectstack/plugin-security': patch
'@objectstack/cli': patch
---

fix: four refusals say what the author can act on — the clone control by its console label, an empty or short unknown key, and an unknown CLI command

Clause-②: no
Metadata-protocol: none

Nothing new is accepted or refused; only the words change.

- **Packaged permission sets.** The `ITEM_LOCKED` save refusal and the `NOT_OVERRIDABLE` lock refusals sent the admin to a "Clone" action. Studio's Access pillar and Setup label that control "New similar" ("新建类似" in a Chinese session), so the diagnostic and both end-user messages, in every language they ship, now name it that way.
- **Unknown keys.** A refusal naming an empty key printed it as empty backticks; it now says "an empty key (`""`)" and offers no rename. On a key of five characters or fewer, a "Did you mean" rename is offered only when the declared key is one edit away, counting a swap of two adjacent letters as one: `lable` → `label` is still offered, while a removed `aria` is no longer answered with `areas`.
- **CLI.** `os <topic> <unknown>` and `os <unknown>` still exit 2 without running anything, and now name the command as typed (`command environments frobnicate not found`) and end with the help that lists the real ones (`See more help with \`os environments --help\``).
7 changes: 5 additions & 2 deletions content/docs/ai/connect-mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,11 @@ can reach is the **default exposure policy (v1)**:
are exposed the same way, with `ai.requiresConfirmation: true`, and forward to
their approvals routes as the caller. The approval service admits the
submitter, and for recalling a pending request the administrator who may
override it; anyone else is refused (`FORBIDDEN`) and the request does not
move. A recalled request is closed: to send the record for approval again,
override it; anyone else is refused and the request does not move. A caller
who cannot read the request is answered `404 REQUEST_NOT_FOUND`, exactly as
for an id that names no request, so the refusal does not tell them the request
exists; one who can read it (a pending approver, say) is answered
`403 FORBIDDEN`. A recalled request is closed: to send the record for approval again,
the agent uses the app's own submit action. Remind, request-info and comments
are not exposed.

Expand Down
2 changes: 1 addition & 1 deletion content/docs/concepts/metadata-lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ See [ADR-0005](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/
| :--- | :--- |
| `flow` | Declare an override from the base's paired `<base>.custom`, or rename it (a write from any other package is told to rename: only the pair declares an override), or switch it off (`POST /api/v1/automation/:name/toggle`, body `{enabled: false}`). The declared override is armed in the base flow's place, keeps its one activation switch, and a run suspended on the base finishes on the version it started on (ADR-0146 D9). A copy under a new name is "New similar", the clone door `POST /api/v1/automation/:name/clone` (body `{name, label}`), which the removal refusal still names. A flow that holds a credential (an inbound hook's `secret`, an `http` node's `signingSecret`) is not cloned in one step: the clone door refuses it with `409`, because a copy would share the secret, and the copy is authored as a new flow with its own. The copy is written switched off, into the source package's paired customization package `<base>.custom` (created on first use; a kernel package, of scope `system` or `cloud`, has no pair in this version, so a copy of a flow it ships answers the ensure door's `409` until the body names `package`), or into the writable package the body's optional `package` names; a flow no read-only package ships has no pair, so its clone names `package`. The answer's `packageId` says where the copy landed ([ADR-0146](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/0146-studio-designs-setup-administers-one-editor-per-item-paired-customize-package.md) D3, D4). |
| `action` | Switch it off (`POST /api/v1/actions/_activation/:object/:action`, body `{enabled: false}`; `:object` is `global` for an object-less action). No clone is offered. |
| `permission` | Clone it under a new name: the "Clone" action on the permission set, or the clone door `POST /api/v1/security/permission-sets/:name/clone` (body `{name, label, package?}`) with a new name. The clone door copies the whole definition from the security catalog; a copy of a packaged set lands in the package's paired `<X>.custom`, and a copy of a set a kernel package ships lands environment-wide (ADR-0146 D3/D6). |
| `permission` | Clone it under a new name: the "New similar" action on the permission set, or the clone door `POST /api/v1/security/permission-sets/:name/clone` (body `{name, label, package?}`) with a new name. The clone door copies the whole definition from the security catalog; a copy of a packaged set lands in the package's paired `<X>.custom`, and a copy of a set a kernel package ships lands environment-wide (ADR-0146 D3/D6). |

A permission set and a position also have a switch, outside the refusal: `POST /api/v1/security/_activation/:type/:name` (`:type` = `permission` or `position`), body `{enabled: false}`, switches one off for the deployment. The refusal does not name it: a packaged position's refusal keeps the managed seal's edit remedy. The audience anchors `everyone` and `guest` are not switchable.

Expand Down
2 changes: 1 addition & 1 deletion content/docs/permissions/authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ only what it owns:
of the write: `permission` declares `allowEnvironmentOverlay: false`
(ADR-0005's security row — overlays of the authorization surface would
create silent privilege drift), so no environment-scope overlay is minted,
and the refusal names the clone (the "Clone" action on the set, or
and the refusal names the clone (the "New similar" action on the set, or
`POST /api/v1/security/permission-sets/:name/clone`). Narrowing the packaged
set itself takes the channel ADR-0086 two-doors always named: **edit the
package and re-publish**. (ADR-0094 D5's 2026-07-14 direction — translate
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"glob": "**/*.js"
},
"hooks": {
"preparse": "./dist/hooks/preparse/strip-arg-separator.js"
"preparse": "./dist/hooks/preparse/strip-arg-separator.js",
"command_not_found": "./dist/hooks/command-not-found/point-at-help.js"
},
"topicSeparator": " ",
"topics": {
Expand Down
52 changes: 52 additions & 0 deletions packages/cli/src/hooks/command-not-found/point-at-help.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import hook, { commandNotFoundMessage, type CommandNotFoundConfig } from './point-at-help.js';

const HERE = dirname(fileURLToPath(import.meta.url));
const PKG = resolve(HERE, '../../../package.json');

/** A command table with one topic (`environments`), one nested topic and one command under a topic. */
const config: CommandNotFoundConfig = {
bin: 'os',
topicSeparator: ' ',
findTopic: (id) => ['environments', 'plugin', 'plugin:trust', 'migrate'].includes(id),
findCommand: (id) => ['migrate:plan', 'dev'].includes(id),
};

const refusal = async (id: string): Promise<any> => {
try {
await (hook as unknown as (opts: { id: string; config: CommandNotFoundConfig }) => Promise<unknown>)({ id, config });
} catch (error) {
return error;
}
throw new Error('expected the hook to refuse');
};

describe('an unknown command points at the help that lists the real ones', () => {
it('a topic-level unknown subcommand: the id as typed, and the topic\'s own help', async () => {
const error = await refusal('environments:frobnicate');
expect(error.oclif?.exit).toBe(2);
expect(error.message).toBe('command environments frobnicate not found\nSee more help with `os environments --help`');
});

it('a top-level unknown command points at the root help', async () => {
const error = await refusal('frobnicate');
expect(error.oclif?.exit).toBe(2);
expect(error.message).toBe('command frobnicate not found\nSee more help with `os --help`');
});

it('the deepest topic or command the typed words reached is the one named', () => {
expect(commandNotFoundMessage('plugin:trust:frobnicate', config)).toContain('`os plugin trust --help`');
expect(commandNotFoundMessage('migrate:plan:frobnicate', config)).toContain('`os migrate plan --help`');
expect(commandNotFoundMessage('nope:frobnicate', config)).toContain('`os --help`');
});

it('is registered as the CLI\'s command_not_found hook, from the built tree', () => {
const manifest = JSON.parse(readFileSync(PKG, 'utf8'));
expect(manifest.oclif.hooks.command_not_found).toBe('./dist/hooks/command-not-found/point-at-help.js');
});
});
50 changes: 50 additions & 0 deletions packages/cli/src/hooks/command-not-found/point-at-help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { Errors, type Hook } from '@oclif/core';

/**
* An unknown command ends with a pointer to the help that lists the real ones.
*
* Without this hook oclif answers `os environments frobnicate` with one line,
* `command environments:frobnicate not found`, and nothing else: the id in its
* internal colon spelling (this CLI separates topics with a space) and no way
* forward. A wrong FLAG already ends with oclif's `See more help with --help`;
* a wrong command name did not, at the top level or under a topic.
*
* The answer is unchanged in kind — a hard error, exit 2, the command never
* runs, and no guess at what was meant (this CLI ships no not-found suggester;
* a typo is refused, not reinterpreted). Only the words change: the id is
* spelled the way it was typed, and the pointer names the help of the deepest
* topic or command the typed words did reach (`os environments --help`), or
* the root's (`os --help`) when the first word is already unknown.
*/

/** The slice of oclif's `Config` the message reads. */
export interface CommandNotFoundConfig {
bin: string;
topicSeparator: string;
findTopic(id: string): unknown;
findCommand(id: string): unknown;
}

/** The refusal's text: what was not found, then where its siblings are listed. */
export function commandNotFoundMessage(id: string, config: CommandNotFoundConfig): string {
const separator = config.topicSeparator || ':';
const segments = id.split(':').filter((segment) => segment !== '');
let reached: string[] = [];
for (let length = segments.length - 1; length > 0; length -= 1) {
const prefix = segments.slice(0, length).join(':');
if (config.findTopic(prefix) || config.findCommand(prefix)) {
reached = segments.slice(0, length);
break;
}
}
const help = [config.bin, ...reached, '--help'].join(' ');
return `command ${segments.join(separator)} not found\nSee more help with \`${help}\``;
}

const hook: Hook<'command_not_found'> = async function ({ id, config }) {
throw new Errors.CLIError(commandNotFoundMessage(id, config), { exit: 2 });
};

export default hook;
8 changes: 5 additions & 3 deletions packages/metadata-protocol/src/packaged-base-regime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
* the action-clone half is not chartered, so a clone route named here would
* advertise one that does not exist;
* - `permission` — the clone only (§8 item 3, the landed lock-and-clone
* machinery): the "Clone" action on the permission set, which posts the copy
* to `POST /data/sys_permission_set` under a new name. Spelled as
* machinery): the "New similar" action on the permission set — the label
* the console draws on that control in Studio's Access pillar and in Setup
* (`perm.clone.action`) — which posts the copy to the catalog's clone door,
* `POST /security/permission-sets/:name/clone`, under a new name. Spelled as
* `plugin-security`'s own lock refusal spells that same path
* (`packaged-permission-set-lock.ts`), so one condition reads one way at
* every door;
Expand Down Expand Up @@ -201,7 +203,7 @@ export const PACKAGED_BASE_REGIME: Readonly<Record<string, PackagedBaseRegimeRow
permission: {
regime: 'C',
routes: {
clone: 'the "Clone" action on the permission set, '
clone: 'the "New similar" action on the permission set, '
+ 'or POST /api/v1/security/permission-sets/:name/clone with a new name',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('packagedBaseRefusal — each Regime C type names its OWN sanctioned pa
const message = expectRegimeC(refusalOn(environmentId, 'permission', 'pkg_perm', 'save'), 'permission', 'pkg_perm', 'save');
// The clone route's spelling moved with C3 stage 8 (the retired
// object's data route → the catalog's clone door); the sentence did not.
expect(message).toContain('Clone it under a new name to customize it (the "Clone" action on the permission set, or POST /api/v1/');
expect(message).toContain('Clone it under a new name to customize it (the "New similar" action on the permission set, or POST /api/v1/');
expect(message).toContain(' with a new name).');
expect(message.toLowerCase()).not.toContain('switch it off');
expect(message).not.toContain('_activation');
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('packagedBaseRefusal — each Regime C type names its OWN sanctioned pa
for (const [type, name, path] of [
['flow', 'pkg_flow', 'POST /api/v1/automation/:name/clone'],
['action', 'pkg_action', 'POST /api/v1/actions/_activation/:object_or_global/:action'],
['permission', 'pkg_perm', 'the "Clone" action on the permission set, or POST /api/v1/'],
['permission', 'pkg_perm', 'the "New similar" action on the permission set, or POST /api/v1/'],
] as const) {
const r: any = p.packagedBaseRefusal({ type, name, operation: 'save', packageId: PACKAGE_ID });
expect({ code: r?.code, status: r?.status, lockSource: r?.lockSource, packageId: r?.packageId }, type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
* discharged, not still standing — do not read the history as a live warning.
*/

// Pays the lint root's first load at collection, never inside a clocked case.
import './lint-root-preload.testkit.js';
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
// [#5619] The producer's OWN write-verb dispatch decisions (#4550 delete /
// #5480 update), so the fake engine below cannot accept a call ObjectQL
Expand Down Expand Up @@ -581,7 +583,7 @@ describe('#7682 — the refusal discriminates on package writability', () => {
// The clone route is the catalog's clone door: the data route of the
// `sys_permission_set` object retired with it (C3 stage 8).
expect(message).toContain(
'Clone it under a new name to customize it (the "Clone" action on the permission set, '
'Clone it under a new name to customize it (the "New similar" action on the permission set, '
+ 'or POST /api/v1/security/permission-sets/:name/clone with a new name).',
);
expect(message).not.toContain('OS_METADATA_WRITABLE');
Expand Down Expand Up @@ -1265,7 +1267,7 @@ describe('[#20910] the repository doors name a Regime C type\'s sanctioned path,
+ 'operator-only where one install serves several organizations).';
// The clone route is the catalog's clone door: the data route of the
// `sys_permission_set` object retired with it (C3 stage 8).
const PERMISSION_CLONE = 'Clone it under a new name to customize it (the "Clone" action on the permission set, '
const PERMISSION_CLONE = 'Clone it under a new name to customize it (the "New similar" action on the permission set, '
+ 'or POST /api/v1/security/permission-sets/:name/clone with a new name).';
const FLOW_PATHS = 'Clone it under a new name to customize it (POST /api/v1/automation/:name/clone, body {name, label}), '
+ 'or switch it off (POST /api/v1/automation/:name/toggle, body {enabled: false}; '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,34 @@ describe('[#32780] a stored permission set in its package\'s registry slot is ne
expect(classifyPackagedPermissionSet(N, ql)).toEqual({ status: 'packaged', packageId: CRM, packageIds: [CRM] });
});
});

// The control the refusal sends the admin to is named by the label the console
// draws on it: "New similar" (Studio's Access pillar and Setup, the console's
// `perm.clone.action`), "新建类似" in a Chinese session, Traditional included,
// and the English label in every language the console's designer strings do
// not ship. A sentence naming a "Clone" button points at a control that is not there.
describe('the lock refusals name the clone control by its console label', () => {
const LOCALES = ['en', 'zh-Hans', 'zh-Hant', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru', 'ar'];
const CHINESE = new Set(['zh-Hans', 'zh-Hant']);
const refusals = (locale: string) => [
new PackagedPermissionSetLockedError('crm_sales', 'com.example.crm', 'update', [locale]),
new PackagedPermissionSetProvenanceUnknownError('crm_sales', 'registry unavailable', [locale]),
];

for (const locale of LOCALES) {
it(`${locale}: the guidance names the "${CHINESE.has(locale) ? '新建类似' : 'New similar'}" action`, () => {
for (const refusal of refusals(locale)) {
expect(refusal.code).toBe('NOT_OVERRIDABLE');
expect(refusal.status).toBe(403);
expect(refusal.userMessage).toContain(CHINESE.has(locale) ? '新建类似' : 'New similar');
expect(refusal.userMessage).not.toMatch(/Clone action|“克隆”|「複製」動作|「複製」アクション|Clonar|Cloner|„Klonen“|«Клонировать»|복제 작업/);
}
});
}

it('the diagnostic names the same control', () => {
const [locked] = refusals('en');
expect(locked.message).toContain('the "New similar" action on the permission set, or POST /api/v1/security/permission-sets/crm_sales/clone');
expect(locked.message).not.toContain('"Clone" action');
});
});
Loading
Loading