@skrr-ai/cli 0.1.174 → 0.1.175

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.
@@ -1,9 +1,10 @@
1
1
  import { BaseCommand } from '../../../base-command';
2
2
  /**
3
- * Release a managed inference provider to one account (OSK-24530).
3
+ * Release a managed inference provider to one account or one workspace
4
+ * (OSK-24530, workspace subjects OSK-24522).
4
5
  *
5
- * Takes effect on that account's next turn, with no deploy. Idempotent: an
6
- * account that already holds an active grant keeps it, unchanged.
6
+ * Takes effect on the subject's next turn, with no deploy. Idempotent: a subject
7
+ * that already holds an active grant keeps it, unchanged.
7
8
  */
8
9
  export default class HarnessesRolloutsGrant extends BaseCommand {
9
10
  static aliases: string[];
@@ -14,7 +15,8 @@ export default class HarnessesRolloutsGrant extends BaseCommand {
14
15
  };
15
16
  static flags: {
16
17
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
- user: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
18
+ user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'for-workspace': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
20
  reason: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
19
21
  };
20
22
  run(): Promise<void>;
@@ -4,17 +4,19 @@ const core_1 = require("@oclif/core");
4
4
  const base_command_1 = require("../../../base-command");
5
5
  const provider_rollouts_1 = require("../../../lib/provider-rollouts");
6
6
  /**
7
- * Release a managed inference provider to one account (OSK-24530).
7
+ * Release a managed inference provider to one account or one workspace
8
+ * (OSK-24530, workspace subjects OSK-24522).
8
9
  *
9
- * Takes effect on that account's next turn, with no deploy. Idempotent: an
10
- * account that already holds an active grant keeps it, unchanged.
10
+ * Takes effect on the subject's next turn, with no deploy. Idempotent: a subject
11
+ * that already holds an active grant keeps it, unchanged.
11
12
  */
12
13
  class HarnessesRolloutsGrant extends base_command_1.BaseCommand {
13
14
  static aliases = ['harnesses:rollouts:grant'];
14
- static description = 'Release a managed inference provider to one account (platform admins)';
15
+ static description = 'Release a managed inference provider to one account or workspace (platform admins)';
15
16
  static examples = [
16
17
  '<%= config.bin %> harnesses rollouts grant copilot-sdk --user me --reason "Owner probe of the Copilot SDK backend"',
17
18
  '<%= config.bin %> harnesses rollouts grant copilot-sdk --user <user-id> --reason "Design partner pilot" --json',
19
+ '<%= config.bin %> harnesses rollouts grant copilot-sdk --for-workspace <workspace-id> --reason "Widen the canary to the workspace"',
18
20
  ];
19
21
  static args = {
20
22
  provider: core_1.Args.string({
@@ -25,7 +27,14 @@ class HarnessesRolloutsGrant extends base_command_1.BaseCommand {
25
27
  };
26
28
  static flags = {
27
29
  json: core_1.Flags.boolean({ description: 'Output as JSON' }),
28
- user: core_1.Flags.string({ description: 'User id to release it to, or `me`', required: true }),
30
+ user: core_1.Flags.string({
31
+ description: 'User id to release it to, or `me` (exactly one of --user or --for-workspace)',
32
+ exactlyOne: ['user', 'for-workspace'],
33
+ }),
34
+ 'for-workspace': core_1.Flags.string({
35
+ description: 'Workspace id to release it to: admits turns that run in and are paid for by that workspace (exactly one of --user or --for-workspace)',
36
+ exactlyOne: ['user', 'for-workspace'],
37
+ }),
29
38
  reason: core_1.Flags.string({
30
39
  description: 'Why (8-512 characters). Recorded on the grant with your account.',
31
40
  required: true,
@@ -34,9 +43,16 @@ class HarnessesRolloutsGrant extends base_command_1.BaseCommand {
34
43
  async run() {
35
44
  this.requireAuth();
36
45
  const { args, flags } = await this.parse(HarnessesRolloutsGrant);
46
+ let subject;
47
+ try {
48
+ subject = (0, provider_rollouts_1.providerRolloutSubjectFromFlags)(flags);
49
+ }
50
+ catch (err) {
51
+ this.error(err.message, { exit: 2 });
52
+ }
37
53
  let result;
38
54
  try {
39
- result = await (0, provider_rollouts_1.grantProviderRollout)(args.provider, { type: 'user', id: flags.user }, flags.reason);
55
+ result = await (0, provider_rollouts_1.grantProviderRollout)(args.provider, subject, flags.reason);
40
56
  }
41
57
  catch (err) {
42
58
  this.handleApiError(err);
@@ -47,9 +63,13 @@ class HarnessesRolloutsGrant extends base_command_1.BaseCommand {
47
63
  return;
48
64
  }
49
65
  const { grant } = result;
66
+ const named = `${grant.subjectType} ${grant.subjectId}`;
67
+ const reaches = grant.subjectType === 'workspace'
68
+ ? 'Turns that run in that workspace, and that it pays for, can now run on managed inference.'
69
+ : 'Their next turn on it can run on managed inference.';
50
70
  this.log(result.created
51
- ? `Released ${grant.provider} to user ${grant.subjectId} (grant ${grant.grantId}). Their next turn on it can run on managed inference.`
52
- : `User ${grant.subjectId} already holds ${grant.provider} (grant ${grant.grantId}); nothing changed.`);
71
+ ? `Released ${grant.provider} to ${named} (grant ${grant.grantId}). ${reaches}`
72
+ : `${named} already holds ${grant.provider} (grant ${grant.grantId}); nothing changed.`);
53
73
  this.log('The payer’s managed inference policy must still permit the provider; this grant does not widen it.');
54
74
  }
55
75
  }
@@ -1,13 +1,18 @@
1
1
  import { BaseCommand } from '../../../base-command';
2
2
  import { type ProviderRolloutGrant } from '../../../lib/provider-rollouts';
3
- /** One table row per grant; `revoked <when>` keeps a withdrawn release readable. */
3
+ /**
4
+ * One table row per grant; `revoked <when>` keeps a withdrawn release readable.
5
+ * SUBJECT carries its type (`user:<id>`, `workspace:<id>`), because the same id
6
+ * space is never shared and a person reading the row must know which one it is.
7
+ */
4
8
  export declare function rolloutRows(grants: ProviderRolloutGrant[]): Array<Record<string, string>>;
5
9
  /**
6
- * Who a managed inference provider has been released to (OSK-24530).
10
+ * Who a managed inference provider has been released to (OSK-24530): people and
11
+ * workspaces (OSK-24522).
7
12
  *
8
13
  * Platform admins only. A provider the server lists here is closed on managed
9
- * inference to every account that holds no active grant, whatever the payer's
10
- * policy permits.
14
+ * inference to every turn that neither its person nor the workspace paying for
15
+ * it holds an active grant for, whatever the payer's policy permits.
11
16
  */
12
17
  export default class HarnessesRolloutsList extends BaseCommand {
13
18
  static aliases: string[];
@@ -17,6 +22,7 @@ export default class HarnessesRolloutsList extends BaseCommand {
17
22
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
23
  provider: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
24
  user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
25
+ 'for-workspace': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
26
  'include-revoked': import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
27
  limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
28
  };
@@ -6,7 +6,11 @@ const base_command_1 = require("../../../base-command");
6
6
  const format_1 = require("../../../lib/format");
7
7
  const list_output_1 = require("../../../lib/list-output");
8
8
  const provider_rollouts_1 = require("../../../lib/provider-rollouts");
9
- /** One table row per grant; `revoked <when>` keeps a withdrawn release readable. */
9
+ /**
10
+ * One table row per grant; `revoked <when>` keeps a withdrawn release readable.
11
+ * SUBJECT carries its type (`user:<id>`, `workspace:<id>`), because the same id
12
+ * space is never shared and a person reading the row must know which one it is.
13
+ */
10
14
  function rolloutRows(grants) {
11
15
  return grants.map((grant) => ({
12
16
  grant: grant.grantId,
@@ -18,11 +22,12 @@ function rolloutRows(grants) {
18
22
  }));
19
23
  }
20
24
  /**
21
- * Who a managed inference provider has been released to (OSK-24530).
25
+ * Who a managed inference provider has been released to (OSK-24530): people and
26
+ * workspaces (OSK-24522).
22
27
  *
23
28
  * Platform admins only. A provider the server lists here is closed on managed
24
- * inference to every account that holds no active grant, whatever the payer's
25
- * policy permits.
29
+ * inference to every turn that neither its person nor the workspace paying for
30
+ * it holds an active grant for, whatever the payer's policy permits.
26
31
  */
27
32
  class HarnessesRolloutsList extends base_command_1.BaseCommand {
28
33
  static aliases = ['harnesses:rollouts:list'];
@@ -31,11 +36,19 @@ class HarnessesRolloutsList extends base_command_1.BaseCommand {
31
36
  '<%= config.bin %> harnesses rollouts list',
32
37
  '<%= config.bin %> harnesses rollouts list --provider copilot-sdk',
33
38
  '<%= config.bin %> harnesses rollouts list --user <user-id> --include-revoked --json',
39
+ '<%= config.bin %> harnesses rollouts list --for-workspace <workspace-id>',
34
40
  ];
35
41
  static flags = {
36
42
  json: core_1.Flags.boolean({ description: 'Output as JSON' }),
37
43
  provider: core_1.Flags.string({ description: 'Only this provider (for example copilot-sdk)' }),
38
- user: core_1.Flags.string({ description: 'Only grants naming this user id' }),
44
+ user: core_1.Flags.string({
45
+ description: 'Only grants naming this user id',
46
+ exclusive: ['for-workspace'],
47
+ }),
48
+ 'for-workspace': core_1.Flags.string({
49
+ description: 'Only grants naming this workspace id',
50
+ exclusive: ['user'],
51
+ }),
39
52
  'include-revoked': core_1.Flags.boolean({
40
53
  description: 'Include withdrawn grants (kept as the record of who released and withdrew it)',
41
54
  }),
@@ -46,9 +59,10 @@ class HarnessesRolloutsList extends base_command_1.BaseCommand {
46
59
  const { flags } = await this.parse(HarnessesRolloutsList);
47
60
  let result;
48
61
  try {
62
+ const subject = flags.user || flags['for-workspace'] ? (0, provider_rollouts_1.providerRolloutSubjectFromFlags)(flags) : null;
49
63
  result = await (0, provider_rollouts_1.listProviderRollouts)({
50
64
  provider: flags.provider,
51
- subjectId: flags.user,
65
+ ...(subject ? { subjectType: subject.type, subjectId: subject.id } : {}),
52
66
  includeRevoked: flags['include-revoked'],
53
67
  limit: flags.limit,
54
68
  });
@@ -62,10 +76,10 @@ class HarnessesRolloutsList extends base_command_1.BaseCommand {
62
76
  return;
63
77
  }
64
78
  const providers = result.providers
65
- .map((entry) => `${entry.displayName} (${entry.provider})`)
79
+ .map((entry) => `${entry.displayName} (${entry.provider}, to ${entry.subjectTypes.join(' or ')})`)
66
80
  .join(', ');
67
81
  this.log(providers
68
- ? `Released per account on managed inference: ${providers}. Anyone without an active grant is refused.`
82
+ ? `Released per subject on managed inference: ${providers}. A turn is refused unless its person, or the workspace paying for it, holds an active grant.`
69
83
  : 'No provider is in the managed inference rollout; policy alone decides every provider.');
70
84
  if (result.grants.length === 0) {
71
85
  this.log(flags['include-revoked']
@@ -1,6 +1,7 @@
1
1
  import { BaseCommand } from '../../../base-command';
2
2
  /**
3
- * Withdraw a managed inference provider from one account (OSK-24530).
3
+ * Withdraw a managed inference provider from one account or one workspace
4
+ * (OSK-24530, workspace subjects OSK-24522).
4
5
  *
5
6
  * The next turn on it is refused, naming the provider. A turn already running
6
7
  * keeps the lease it was admitted with until that lease ends. The grant is kept
@@ -15,7 +16,8 @@ export default class HarnessesRolloutsRevoke extends BaseCommand {
15
16
  };
16
17
  static flags: {
17
18
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
- user: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
19
+ user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ 'for-workspace': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
21
  reason: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
20
22
  };
21
23
  run(): Promise<void>;
@@ -4,7 +4,8 @@ const core_1 = require("@oclif/core");
4
4
  const base_command_1 = require("../../../base-command");
5
5
  const provider_rollouts_1 = require("../../../lib/provider-rollouts");
6
6
  /**
7
- * Withdraw a managed inference provider from one account (OSK-24530).
7
+ * Withdraw a managed inference provider from one account or one workspace
8
+ * (OSK-24530, workspace subjects OSK-24522).
8
9
  *
9
10
  * The next turn on it is refused, naming the provider. A turn already running
10
11
  * keeps the lease it was admitted with until that lease ends. The grant is kept
@@ -12,10 +13,11 @@ const provider_rollouts_1 = require("../../../lib/provider-rollouts");
12
13
  */
13
14
  class HarnessesRolloutsRevoke extends base_command_1.BaseCommand {
14
15
  static aliases = ['harnesses:rollouts:revoke'];
15
- static description = 'Withdraw a managed inference provider from one account (platform admins)';
16
+ static description = 'Withdraw a managed inference provider from one account or workspace (platform admins)';
16
17
  static examples = [
17
18
  '<%= config.bin %> harnesses rollouts revoke copilot-sdk --user me --reason "Probe finished"',
18
19
  '<%= config.bin %> harnesses rollouts revoke copilot-sdk --user <user-id> --reason "Pilot ended" --json',
20
+ '<%= config.bin %> harnesses rollouts revoke copilot-sdk --for-workspace <workspace-id> --reason "Canary rolled back"',
19
21
  ];
20
22
  static args = {
21
23
  provider: core_1.Args.string({
@@ -26,7 +28,14 @@ class HarnessesRolloutsRevoke extends base_command_1.BaseCommand {
26
28
  };
27
29
  static flags = {
28
30
  json: core_1.Flags.boolean({ description: 'Output as JSON' }),
29
- user: core_1.Flags.string({ description: 'User id to withdraw it from, or `me`', required: true }),
31
+ user: core_1.Flags.string({
32
+ description: 'User id to withdraw it from, or `me` (exactly one of --user or --for-workspace)',
33
+ exactlyOne: ['user', 'for-workspace'],
34
+ }),
35
+ 'for-workspace': core_1.Flags.string({
36
+ description: 'Workspace id to withdraw it from (exactly one of --user or --for-workspace)',
37
+ exactlyOne: ['user', 'for-workspace'],
38
+ }),
30
39
  reason: core_1.Flags.string({
31
40
  description: 'Why (8-512 characters). Recorded on the grant with your account.',
32
41
  required: true,
@@ -35,9 +44,16 @@ class HarnessesRolloutsRevoke extends base_command_1.BaseCommand {
35
44
  async run() {
36
45
  this.requireAuth();
37
46
  const { args, flags } = await this.parse(HarnessesRolloutsRevoke);
47
+ let subject;
48
+ try {
49
+ subject = (0, provider_rollouts_1.providerRolloutSubjectFromFlags)(flags);
50
+ }
51
+ catch (err) {
52
+ this.error(err.message, { exit: 2 });
53
+ }
38
54
  let result;
39
55
  try {
40
- result = await (0, provider_rollouts_1.revokeProviderRollout)(args.provider, { type: 'user', id: flags.user }, flags.reason);
56
+ result = await (0, provider_rollouts_1.revokeProviderRollout)(args.provider, subject, flags.reason);
41
57
  }
42
58
  catch (err) {
43
59
  this.handleApiError(err);
@@ -48,7 +64,10 @@ class HarnessesRolloutsRevoke extends base_command_1.BaseCommand {
48
64
  return;
49
65
  }
50
66
  for (const grant of result.revoked) {
51
- this.log(`Withdrew ${grant.provider} from user ${grant.subjectId} (grant ${grant.grantId}). Their next turn on it is refused.`);
67
+ this.log(`Withdrew ${grant.provider} from ${grant.subjectType} ${grant.subjectId} (grant ${grant.grantId}). ` +
68
+ (grant.subjectType === 'workspace'
69
+ ? 'The next turn that workspace pays for is refused, unless the person holds their own grant.'
70
+ : 'Their next turn on it is refused, unless their workspace holds a grant for it.'));
52
71
  }
53
72
  this.log('A turn already running keeps its lease until that lease ends.');
54
73
  }
@@ -1,3 +1,4 @@
1
+ import type { HarnessCostProvenance, HarnessUsageCost } from '@skrr-ai/data-provider';
1
2
  import { BaseCommand } from '../../base-command';
2
3
  /**
3
4
  * Usage for one harness, or the rollup across all of them.
@@ -6,8 +7,19 @@ import { BaseCommand } from '../../base-command';
6
7
  * "how much did this cost" is one question the caller asks at two scopes. The
7
8
  * web makes the same pairing (`usage(id)` and `fleetUsage`).
8
9
  */
9
- /** Two decimals is how money is read; the API sends full float precision. */
10
+ /**
11
+ * Two decimals is how money is read; the API sends full float precision.
12
+ *
13
+ * Read from the server's `cost` (OSK-24547): a managed request is priced by the platform ledger,
14
+ * and `totalCostUsd` is only what the HARNESS reported, so a charged managed turn used to print
15
+ * here as nothing reported and in `--json` as `totalCostUsd: 0`. A reply from an older server
16
+ * has no `cost` and is read from the harness fields, as before.
17
+ */
10
18
  export declare function usageCost(row: UsageRow): string;
19
+ /** Where a COST figure came from, in the words the legend below the table explains. */
20
+ export declare const USAGE_COST_SOURCE_LABEL: Record<HarnessCostProvenance, string>;
21
+ /** The SOURCE cell: who priced the COST beside it. */
22
+ export declare function usageCostSource(row: UsageRow): string;
11
23
  export type UsageRow = {
12
24
  /** Fleet rollup only — one row per harness. */
13
25
  harnessId?: string;
@@ -30,6 +42,11 @@ export type UsageRow = {
30
42
  cachedInputTokens?: number;
31
43
  /** Prompt-cache writes; absent from usage recorded before OSK-10006. */
32
44
  cacheCreationInputTokens?: number;
45
+ /**
46
+ * The best-known cost and where it came from. Absent from a server that predates it, which
47
+ * `harnessUsageCost` reads from the harness fields above.
48
+ */
49
+ cost?: HarnessUsageCost;
33
50
  };
34
51
  /**
35
52
  * The rows to render, whichever spelling the server used.
@@ -61,6 +78,7 @@ export interface UsageTable {
61
78
  export declare const HARNESS_USAGE_COVERAGE: {
62
79
  scope: string;
63
80
  explanation: string;
81
+ costExplanation: string;
64
82
  };
65
83
  /** Keep the server response intact and add a machine-readable CLI explanation. */
66
84
  export declare function withUsageCoverage<T extends object>(report: T): T & {
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HARNESS_USAGE_COVERAGE = void 0;
3
+ exports.HARNESS_USAGE_COVERAGE = exports.USAGE_COST_SOURCE_LABEL = void 0;
4
4
  exports.usageCost = usageCost;
5
+ exports.usageCostSource = usageCostSource;
5
6
  exports.selectUsageRows = selectUsageRows;
6
7
  exports.usageRowHarnessCell = usageRowHarnessCell;
7
8
  exports.withUsageCoverage = withUsageCoverage;
@@ -18,14 +19,31 @@ const harnesses_1 = require("../../lib/harnesses");
18
19
  * "how much did this cost" is one question the caller asks at two scopes. The
19
20
  * web makes the same pairing (`usage(id)` and `fleetUsage`).
20
21
  */
21
- /** Two decimals is how money is read; the API sends full float precision. */
22
+ /**
23
+ * Two decimals is how money is read; the API sends full float precision.
24
+ *
25
+ * Read from the server's `cost` (OSK-24547): a managed request is priced by the platform ledger,
26
+ * and `totalCostUsd` is only what the HARNESS reported, so a charged managed turn used to print
27
+ * here as nothing reported and in `--json` as `totalCostUsd: 0`. A reply from an older server
28
+ * has no `cost` and is read from the harness fields, as before.
29
+ */
22
30
  function usageCost(row) {
23
- const status = (0, data_provider_1.harnessCostReporting)(row);
24
- if (status === 'idle' || status === 'not_reported' || status === 'unknown' ||
25
- typeof row.totalCostUsd !== 'number' || !Number.isFinite(row.totalCostUsd))
31
+ const cost = (0, data_provider_1.harnessUsageCost)(row);
32
+ if (cost.costUsd === null || !Number.isFinite(cost.costUsd))
26
33
  return '—';
27
- const value = status === 'partial' ? Math.floor(row.totalCostUsd * 100) / 100 : row.totalCostUsd;
28
- return `$${value.toFixed(2)}${status === 'partial' ? '+' : ''}`;
34
+ const value = cost.reporting === 'partial' ? Math.floor(cost.costUsd * 100) / 100 : cost.costUsd;
35
+ return `$${value.toFixed(2)}${cost.reporting === 'partial' ? '+' : ''}`;
36
+ }
37
+ /** Where a COST figure came from, in the words the legend below the table explains. */
38
+ exports.USAGE_COST_SOURCE_LABEL = {
39
+ harness: 'harness',
40
+ ledger: 'charged',
41
+ mixed: 'both',
42
+ none: '—',
43
+ };
44
+ /** The SOURCE cell: who priced the COST beside it. */
45
+ function usageCostSource(row) {
46
+ return exports.USAGE_COST_SOURCE_LABEL[(0, data_provider_1.harnessUsageCost)(row).source];
29
47
  }
30
48
  /** Thousands separators — these run to eight digits and are compared by eye. */
31
49
  function count(value) {
@@ -59,6 +77,7 @@ const SHARED_COLUMNS = [
59
77
  { key: 'provider', header: 'PROVIDER' },
60
78
  { key: 'sessions', header: 'SESSIONS' },
61
79
  { key: 'cost', header: 'COST' },
80
+ { key: 'source', header: 'SOURCE' },
62
81
  { key: 'in', header: 'INPUT' },
63
82
  { key: 'out', header: 'OUTPUT' },
64
83
  { key: 'cached', header: 'CACHED' },
@@ -67,6 +86,7 @@ const SHARED_COLUMNS = [
67
86
  exports.HARNESS_USAGE_COVERAGE = {
68
87
  scope: 'skrr_recorded_harness_usage',
69
88
  explanation: 'Only usage recorded by Skrr for these harnesses is shown. Other activity or unreported usage may be absent; this is not a provider bill.',
89
+ costExplanation: '`cost` is the best-known cost and where it came from: `ledger` is what Skrr charged for managed inference, `harness` what the harness itself reported. `costUsd` is null when it is not known, and a lower bound when `reporting` is `partial`. `totalCostUsd` and `costReportedSessions` count only harness-reported prices.',
70
90
  };
71
91
  /** Keep the server response intact and add a machine-readable CLI explanation. */
72
92
  function withUsageCoverage(report) {
@@ -90,6 +110,7 @@ function buildUsageTable(rows, perHarness) {
90
110
  provider: (0, format_1.formatCell)(r.provider),
91
111
  sessions: count(r.sessions),
92
112
  cost: usageCost(r),
113
+ source: usageCostSource(r),
93
114
  in: count(r.inputTokens),
94
115
  out: count(r.outputTokens),
95
116
  cached: count(r.cachedInputTokens),
@@ -162,8 +183,10 @@ class HarnessesUsage extends base_command_1.BaseCommand {
162
183
  const table = buildUsageTable(rows, Boolean(args.harness));
163
184
  (0, format_1.renderTable)(table.rows, table.columns, (line) => this.log(line));
164
185
  if (totals) {
186
+ const source = usageCostSource(totals);
187
+ const totalSource = source === '—' ? '' : ` (${source})`;
165
188
  this.log('');
166
- this.log(`Total: ${count(totals.sessions)} sessions · ${usageCost(totals)} · ` +
189
+ this.log(`Total: ${count(totals.sessions)} sessions · ${usageCost(totals)}${totalSource} · ` +
167
190
  `${count(totals.inputTokens)} in / ${count(totals.outputTokens)} out / ` +
168
191
  `${count(totals.cachedInputTokens)} cached / ${count(totals.cacheCreationInputTokens)} cache write`);
169
192
  // SAY WHICH PROVIDERS THAT TOTAL COVERS.
@@ -186,6 +209,8 @@ class HarnessesUsage extends base_command_1.BaseCommand {
186
209
  }
187
210
  this.log('');
188
211
  this.log('Cost: — means unknown, not reported, or no activity; + means a lower bound.');
212
+ this.log('Source: charged = what Skrr charged for managed inference; harness = what the harness ' +
213
+ 'reported (your own key or subscription); both = some of each.');
189
214
  this.log(exports.HARNESS_USAGE_COVERAGE.explanation);
190
215
  }
191
216
  }
@@ -75,9 +75,26 @@ export interface HeldBreakdown {
75
75
  frozenCount: number;
76
76
  /** When the oldest frozen hold froze, or null when none is. */
77
77
  oldestFrozenAt: string | null;
78
+ /**
79
+ * How the frozen money ends, soonest first (OSK-24540), from the policy the billing sweep acts on.
80
+ * Absent from an older server, which only knew "frozen".
81
+ */
82
+ frozenOutcomes?: FrozenOutcome[];
78
83
  /** Held in the counter but accounted for by no hold row. */
79
84
  unattributedMicros: number;
80
85
  }
86
+ /**
87
+ * One way frozen money ends. `settles_on_record`: on its own, when the provider's usage record is
88
+ * read (or returned once the provider is shown never to have been called); `by` is when it becomes a
89
+ * review if no record arrives. `returned_after_window`: given back once `by` has passed.
90
+ * `needs_review`: a person resolves it, so there is no date (`by` null).
91
+ */
92
+ export interface FrozenOutcome {
93
+ outcome: 'settles_on_record' | 'returned_after_window' | 'needs_review';
94
+ count: number;
95
+ micros: number;
96
+ by: string | null;
97
+ }
81
98
  export interface BalanceTransaction {
82
99
  tokenType?: string;
83
100
  context?: string;
@@ -82,11 +82,14 @@ async function getUsageBreakdown(workspaceId, params = {}) {
82
82
  }
83
83
  /** Resolve only identities this caller may VIEW; the server omits denied IDs. */
84
84
  async function getUsageAgentNames(ids, workspaceId) {
85
- const uniqueIds = [...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 100);
85
+ const uniqueIds = [
86
+ ...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0 && id.length <= 256)),
87
+ ].slice(0, 100);
86
88
  if (!uniqueIds.length)
87
89
  return new Map();
88
90
  const result = await (0, api_fetch_1.apiFetch)('/api/agents/identity-batch', {
89
- method: 'POST', body: { ids: uniqueIds },
91
+ method: 'POST',
92
+ body: { ids: uniqueIds },
90
93
  ...(workspaceId ? { headers: { 'X-Workspace-Id': workspaceId } } : {}),
91
94
  signal: AbortSignal.timeout(3000),
92
95
  });
@@ -97,6 +100,8 @@ async function getUsageAgentNames(ids, workspaceId) {
97
100
  for (const row of result.data) {
98
101
  if (typeof row?.id !== 'string' || !requested.has(row.id) || typeof row.name !== 'string')
99
102
  continue;
103
+ // Matching control characters is the point: a name is printed to a terminal, so they are stripped.
104
+ // eslint-disable-next-line no-control-regex
100
105
  const name = row.name.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').trim();
101
106
  if (name)
102
107
  names.set(row.id, name);
@@ -159,6 +164,31 @@ function workspaceBalanceLines(balance) {
159
164
  ` Posted: ${formatCreditsWithUsd(balance.postedBalanceMicros)}`,
160
165
  ];
161
166
  }
167
+ /** `2026-11-17 03:10 UTC`: an instant to the minute, in the one zone every reader shares. */
168
+ function utcMinute(iso) {
169
+ if (!iso)
170
+ return null;
171
+ const date = new Date(iso);
172
+ return Number.isNaN(date.getTime())
173
+ ? null
174
+ : `${date.toISOString().slice(0, 16).replace('T', ' ')} UTC`;
175
+ }
176
+ function frozenOutcomeLine(entry) {
177
+ const amount = `${formatCreditsWithUsd(entry.micros)} (${entry.count})`;
178
+ const by = utcMinute(entry.by);
179
+ switch (entry.outcome) {
180
+ case 'settles_on_record':
181
+ return (` settling ${amount}: settles on its own when the provider's usage record` +
182
+ ` is read, usually within minutes of the turn ending` +
183
+ (by ? `; reviewed after ${by} if none arrives` : ''));
184
+ case 'returned_after_window':
185
+ // "after", not "by": the sweep returns it on its first pass once the window has elapsed.
186
+ return (` returning ${amount}: returned to this balance` +
187
+ (by ? ` after ${by}` : ' once its window elapses'));
188
+ default:
189
+ return ` in review ${amount}: waits for billing to review it; the statement's \`exception\` entries list it`;
190
+ }
191
+ }
162
192
  /**
163
193
  * The lines that say what a Held figure is made of, indented under it. Empty when the server did not
164
194
  * send a breakdown (an older server ignores the request), so nothing is invented for it.
@@ -182,9 +212,22 @@ function heldBreakdownLines(held) {
182
212
  const since = held.oldestFrozenAt
183
213
  ? `, the oldest since ${held.oldestFrozenAt.slice(0, 10)}`
184
214
  : '';
185
- lines.push(` frozen ${formatCreditsWithUsd(held.frozenMicros)}` +
186
- ` (${held.frozenCount} hold${held.frozenCount === 1 ? '' : 's'} from work that ended without settling${since};` +
187
- ' held until billing clears them)');
215
+ const holds = `${held.frozenCount} hold${held.frozenCount === 1 ? '' : 's'}`;
216
+ const outcomes = (held.frozenOutcomes ?? []).filter((entry) => entry.count > 0);
217
+ if (outcomes.length === 0) {
218
+ // An older server, which says only that it is frozen.
219
+ lines.push(` frozen ${formatCreditsWithUsd(held.frozenMicros)}` +
220
+ ` (${holds} from work that ended without settling${since}; held until billing clears them)`);
221
+ }
222
+ else {
223
+ // "Held until billing clears them" was true of almost none of it: a hosted turn's hold settles
224
+ // on its own within minutes, an agent turn's is returned after a day, and only the rest wait
225
+ // for a person. Say which, and by when, as the server's policy decides it (OSK-24540).
226
+ lines.push(` frozen ${formatCreditsWithUsd(held.frozenMicros)}` +
227
+ ` (${holds} from work that ended without settling${since})`);
228
+ for (const entry of outcomes)
229
+ lines.push(frozenOutcomeLine(entry));
230
+ }
188
231
  }
189
232
  if (held.unattributedMicros > 0) {
190
233
  lines.push(` other ${formatCreditsWithUsd(held.unattributedMicros)}` +
@@ -1,11 +1,16 @@
1
+ import type { ManagedProviderRolloutSubjectType } from '@skrr-ai/data-provider';
1
2
  /**
2
3
  * Managed inference provider rollouts (OSK-24530): `/api/admin/provider-rollouts`.
3
4
  *
4
5
  * A provider in the server's rollout registry (today `copilot-sdk`) is closed to
5
6
  * every account on managed inference until it is released to that account,
6
- * whatever the payer's policy permits. These calls release it to one person,
7
- * list who holds it, and withdraw it, with no deploy: admission reads the grants
8
- * on every turn.
7
+ * whatever the payer's policy permits. These calls release it to one person or
8
+ * one workspace, list who holds it, and withdraw it, with no deploy: admission
9
+ * reads the grants on every turn.
10
+ *
11
+ * A workspace grant admits a turn only when that workspace is the turn's own and
12
+ * is paying for it. A member of a granted workspace who works in another
13
+ * workspace is not admitted by it.
9
14
  *
10
15
  * Platform admins only, signed in as a person (`skrr login`). A personal access
11
16
  * token is refused for every `/api/admin` path, and a daemon credential for this
@@ -38,15 +43,31 @@ export interface ProviderRolloutList {
38
43
  }
39
44
  export declare function listProviderRollouts(opts?: {
40
45
  provider?: string;
46
+ subjectType?: ManagedProviderRolloutSubjectType;
41
47
  subjectId?: string;
42
48
  includeRevoked?: boolean;
43
49
  limit?: number;
44
50
  }): Promise<ProviderRolloutList>;
45
- /** Who a grant names. `user` is the only subject type the server accepts today; `me` is yourself. */
51
+ /**
52
+ * Who a grant names: a `user` by account id (`me` is yourself), or a `workspace`
53
+ * by workspace id.
54
+ */
46
55
  export interface ProviderRolloutSubject {
47
- type: 'user';
56
+ type: ManagedProviderRolloutSubjectType;
48
57
  id: string;
49
58
  }
59
+ /**
60
+ * The subject a `grant` / `revoke` / `list` invocation names, from its flags.
61
+ * `--for-workspace`, not `--workspace`: the global `--workspace` flag scopes the
62
+ * REQUEST (`X-Workspace-Id`), and reusing the name would make one flag mean two
63
+ * things. Exactly one of the two is required; the commands declare that with
64
+ * oclif's `exactlyOne`, and this repeats it so a caller cannot build a subject
65
+ * that names both or neither.
66
+ */
67
+ export declare function providerRolloutSubjectFromFlags(flags: {
68
+ user?: string;
69
+ 'for-workspace'?: string;
70
+ }): ProviderRolloutSubject;
50
71
  /** Release `provider` to one subject. Idempotent: an active grant comes back as is. */
51
72
  export declare function grantProviderRollout(provider: string, subject: ProviderRolloutSubject, reason: string): Promise<{
52
73
  created: boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listProviderRollouts = listProviderRollouts;
4
+ exports.providerRolloutSubjectFromFlags = providerRolloutSubjectFromFlags;
4
5
  exports.grantProviderRollout = grantProviderRollout;
5
6
  exports.revokeProviderRollout = revokeProviderRollout;
6
7
  const api_fetch_1 = require("./api-fetch");
@@ -8,11 +9,32 @@ const triggers_1 = require("./triggers");
8
9
  async function listProviderRollouts(opts = {}) {
9
10
  return (0, api_fetch_1.apiFetch)((0, triggers_1.withQuery)('/api/admin/provider-rollouts', {
10
11
  provider: opts.provider,
12
+ subjectType: opts.subjectType,
11
13
  subjectId: opts.subjectId,
12
14
  includeRevoked: opts.includeRevoked ? 'true' : undefined,
13
15
  limit: opts.limit,
14
16
  }));
15
17
  }
18
+ /**
19
+ * The subject a `grant` / `revoke` / `list` invocation names, from its flags.
20
+ * `--for-workspace`, not `--workspace`: the global `--workspace` flag scopes the
21
+ * REQUEST (`X-Workspace-Id`), and reusing the name would make one flag mean two
22
+ * things. Exactly one of the two is required; the commands declare that with
23
+ * oclif's `exactlyOne`, and this repeats it so a caller cannot build a subject
24
+ * that names both or neither.
25
+ */
26
+ function providerRolloutSubjectFromFlags(flags) {
27
+ const user = flags.user?.trim();
28
+ const workspace = flags['for-workspace']?.trim();
29
+ if (user && workspace) {
30
+ throw new Error('Name one subject: --user <id|me> or --for-workspace <workspace-id>, not both.');
31
+ }
32
+ if (user)
33
+ return { type: 'user', id: user };
34
+ if (workspace)
35
+ return { type: 'workspace', id: workspace };
36
+ throw new Error('Name a subject: --user <id|me> or --for-workspace <workspace-id>.');
37
+ }
16
38
  /** Release `provider` to one subject. Idempotent: an active grant comes back as is. */
17
39
  async function grantProviderRollout(provider, subject, reason) {
18
40
  return (0, api_fetch_1.apiFetch)(`/api/admin/provider-rollouts/${encodeURIComponent(provider)}/subjects/${encodeURIComponent(subject.type)}/${encodeURIComponent(subject.id)}`, { method: 'PUT', body: { reason } });