cortexapps-cli 1.48.0__py3-none-any.whl → 1.50.0__py3-none-any.whl

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.
cortexapps_cli/cli.py CHANGED
@@ -13,7 +13,6 @@ import requests
13
13
 
14
14
  from cortexapps_cli.cortex_client import CortexClient
15
15
 
16
- import cortexapps_cli.commands.ai_skills as ai_skills
17
16
  import cortexapps_cli.commands.api_keys as api_keys
18
17
  import cortexapps_cli.commands.audit_logs as audit_logs
19
18
  import cortexapps_cli.commands.backup as backup
@@ -47,6 +46,7 @@ import cortexapps_cli.commands.solutions as solutions
47
46
  import cortexapps_cli.commands.teams as teams
48
47
  import cortexapps_cli.commands.users as users
49
48
  import cortexapps_cli.commands.verifications as verifications
49
+ import cortexapps_cli.commands.whoami as whoami
50
50
  import cortexapps_cli.commands.workflows as workflows
51
51
 
52
52
  class _SortedTyper(typer.Typer):
@@ -68,7 +68,7 @@ app = _SortedTyper(
68
68
  # interleaved with add_typer() calls so they appear alphabetically in --help.
69
69
 
70
70
  # global options
71
- @app.callback()
71
+ @app.callback(invoke_without_command=True)
72
72
  def global_callback(
73
73
  ctx: typer.Context,
74
74
  api_key: str = typer.Option(None, "--api-key", "-k", help="API key", envvar="CORTEX_API_KEY"),
@@ -143,6 +143,10 @@ def global_callback(
143
143
  api_key = api_key.strip('"\' ')
144
144
  url = url.strip('"\' /')
145
145
 
146
+ if ctx.invoked_subcommand is None:
147
+ typer.echo(ctx.get_help())
148
+ raise typer.Exit()
149
+
146
150
  ctx.obj["client"] = CortexClient(api_key, tenant, numeric_level, url, rate_limit)
147
151
 
148
152
  DEFAULT_API_URL = "https://api.getcortexapp.com"
@@ -250,7 +254,6 @@ def version():
250
254
  print(version)
251
255
 
252
256
  # Register all commands alphabetically so they appear in order in --help
253
- app.add_typer(ai_skills.app, name="ai-skills")
254
257
  app.add_typer(api_keys.app, name="api-keys")
255
258
  app.add_typer(audit_logs.app, name="audit-logs")
256
259
  app.add_typer(backup.app, name="backup")
@@ -286,6 +289,7 @@ app.add_typer(teams.app, name="teams")
286
289
  app.add_typer(users.app, name="users")
287
290
  app.add_typer(verifications.app, name="verifications")
288
291
  app.command()(version)
292
+ app.add_typer(whoami.app, name="whoami")
289
293
  app.add_typer(workflows.app, name="workflows")
290
294
 
291
295
  if __name__ == "__main__":
@@ -138,6 +138,14 @@ def get(
138
138
  r = client.get("api/v1/auth/key/"+ cid)
139
139
  print_output_with_context(ctx, r)
140
140
 
141
+ @app.command()
142
+ def current(ctx: typer.Context):
143
+ """
144
+ Print the API key currently in use. Useful for passing to scripts, e.g. $(cortex api-keys current).
145
+ """
146
+ client = ctx.obj["client"]
147
+ typer.echo(client.api_key)
148
+
141
149
  @app.command()
142
150
  def delete(
143
151
  ctx: typer.Context,
@@ -0,0 +1,59 @@
1
+ import base64
2
+ import gzip
3
+ import json
4
+ import typer
5
+ from datetime import datetime, timezone
6
+ from rich.console import Console
7
+ from rich.table import Table
8
+ import rich.box
9
+
10
+ app = typer.Typer(
11
+ help="Show identity and metadata for the currently configured API key",
12
+ no_args_is_help=False,
13
+ invoke_without_command=True,
14
+ )
15
+
16
+ @app.callback(invoke_without_command=True)
17
+ def whoami(ctx: typer.Context):
18
+ """Show identity and metadata for the currently configured API key."""
19
+ if ctx.invoked_subcommand is not None:
20
+ return
21
+
22
+ client = ctx.obj["client"]
23
+ token = client.api_key
24
+
25
+ parts = token.split(".")
26
+ if len(parts) != 3:
27
+ typer.echo("Error: API key is not a valid JWT", err=True)
28
+ raise typer.Exit(1)
29
+
30
+ header_b64, payload_b64, _ = parts
31
+ header = json.loads(base64.urlsafe_b64decode(header_b64 + "=="))
32
+ payload_bytes = base64.urlsafe_b64decode(payload_b64 + "==")
33
+ if header.get("zip") == "GZIP":
34
+ payload_bytes = gzip.decompress(payload_bytes)
35
+ claims = json.loads(payload_bytes)
36
+
37
+ def fmt_ts(ts):
38
+ if ts is None:
39
+ return "—"
40
+ return datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
41
+
42
+ rows = [
43
+ ("Base URL", client.base_url),
44
+ ("Tenant", client.tenant),
45
+ ("Tenant ID", claims.get("sub") or "—"),
46
+ ("Token Type", claims.get("type") or "—"),
47
+ ("Auth Scope", claims.get("key-authenticated-request-type") or "—"),
48
+ ("Issued", fmt_ts(claims.get("iat"))),
49
+ ("Expires", fmt_ts(claims.get("exp"))),
50
+ ("Last 4", token[-4:]),
51
+ ]
52
+
53
+ console = Console()
54
+ table = Table(show_header=False, box=rich.box.SIMPLE, padding=(0, 1))
55
+ table.add_column(style="dim", no_wrap=True)
56
+ table.add_column()
57
+ for label, value in rows:
58
+ table.add_row(label, value)
59
+ console.print(table)
@@ -79,10 +79,10 @@ Environments, releases, and service-versions are available in a catalog named [E
79
79
 
80
80
  **Try the workflows**
81
81
 
82
- Three workflows were installed. Go to [Workflows](https://app.getcortexapp.com/admin/workflows) in the Cortex UI:
82
+ Three workflows were installed:
83
83
 
84
- - **Create Environment** (`create-environment`) — provision a new environment entity
85
- - **Create Release** (`create-release`) — create a release linked to service versions
86
- - **Trigger GitHub Release** (`trigger-github-release`) — publish a service version via GitHub Actions
84
+ - **[Create Environment](https://app.getcortexapp.com/admin/workflows/create-environment)** (`create-environment`) — provision a new environment entity
85
+ - **[Create Release](https://app.getcortexapp.com/admin/workflows/create-release)** (`create-release`) — create a release linked to service versions
86
+ - **[Trigger GitHub Release](https://app.getcortexapp.com/admin/workflows/trigger-github-release)** (`trigger-github-release`) — publish a service version via GitHub Actions
87
87
 
88
88
  These are all stub workflows. You might add the creation of these entities as part of your automated CI/CD process. You might extend these workflows and call them via the Cortex API. These are included to show conceptually what you'll want to create/maintain.
@@ -205,7 +205,7 @@ class GitHubActionsSetup(SolutionSetup):
205
205
 
206
206
  workflow_tag = "github-actions-deploy"
207
207
  entity_url = f"{app_url}/admin/resources?tag=github-actions-demo"
208
- workflows_url = f"{app_url}/admin/workflows?activeTab=runs"
208
+ workflows_url = f"{app_url}/admin/workflows/github-actions-deploy"
209
209
 
210
210
  if self._answers.get("github_integration_alias"):
211
211
  print(f"\nTo trigger a deploy manually later:")
@@ -408,7 +408,7 @@ info:
408
408
  api_key = self._answers["cortex_api_key"]
409
409
  alias = self._answers["github_integration_alias"]
410
410
  app_url = base_url.replace("api.", "app.", 1) if "api." in base_url else base_url
411
- workflows_url = f"{app_url}/admin/workflows?activeTab=runs"
411
+ workflows_url = f"{app_url}/admin/workflows/github-actions-deploy"
412
412
 
413
413
  yaml_content = WORKFLOW_TEMPLATE_PATH.read_text().replace(
414
414
  "PLACEHOLDER_INTEGRATION_ALIAS", alias
@@ -475,7 +475,7 @@ info:
475
475
  raise RuntimeError("No run ID returned from workflow start")
476
476
 
477
477
  app_url = base_url.replace("api.", "app.", 1) if "api." in base_url else base_url
478
- workflows_url = f"{app_url}/admin/workflows?activeTab=runs"
478
+ workflows_url = f"{app_url}/admin/workflows/github-actions-deploy"
479
479
 
480
480
  terminal = {"COMPLETED", "FAILED", "CANCELLED"}
481
481
  start = time.time()
@@ -241,7 +241,7 @@ class HarnessDeploySetup(SolutionSetup):
241
241
  )
242
242
 
243
243
  workflow_tag = "harness-trigger-deploy"
244
- workflows_url = f"{app_url}/admin/workflows"
244
+ workflows_url = f"{app_url}/admin/workflows/harness-trigger-deploy"
245
245
  entity_url = cortex_url
246
246
 
247
247
  print(f"\nTo trigger a deploy manually later:")
@@ -715,7 +715,7 @@ info:
715
715
  workflow_tag = "jenkins-trigger-deploy"
716
716
 
717
717
  entity_url = f"{app_url}/admin/resources?tag={entity_tag}"
718
- workflows_url = f"{app_url}/admin/workflows"
718
+ workflows_url = f"{app_url}/admin/workflows/jenkins-trigger-deploy"
719
719
  jenkins_url = self._answers.get("jenkins_url", "")
720
720
  jenkins_job = self._answers.get("jenkins_job", "cortex-deploy")
721
721
  jenkins_job_url = f"{jenkins_url}/job/{jenkins_job}" if jenkins_url else ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cortexapps-cli
3
- Version: 1.48.0
3
+ Version: 1.50.0
4
4
  Summary: Command Line Interface for cortexapps
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,8 +1,7 @@
1
1
  cortexapps_cli/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
2
- cortexapps_cli/cli.py,sha256=XRpKxwp2K9gKFbNkvAhTdKy4qjguB9TgIKWy4889rM8,11972
2
+ cortexapps_cli/cli.py,sha256=7seWQm6YaZfxg6Tnx0C75Bn-PWMGyyATVsDQzGIDILs,12089
3
3
  cortexapps_cli/command_options.py,sha256=9xVu61fVKOQFs3wTw0RV-uJbT1Z4-Z3D7YngpS0mEhY,1714
4
- cortexapps_cli/commands/ai_skills.py,sha256=9T8gcHXbaKTGaXlAxEf-wtW9MQTm2Z0DlGxKHbngAk0,7425
5
- cortexapps_cli/commands/api_keys.py,sha256=f5LfrfuYJowH3BsHXR28hSmysSRoEcPU9PWAlDMfryI,5245
4
+ cortexapps_cli/commands/api_keys.py,sha256=i9kReOrfXjJmQ2yvA5nanvXygafEcdjpeFoS1VuOCdQ,5476
6
5
  cortexapps_cli/commands/audit_logs.py,sha256=u0fa5I4GFZrcn8kUa0zwZPMkrmrUsgzh6NGVr8i7MEU,4194
7
6
  cortexapps_cli/commands/backup.py,sha256=RLdFrkUiLzD763DgKDBgJwAufYzXziXXbPnBLe-Yijc,39152
8
7
  cortexapps_cli/commands/backup_commands/cortex_export.py,sha256=hn6SBGRyYspamhOT8p4F_WS0DLcuiDpMdUpi15FsGUY,4680
@@ -94,6 +93,7 @@ cortexapps_cli/commands/verifications.py,sha256=9OCfP_Po2ncJaM9bR53FBDE-MwJyA-dC
94
93
  cortexapps_cli/commands/verifications_commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
95
94
  cortexapps_cli/commands/verifications_commands/entity.py,sha256=abmbyqC7ywuzGCvxiUoecE9QYeVYGGj4a-9EQwzGglI,2674
96
95
  cortexapps_cli/commands/verifications_commands/periods.py,sha256=C9YAbZ96j4H5hHsD5FS4DL0p9tDR_f--zt3hLUnf6B8,4333
96
+ cortexapps_cli/commands/whoami.py,sha256=3Xvbctk7bLGfSlz7bm-cgh2iBlWditODw8pcX4pKwrY,1892
97
97
  cortexapps_cli/commands/workflows.py,sha256=27rwCwUrwnmKf6MXNg8mB9qKFyhimMIUQx7LSt1qKZo,7360
98
98
  cortexapps_cli/cortex_client.py,sha256=BMb-NKkRLttOun0DUp_I8H5Ju1OXrRvSgRDONejQHCA,13749
99
99
  cortexapps_cli/models/team.py,sha256=DZ_MmXLLhi4AoT3sng-JEUOWSafFQH_FqY0xODusdtg,6460
@@ -143,7 +143,7 @@ cortexapps_cli/solutions/ai-spend/plugins/team-ai-spend.json,sha256=TUVxUiVAT8Iy
143
143
  cortexapps_cli/solutions/ai-spend/scorecards/ai-spend-scorecard.yaml,sha256=lRW6WMblTxUv85Oy-xLkTqAZS3UioL9iGiVkHHVibWI,2479
144
144
  cortexapps_cli/solutions/ai-spend/scripts/sync-claude-spend.py,sha256=4fo8LFyWs-OeccCOZbwafp7ZU6jALtTqozo3ryoW2xU,11435
145
145
  cortexapps_cli/solutions/environments/.github/workflows/cortex-service-version.yaml,sha256=WjoMTJaIe7DLs3FJyWJnziAfF3SsV7AL-T8QqHeYkNg,2190
146
- cortexapps_cli/solutions/environments/README.md,sha256=tVtWbE1z6VZ7yGCLSH0E6vAXcUavEE1gdsEZetTyH4Q,4856
146
+ cortexapps_cli/solutions/environments/README.md,sha256=vkawuZpzaATQOCPz-yO6Iy14fL2kJ5JvsrlEPgrfwh4,4975
147
147
  cortexapps_cli/solutions/environments/catalog/api-gateway-3.0.1.yaml,sha256=UW8zmgimDK7SVDSR_8VPFpNlVxxeGhroee8y6GUoaq0,431
148
148
  cortexapps_cli/solutions/environments/catalog/api-gateway-3.1.0.yaml,sha256=-H6lSz3WnyilffedS9-GqUraelul-JVtaTyv_8OQ4QI,431
149
149
  cortexapps_cli/solutions/environments/catalog/api-gateway-3.1.1.yaml,sha256=JGNZm-6HkDQ5olUXk5glDkD9ZRkcV9SumgIRQz4-Yog,431
@@ -202,7 +202,7 @@ cortexapps_cli/solutions/github-actions-deploy/_templates/cortex-register-deploy
202
202
  cortexapps_cli/solutions/github-actions-deploy/_templates/github-actions-deploy.yaml,sha256=ZqAfqF1uqa_bkbcdTnbeuQRQhwfrss38-GM5Rg8oRWs,4707
203
203
  cortexapps_cli/solutions/github-actions-deploy/catalog/github-actions-demo.yaml,sha256=hM9FxSRKR6RUhx3es2BwBHCFEI2zWNxMLIMHty1fUrY,285
204
204
  cortexapps_cli/solutions/github-actions-deploy/scorecards/deploy-health.yaml,sha256=N9-RtYmTjFDnuNcEOqrgNX7uOYV-DZwjOSl9oo1_DyA,1571
205
- cortexapps_cli/solutions/github-actions-deploy/setup.py,sha256=7ZzopV4FpRnRdwy-WdgyZQJQ6RiDLpIy-kT-cATdAHM,22440
205
+ cortexapps_cli/solutions/github-actions-deploy/setup.py,sha256=diHmXa8tK_4wV8TRf2c5rAzY4niwag9CQJh2aMq_QE4,22461
206
206
  cortexapps_cli/solutions/harness-deploy/README.md,sha256=-Tz7rYl_z2WY5q-GDd8Wu9FZ_o07cEdoGfoNjWpuSgw,5742
207
207
  cortexapps_cli/solutions/harness-deploy/_templates/cortex-async-callback-template.yaml,sha256=b4mcJGhOsjTiXvoB4qJbXo2bS-tsmt2ZWbv4ussboPg,2421
208
208
  cortexapps_cli/solutions/harness-deploy/_templates/cortex-deploy-pipeline.yaml,sha256=TVVPq5XDNLbE-bfOrOkJvs4yW7Fe2e7Jd3jNDSZS4XE,4143
@@ -210,13 +210,13 @@ cortexapps_cli/solutions/harness-deploy/_templates/cortex-record-deploy-template
210
210
  cortexapps_cli/solutions/harness-deploy/_templates/trigger-harness-deploy.yaml,sha256=zriJ-q7YLuFSX5bS6VfD9dSo0lw5YGbhxWI9m21eirw,6757
211
211
  cortexapps_cli/solutions/harness-deploy/catalog/harness-demo.yaml,sha256=h-QPj7ro1f_v1GL6k9nY54Zsg941chAxiqj6gLfZwAU,431
212
212
  cortexapps_cli/solutions/harness-deploy/scorecards/deploy-health.yaml,sha256=OvDAXSTiafneaBO_XUDyf2yQMUowNvV5Q3GDHuss3QU,1566
213
- cortexapps_cli/solutions/harness-deploy/setup.py,sha256=zdOg2B_1oWCGgBNSHkpVGjDbYZDXooyvo1Yue2SQAAA,23056
213
+ cortexapps_cli/solutions/harness-deploy/setup.py,sha256=R-gVcjhtxPE3_A86_SINs11jbMbPY5aLNu5qEK1fbXA,23079
214
214
  cortexapps_cli/solutions/jenkins-deploy/README.md,sha256=EJC5cQzee3fUp9zZrBeAhEya0dIHPnQ2Ds3xIuT2MkI,6813
215
215
  cortexapps_cli/solutions/jenkins-deploy/_templates/Jenkinsfile,sha256=Y-QHU9yMV9PTng5Us6Bkt9I9Ucet3HG3eunyjd834Mk,4051
216
216
  cortexapps_cli/solutions/jenkins-deploy/_templates/trigger-jenkins-deploy.yaml,sha256=lnWHarqKaP8Ikxg3TsbPC4SmsZIDcsYUhIPyCVrIU8c,4439
217
217
  cortexapps_cli/solutions/jenkins-deploy/catalog/jenkins-demo.yaml,sha256=3kVzs0TfqtqP2k_kcgxO0nVVfvIeIzbzQ47Naa2pOSo,368
218
218
  cortexapps_cli/solutions/jenkins-deploy/scorecards/deploy-health.yaml,sha256=M20MKOExRk1-CfId8mywBKchRyE7DWKjqgjsy7v8IKU,1566
219
- cortexapps_cli/solutions/jenkins-deploy/setup.py,sha256=Ebzwvu7fJVkz5rbv7HKjcD0xHVCC1KTEPndgm0PqTco,35950
219
+ cortexapps_cli/solutions/jenkins-deploy/setup.py,sha256=Wmc13jed8GzVchhsIdpduKEkvYxWdF5h6Lh2rxNKP7A,35973
220
220
  cortexapps_cli/solutions/kubernetes-agent/README.md,sha256=WT8smSLEctQxT1R0hV4hK7brUhOTYMl8GWUzG79e12U,7796
221
221
  cortexapps_cli/solutions/kubernetes-agent/catalog/demo-kubernetes.yaml,sha256=hVJFeP8S2HE_Sc8glWXQqW1gdlZeiTsQgHsxoMIzHBQ,167
222
222
  cortexapps_cli/solutions/kubernetes-agent/helm-chart/.helmignore,sha256=u5h-ao70WpklXR1jKBJILV8PMlXqhBUgtNkDQt9f4rM,349
@@ -274,8 +274,8 @@ cortexapps_cli/solutions/workday/data/configuration.json,sha256=8_C6pFrCSSXIv3hx
274
274
  cortexapps_cli/solutions/workday/data/pied-piper-supervisory-org.json,sha256=OS0F5Pl0sBS4pENRsEhHAkAcXfqg8GLI8dJx2sqEvtE,3191
275
275
  cortexapps_cli/solutions/workday/setup.py,sha256=t7I5sCXqta66lC9PKEZfpSZ8l_0OBbCnpvSFuh7y9Jw,5591
276
276
  cortexapps_cli/utils.py,sha256=zJilDiFhL-cYdp5LA251rED7vdc0EIEivCZpCqQRvmI,6992
277
- cortexapps_cli-1.48.0.dist-info/METADATA,sha256=maxR_09kkwU3LCvQfy7-6kU7nYLykTomzrwjJbCK_Vg,17883
278
- cortexapps_cli-1.48.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
279
- cortexapps_cli-1.48.0.dist-info/entry_points.txt,sha256=YffF7CawiDnK0vE7Fg9mAItnXoSjLvVkW3IdHhumz84,49
280
- cortexapps_cli-1.48.0.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
281
- cortexapps_cli-1.48.0.dist-info/RECORD,,
277
+ cortexapps_cli-1.50.0.dist-info/METADATA,sha256=QSurSLRSbU0GbQtwmbWkANDHoco553rHfw25RtzAHNs,17883
278
+ cortexapps_cli-1.50.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
279
+ cortexapps_cli-1.50.0.dist-info/entry_points.txt,sha256=YffF7CawiDnK0vE7Fg9mAItnXoSjLvVkW3IdHhumz84,49
280
+ cortexapps_cli-1.50.0.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
281
+ cortexapps_cli-1.50.0.dist-info/RECORD,,
@@ -1,200 +0,0 @@
1
- import json
2
- import re
3
- from pathlib import Path
4
- from typing import Optional
5
-
6
- import typer
7
- import yaml
8
- from typing_extensions import Annotated
9
-
10
- app = typer.Typer(help="AI Skills commands", no_args_is_help=True)
11
-
12
-
13
- def _parse_frontmatter(content: str) -> tuple[dict, str]:
14
- """Split a SKILL.md file into its YAML frontmatter and body."""
15
- match = re.match(r"^---\n(.*?)\n---\n(.*)$", content, re.DOTALL)
16
- if not match:
17
- return {}, content
18
- try:
19
- frontmatter = yaml.safe_load(match.group(1)) or {}
20
- except yaml.YAMLError:
21
- frontmatter = {}
22
- return frontmatter, match.group(2)
23
-
24
-
25
- def _local_links(text: str, base_dir: Path) -> list[Path]:
26
- """Return local files referenced by markdown links in text, resolved against base_dir."""
27
- links = []
28
- for target in re.findall(r"\]\(([^)]+)\)", text):
29
- target = target.split("#")[0].strip()
30
- if not target or target.startswith(("http://", "https://", "${")):
31
- continue
32
- candidate = (base_dir / target).resolve()
33
- if candidate.is_file():
34
- links.append(candidate)
35
- return links
36
-
37
-
38
- def _has_deep_references(skill_dir: Path, body: str) -> bool:
39
- """True if a file SKILL.md links to itself links to another local file (>1 level deep)."""
40
- for linked in _local_links(body, skill_dir):
41
- try:
42
- linked_body = linked.read_text(encoding="utf-8")
43
- except OSError:
44
- continue
45
- if _local_links(linked_body, linked.parent):
46
- return True
47
- return False
48
-
49
-
50
- def _entity_yaml(tag: str, entity_type: str, description: str, relationships: list) -> str:
51
- info = {
52
- "title": tag,
53
- "description": description or "",
54
- "x-cortex-tag": tag,
55
- "x-cortex-type": entity_type,
56
- "x-cortex-definition": {},
57
- }
58
- if relationships:
59
- info["x-cortex-relationships"] = relationships
60
- doc = {"openapi": "3.0.0", "info": info}
61
- return yaml.safe_dump(doc, sort_keys=False)
62
-
63
-
64
- def _push_entity(client, entity_yaml: str) -> None:
65
- client.post(
66
- "api/v1/open-api",
67
- data=entity_yaml,
68
- content_type="application/openapi;charset=UTF-8",
69
- )
70
-
71
-
72
- def _push_custom_data(client, tag: str, key: str, value) -> None:
73
- client.post(
74
- f"api/v1/catalog/{tag}/custom-data",
75
- data={"key": key, "value": str(value)},
76
- params={"force": False},
77
- )
78
-
79
-
80
- @app.command()
81
- def sync(
82
- ctx: typer.Context,
83
- directory: Annotated[
84
- Path,
85
- typer.Option(
86
- "--directory", "-d",
87
- help="Directory containing plugin folders, each with .claude-plugin/plugin.json and skills/*/SKILL.md (the eng-commons layout).",
88
- ),
89
- ],
90
- service: Annotated[
91
- Optional[str],
92
- typer.Option(
93
- "--service", "-s",
94
- help="Cortex Service tag to link every synced plugin/skill's ownership to (ai-plugin-service / ai-skill-service).",
95
- show_default=False,
96
- ),
97
- ] = None,
98
- dry_run: Annotated[
99
- bool,
100
- typer.Option("--dry-run", "-n", help="Print what would be synced without pushing anything to Cortex."),
101
- ] = False,
102
- ):
103
- """
104
- Scan a plugins directory and sync ai-plugin / ai-skill catalog entities into Cortex.
105
-
106
- Expects the eng-commons layout:
107
-
108
- <directory>/<plugin>/.claude-plugin/plugin.json
109
- <directory>/<plugin>/skills/<skill>/SKILL.md
110
-
111
- For each skill, also pushes the lineCount, descriptionCharCount, and
112
- hasDeepReferences Custom Data keys the ai-skills-quality scorecard reads
113
- (see cortexapps_cli/solutions/ai-skills/scorecards/ai-skills-quality.yaml),
114
- via the Custom Data API.
115
-
116
- Re-run this on a schedule tied to when skills actually change (a GitHub
117
- Action or webhook on push to the plugins repo), not on a fixed timer —
118
- these values change maybe a couple of times a year, so recomputing them
119
- multiple times a day is wasted work the scorecard evaluator would
120
- otherwise have to redo live against git on every single evaluation.
121
- """
122
- client = None if dry_run else ctx.obj["client"]
123
-
124
- plugin_dirs = sorted(
125
- p for p in directory.iterdir()
126
- if p.is_dir() and (p / ".claude-plugin" / "plugin.json").is_file()
127
- )
128
- if not plugin_dirs:
129
- typer.echo(f"No plugins found under {directory} (expected <plugin>/.claude-plugin/plugin.json)")
130
- raise typer.Exit(1)
131
-
132
- synced_plugins = 0
133
- synced_skills = 0
134
-
135
- for plugin_dir in plugin_dirs:
136
- manifest = json.loads((plugin_dir / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8"))
137
- plugin_tag = manifest.get("name", plugin_dir.name)
138
- plugin_description = manifest.get("description", "")
139
-
140
- skill_tags = []
141
- skills_dir = plugin_dir / "skills"
142
- if skills_dir.is_dir():
143
- for skill_dir in sorted(p for p in skills_dir.iterdir() if p.is_dir()):
144
- skill_md = skill_dir / "SKILL.md"
145
- if not skill_md.is_file():
146
- continue
147
-
148
- content = skill_md.read_text(encoding="utf-8")
149
- frontmatter, body = _parse_frontmatter(content)
150
- skill_tag = frontmatter.get("name", skill_dir.name)
151
- skill_description = frontmatter.get("description", "")
152
-
153
- line_count = len(body.strip("\n").split("\n")) if body.strip("\n") else 0
154
- description_char_count = len(skill_description)
155
- has_deep_references = _has_deep_references(skill_dir, body)
156
-
157
- relationships = []
158
- if service:
159
- relationships.append({"type": "ai-skill-service", "destinations": [{"tag": service}]})
160
-
161
- skill_yaml = _entity_yaml(skill_tag, "ai-skill", skill_description, relationships)
162
-
163
- if dry_run:
164
- typer.echo(f"--- {skill_tag} (ai-skill) ---")
165
- typer.echo(skill_yaml)
166
- typer.echo(
167
- f" custom-data: lineCount={line_count} "
168
- f"descriptionCharCount={description_char_count} "
169
- f"hasDeepReferences={has_deep_references}"
170
- )
171
- else:
172
- _push_entity(client, skill_yaml)
173
- _push_custom_data(client, skill_tag, "lineCount", line_count)
174
- _push_custom_data(client, skill_tag, "descriptionCharCount", description_char_count)
175
- _push_custom_data(client, skill_tag, "hasDeepReferences", "true" if has_deep_references else "false")
176
-
177
- skill_tags.append(skill_tag)
178
- synced_skills += 1
179
-
180
- relationships = []
181
- if skill_tags:
182
- relationships.append({
183
- "type": "ai-plugin-skills",
184
- "destinations": [{"tag": t} for t in skill_tags],
185
- })
186
- if service:
187
- relationships.append({"type": "ai-plugin-service", "destinations": [{"tag": service}]})
188
-
189
- plugin_yaml = _entity_yaml(plugin_tag, "ai-plugin", plugin_description, relationships)
190
-
191
- if dry_run:
192
- typer.echo(f"--- {plugin_tag} (ai-plugin) ---")
193
- typer.echo(plugin_yaml)
194
- else:
195
- _push_entity(client, plugin_yaml)
196
-
197
- synced_plugins += 1
198
-
199
- suffix = " (dry run — nothing was pushed)" if dry_run else ""
200
- typer.echo(f"\nSynced {synced_plugins} plugin(s), {synced_skills} skill(s){suffix}.")