@sparkelf/dsh-dataops-managed 0.3.41 → 0.3.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -972,6 +972,75 @@ function isToolCapabilityEnabled(name, state) {
972
972
  if (!state.enabled) return false;
973
973
  return state.capabilities[policy.capability] ?? policy.defaultEnabled ?? false;
974
974
  }
975
+ /** Keys a group-chat Session may carry as its opaque `actor`. */
976
+ const ACTOR_KEYS = [
977
+ "roleCodes",
978
+ "systemKeys",
979
+ "permissions",
980
+ "permissionKeys",
981
+ "primaryRole",
982
+ "userId"
983
+ ];
984
+ /**
985
+ * Whether an opaque Session actor is a usable DataOps scope.
986
+ *
987
+ * `Session.actor` is untyped by design -- the base never interprets it -- so the connector has to
988
+ * decide here. A value without any of the scope's identifying fields is not one of ours, and a
989
+ * disclosure rule must then hide rather than fall through to the workspace's scope: the Session
990
+ * belongs to someone else.
991
+ * @param actor - the opaque value the Session carries.
992
+ * @returns true when the actor can be read as a {@link DataOpsScope}.
993
+ */
994
+ function isScopeActor(actor) {
995
+ return isRecord$1(actor) && ACTOR_KEYS.some((key) => key in actor);
996
+ }
997
+ /**
998
+ * Whether the model must not see one managed tool in this Session.
999
+ *
1000
+ * A Session carrying a scope-like actor is a group-chat room acting for a member: the member's
1001
+ * own scope decides, never the workspace's. Otherwise the workspace scope applies, which is exactly
1002
+ * what the registration set was derived from, so an ordinary Session sees no change at all.
1003
+ * @param name - the registered tool name.
1004
+ * @param actor - `Session.actor`, or undefined outside a room.
1005
+ * @param workspaceScope - the scope the registration set was built from.
1006
+ * @returns true to hide the tool for this Session.
1007
+ */
1008
+ function sessionHidesTool(name, actor, workspaceScope) {
1009
+ if (actor !== void 0) return !isScopeActor(actor) || !isToolVisible(name, actor);
1010
+ if (workspaceScope === void 0) return true;
1011
+ return !isToolVisible(name, workspaceScope);
1012
+ }
1013
+ /**
1014
+ * Whether the model must not see one skill in this Session.
1015
+ *
1016
+ * A skill declares the permissions it needs in its frontmatter; the effective scope must hold all
1017
+ * of them. Skills without such a declaration are never claimed by the rule, so the plugin's own
1018
+ * connector gate stays the only thing that hides them.
1019
+ * @param permissions - `metadata.permissions` from the candidate, when the frontmatter carried it.
1020
+ * @param actor - `Session.actor`, or undefined outside a room.
1021
+ * @param workspaceScope - the scope the registration set was built from.
1022
+ * @returns true to hide the skill for this Session.
1023
+ */
1024
+ /**
1025
+ * Read the permissions a skill's frontmatter declares.
1026
+ *
1027
+ * The candidate carries provider frontmatter as opaque `metadata`; only `permissions` is a
1028
+ * disclosure fact here. A malformed value is ignored rather than hidden: the plugin only claims
1029
+ * candidates it can read.
1030
+ * @param metadata - `SkillCandidate.metadata`, when the provider supplied one.
1031
+ * @returns the declared permission keys, or an empty list.
1032
+ */
1033
+ function skillPermissions(metadata) {
1034
+ const value = metadata?.["permissions"];
1035
+ if (!Array.isArray(value)) return [];
1036
+ return value.filter((entry) => typeof entry === "string");
1037
+ }
1038
+ function sessionHidesSkill(permissions, actor, workspaceScope) {
1039
+ const effective = actor !== void 0 ? isScopeActor(actor) ? actor : void 0 : workspaceScope;
1040
+ if (effective === void 0) return true;
1041
+ const held = new Set(permissionList(effective) ?? []);
1042
+ return !permissions.every((permission) => held.has(permission));
1043
+ }
975
1044
  function isToolVisible(name, scope) {
976
1045
  const policy = AI_TOOL_ACCESS[name];
977
1046
  if (policy.superAdminOnly === true && !isSuperAdmin(scope)) return false;
@@ -4134,6 +4203,30 @@ async function apply(ctx, config) {
4134
4203
  return (scope.permissions ?? scope.permissionKeys ?? []).includes(CONNECTOR_SKILL_PERMISSION);
4135
4204
  };
4136
4205
  ctx.effect(() => () => aiTools.dispose(), "dataops-managed: skill and review tool disclosure");
4206
+ /**
4207
+ * Per-session disclosure.
4208
+ *
4209
+ * The registration set above is global to the workspace; a group-chat room acts for one member,
4210
+ * so its Session carries that member's scope as an opaque actor and the base asks these rules
4211
+ * while it assembles the step. Both registries are optional: an older base without them keeps
4212
+ * today's workspace-wide behaviour, and `addVisibilityFilter` is only called when it exists.
4213
+ */
4214
+ ctx.effect(() => {
4215
+ const tools = ctx.tools;
4216
+ const skills = ctx.skills;
4217
+ const disposers = [];
4218
+ if (typeof tools.addVisibilityFilter === "function") disposers.push(tools.addVisibilityFilter({
4219
+ appliesTo: (tool) => tool.name.startsWith("dataops_"),
4220
+ hidden: (session, tool) => sessionHidesTool(tool.name, session?.actor, aiTools.currentScope())
4221
+ }));
4222
+ if (typeof skills.addVisibilityFilter === "function") disposers.push(skills.addVisibilityFilter({
4223
+ appliesTo: (candidate) => skillPermissions(candidate.metadata).length > 0,
4224
+ hidden: (session, candidate) => sessionHidesSkill(skillPermissions(candidate.metadata), session?.actor, aiTools.currentScope())
4225
+ }));
4226
+ return () => {
4227
+ for (const dispose of disposers.splice(0)) dispose();
4228
+ };
4229
+ }, "dataops-managed: per-session tool and skill disclosure");
4137
4230
  ctx.effect(() => ctx.on("credentials/reference-updated", (ref) => {
4138
4231
  if (String(ref) !== config.credentialRef) return;
4139
4232
  aiTools.refresh(true);
@@ -209,6 +209,51 @@ export declare function isToolCapabilityEnabled(name: AiToolName, state: {
209
209
  readonly enabled: boolean;
210
210
  readonly capabilities: Record<string, boolean>;
211
211
  }): boolean;
212
+ /**
213
+ * Whether an opaque Session actor is a usable DataOps scope.
214
+ *
215
+ * `Session.actor` is untyped by design -- the base never interprets it -- so the connector has to
216
+ * decide here. A value without any of the scope's identifying fields is not one of ours, and a
217
+ * disclosure rule must then hide rather than fall through to the workspace's scope: the Session
218
+ * belongs to someone else.
219
+ * @param actor - the opaque value the Session carries.
220
+ * @returns true when the actor can be read as a {@link DataOpsScope}.
221
+ */
222
+ export declare function isScopeActor(actor: unknown): actor is DataOpsScope;
223
+ /**
224
+ * Whether the model must not see one managed tool in this Session.
225
+ *
226
+ * A Session carrying a scope-like actor is a group-chat room acting for a member: the member's
227
+ * own scope decides, never the workspace's. Otherwise the workspace scope applies, which is exactly
228
+ * what the registration set was derived from, so an ordinary Session sees no change at all.
229
+ * @param name - the registered tool name.
230
+ * @param actor - `Session.actor`, or undefined outside a room.
231
+ * @param workspaceScope - the scope the registration set was built from.
232
+ * @returns true to hide the tool for this Session.
233
+ */
234
+ export declare function sessionHidesTool(name: AiToolName, actor: unknown, workspaceScope: DataOpsScope | undefined): boolean;
235
+ /**
236
+ * Whether the model must not see one skill in this Session.
237
+ *
238
+ * A skill declares the permissions it needs in its frontmatter; the effective scope must hold all
239
+ * of them. Skills without such a declaration are never claimed by the rule, so the plugin's own
240
+ * connector gate stays the only thing that hides them.
241
+ * @param permissions - `metadata.permissions` from the candidate, when the frontmatter carried it.
242
+ * @param actor - `Session.actor`, or undefined outside a room.
243
+ * @param workspaceScope - the scope the registration set was built from.
244
+ * @returns true to hide the skill for this Session.
245
+ */
246
+ /**
247
+ * Read the permissions a skill's frontmatter declares.
248
+ *
249
+ * The candidate carries provider frontmatter as opaque `metadata`; only `permissions` is a
250
+ * disclosure fact here. A malformed value is ignored rather than hidden: the plugin only claims
251
+ * candidates it can read.
252
+ * @param metadata - `SkillCandidate.metadata`, when the provider supplied one.
253
+ * @returns the declared permission keys, or an empty list.
254
+ */
255
+ export declare function skillPermissions(metadata: Readonly<Record<string, unknown>> | undefined): readonly string[];
256
+ export declare function sessionHidesSkill(permissions: readonly string[], actor: unknown, workspaceScope: DataOpsScope | undefined): boolean;
212
257
  export declare function isToolVisible(name: AiToolName, scope: DataOpsScope): boolean;
213
258
  /**
214
259
  * Validate one `/api/ai/review/context` body.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.41",
3
+ "version": "0.3.43",
4
4
  "description": "DataOps JWT intake and credential-backed MCP tools for managed DeepSeek Harness workspaces.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",