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
15 changes: 15 additions & 0 deletions .agents/skills/upsert-process-bpmn/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ BC alias: `POST /api/1.0/package-skeleton/deploy-process`.
php .agents/skills/upsert-process-bpmn/scripts/sync-process.php upsert projects/{slug}/bpmn/{name}.xml
```

## Alternative B

Add `--alternative B` to write the BPMN to **Alternative B** of an existing process. The live process (Alternative A) is never changed. Without `--publish` it saves the B draft; with `--publish` it publishes a B version and links it to the A/B record (`process_version_b_id`). Requires package-ab-testing and a process that already exists (deploy it as A first). `version_name` is not needed for B.

```bash
php .agents/skills/upsert-process-bpmn/scripts/sync-process.php upsert projects/{slug}/bpmn/{name}.xml --alternative B --publish
```

Publishing B does **not** route cases to it: A/B routing stays as configured. Check the routing expression before switching (see the `pm4-process-refactor` skill, "Run a case on B").

## Pull

```bash
php .agents/skills/upsert-process-bpmn/scripts/sync-process.php get {name} --output projects/{slug}/bpmn/{name}.xml
```

## Local HTTPS and updates

- A local instance with a self-signed certificate fails with `SSL certificate problem`. Pass `--insecure` (or set `PM_INSECURE=1`) for local development only, or set `PM_CA_BUNDLE=/path/to/ca.pem` (or `CURL_CA_BUNDLE`) to keep verification on. Using `http://` for a local host also works.
- Updating an asset that already exists needs `--version-name "short change summary"`. Without it the API returns 422 and the CLI prints a hint.

Order: upsert-script-php → upsert-screen-yaml → this skill.
80 changes: 75 additions & 5 deletions .agents/skills/upsert-process-bpmn/scripts/sync-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function upsertProcess(string $file, string $host, string $token, array $options
if (is_string($versionName) && $versionName !== '') {
$payload['version_name'] = $versionName;
}
$payload += resolveAlternativePayload($options);

$response = request(
'POST',
Expand All @@ -86,6 +87,27 @@ function upsertProcess(string $file, string $host, string $token, array $options
exit(0);
}

/**
* @return array<string, mixed>
*/
function resolveAlternativePayload(array $options): array
{
$alternative = strtoupper((string) ($options['alternative'] ?? ''));
$publish = (bool) $options['publish'];

if ($alternative !== '' && !in_array($alternative, ['A', 'B'], true)) {
fail('--alternative must be A or B.');
}
if ($publish && $alternative !== 'B') {
fail('--publish is only valid with --alternative B.');
}
if ($alternative !== 'B') {
return [];
}

return ['alternative' => 'B', 'publish' => $publish];
}

function getProcess(
string $name,
string $host,
Expand Down Expand Up @@ -152,11 +174,10 @@ function request(
$options[CURLOPT_POSTFIELDS] = $encoded;
}

curl_setopt_array($handle, $options);
curl_setopt_array($handle, tlsOptions() + $options);
$body = curl_exec($handle);
$status = (int) curl_getinfo($handle, CURLINFO_HTTP_CODE);
$error = curl_error($handle);
curl_close($handle);

if ($body === false) {
fail("Request failed: {$error}");
Expand All @@ -171,14 +192,15 @@ function request(
) {
fwrite(STDERR, "HTTP {$status} from {$url}" . PHP_EOL);
fwrite(STDERR, $body . PHP_EOL);
printVersionNameHint((string) $body);
exit(1);
}

return $data;
}

/**
* @return array{0: ?string, 1: ?string, 2: array{host: ?string, token: ?string, output: ?string, description: ?string, version-name: ?string}}
* @return array{0: ?string, 1: ?string, 2: array{host: ?string, token: ?string, output: ?string, description: ?string, version-name: ?string, alternative: ?string, publish: bool}}
*/
function parseArguments(array $arguments): array
{
Expand All @@ -191,11 +213,22 @@ function parseArguments(array $arguments): array
'description' => null,
'category' => null,
'version-name' => null,
'alternative' => null,
];
$flags = ['publish' => false];

for ($index = 0; $index < count($arguments); $index++) {
$argument = $arguments[$index];

if ($argument === '--publish') {
$flags['publish'] = true;
continue;
}

if ($argument === '--insecure') {
continue; // Read by tlsOptions().
}

foreach (array_keys($options) as $option) {
if ($argument === "--{$option}") {
$options[$option] = $arguments[++$index] ?? '';
Expand All @@ -215,7 +248,7 @@ function parseArguments(array $arguments): array
fail("Unknown argument: {$argument}");
}

return [$command, $target, $options];
return [$command, $target, $options + $flags];
}

function resolvePath(string $path): string
Expand Down Expand Up @@ -331,7 +364,11 @@ function usage(): never
fwrite(STDERR, <<<TEXT
Usage:
php sync-process.php upsert path/to/process.bpmn [--host URL] [--token TOKEN] [--description TEXT] [--version-name TEXT]
php sync-process.php get process-name [--output path/to/process.bpmn] [--host URL] [--token TOKEN]
[--alternative B [--publish]] [--insecure]
php sync-process.php get process-name [--output path/to/process.bpmn] [--host URL] [--token TOKEN] [--insecure]

Local HTTPS with a self-signed certificate: --insecure (or PM_INSECURE=1), or PM_CA_BUNDLE=/path/ca.pem.
Updating an existing process needs --version-name.

TEXT);
exit(1);
Expand All @@ -342,3 +379,36 @@ function fail(string $message): never
fwrite(STDERR, $message . PHP_EOL);
exit(1);
}

/**
* TLS options for a local HTTPS instance with a self-signed or private CA.
*
* --insecure or PM_INSECURE=1 skips verification (local development only).
* PM_CA_BUNDLE or CURL_CA_BUNDLE points to a CA file and keeps verification on.
*
* @return array<int, mixed>
*/
function tlsOptions(): array
{
$env = loadDotEnv(dirname(__DIR__, 4) . '/.env');
$flag = strtolower((string) ($env['PM_INSECURE'] ?? getenv('PM_INSECURE') ?: ''));
if (in_array('--insecure', $GLOBALS['argv'] ?? [], true) || in_array($flag, ['1', 'true', 'yes'], true)) {
fwrite(STDERR, "Warning: TLS verification is disabled (--insecure or PM_INSECURE).\n");

return [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0];
}

$bundle = (string) ($env['PM_CA_BUNDLE'] ?? getenv('PM_CA_BUNDLE') ?: getenv('CURL_CA_BUNDLE') ?: '');

return $bundle !== '' && is_file($bundle) ? [CURLOPT_CAINFO => $bundle] : [];
}

/**
* Updating an existing asset needs a version name; say so instead of only printing the raw 422.
*/
function printVersionNameHint(string $body): void
{
if (stripos($body, 'version name') !== false) {
fwrite(STDERR, "Hint: this asset already exists, so an update needs --version-name \"short change summary\".\n");
}
}
11 changes: 11 additions & 0 deletions .agents/skills/upsert-screen-yaml/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,15 @@ php .agents/skills/upsert-screen-yaml/scripts/upsert-screen.php projects/{slug}/
php .agents/skills/upsert-screen-yaml/scripts/get-screen.php projects/{slug}/screens/{title}.yaml
```

Every item in the pulled YAML carries `inspector: []` (the export drops the inspector metadata and adds the empty list back), so a pulled screen can be pushed again without editing.

## Titles with `/`

The YAML basename is the screen title, and a file name cannot contain `/`. For a converter title such as `PD.01 / DT.13 / Totals v1.0`, use `PD.01 - DT.13 - Totals v1.0` as the file name and push it. That creates a screen with the new title; the original keeps its old title, so point the task's `${screen:...}` ref to the new one. Do not use look-alike Unicode slashes.

## Local HTTPS and updates

- A local instance with a self-signed certificate fails with `SSL certificate problem`. Pass `--insecure` (or set `PM_INSECURE=1`) for local development only, or set `PM_CA_BUNDLE=/path/to/ca.pem` (or `CURL_CA_BUNDLE`) to keep verification on. Using `http://` for a local host also works.
- Updating an asset that already exists needs `--version-name "short change summary"`. Without it the API returns 422 and the CLI prints a hint.

Publish **after** scripts, **before** process BPMN.
28 changes: 25 additions & 3 deletions .agents/skills/upsert-screen-yaml/scripts/get-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

if ($name === null || $name === '') {
fwrite(STDERR, "Usage: php get-screen.php path/to/screen.yaml [--host URL] [--token TOKEN]\n");
fwrite(STDERR, "Usage: php get-screen.php path/to/screen.yaml [--host URL] [--token TOKEN] [--insecure]\n");
fwrite(STDERR, " php get-screen.php --name screen-title [--out path/to/screen.yaml]\n");
exit(1);
}
Expand All @@ -57,7 +57,7 @@
$url = rtrim($host, '/') . ENDPOINT_PATH . '?name=' . rawurlencode($name);

$ch = curl_init($url);
curl_setopt_array($ch, [
curl_setopt_array($ch, tlsOptions() + [
CURLOPT_HTTPGET => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
Expand All @@ -70,7 +70,6 @@
$body = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($body === false) {
fwrite(STDERR, "Request failed: {$error}\n");
Expand Down Expand Up @@ -199,3 +198,26 @@ function loadDotEnv(string $path): array

return $vars;
}

/**
* TLS options for a local HTTPS instance with a self-signed or private CA.
*
* --insecure or PM_INSECURE=1 skips verification (local development only).
* PM_CA_BUNDLE or CURL_CA_BUNDLE points to a CA file and keeps verification on.
*
* @return array<int, mixed>
*/
function tlsOptions(): array
{
$env = loadDotEnv(dirname(__DIR__, 4) . '/.env');
$flag = strtolower((string) ($env['PM_INSECURE'] ?? getenv('PM_INSECURE') ?: ''));
if (in_array('--insecure', $GLOBALS['argv'] ?? [], true) || in_array($flag, ['1', 'true', 'yes'], true)) {
fwrite(STDERR, "Warning: TLS verification is disabled (--insecure or PM_INSECURE).\n");

return [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0];
}

$bundle = (string) ($env['PM_CA_BUNDLE'] ?? getenv('PM_CA_BUNDLE') ?: getenv('CURL_CA_BUNDLE') ?: '');

return $bundle !== '' && is_file($bundle) ? [CURLOPT_CAINFO => $bundle] : [];
}
39 changes: 36 additions & 3 deletions .agents/skills/upsert-screen-yaml/scripts/upsert-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
[$yamlFile, $hostOverride, $tokenOverride, $versionName] = parseCliArgs(array_slice($argv, 1));

if ($yamlFile === null) {
fwrite(STDERR, "Usage: php upsert-screen.php path/to/screen.yaml [--host URL] [--token TOKEN] [--version-name TEXT]\n");
fwrite(STDERR, "Usage: php upsert-screen.php path/to/screen.yaml [--host URL] [--token TOKEN] [--version-name TEXT] [--insecure]\n");
exit(1);
}

Expand Down Expand Up @@ -69,7 +69,7 @@
$payload = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

$ch = curl_init($url);
curl_setopt_array($ch, [
curl_setopt_array($ch, tlsOptions() + [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
Expand All @@ -84,7 +84,6 @@
$body = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($body === false) {
fwrite(STDERR, "Request failed: {$error}\n");
Expand All @@ -95,6 +94,7 @@
if (!is_array($data) || empty($data['success'])) {
fwrite(STDERR, "HTTP {$status} from {$url}\n");
fwrite(STDERR, $body . "\n");
printVersionNameHint((string) $body);
exit(1);
}

Expand Down Expand Up @@ -188,3 +188,36 @@ function loadDotEnv(string $path): array

return $vars;
}

/**
* TLS options for a local HTTPS instance with a self-signed or private CA.
*
* --insecure or PM_INSECURE=1 skips verification (local development only).
* PM_CA_BUNDLE or CURL_CA_BUNDLE points to a CA file and keeps verification on.
*
* @return array<int, mixed>
*/
function tlsOptions(): array
{
$env = loadDotEnv(dirname(__DIR__, 4) . '/.env');
$flag = strtolower((string) ($env['PM_INSECURE'] ?? getenv('PM_INSECURE') ?: ''));
if (in_array('--insecure', $GLOBALS['argv'] ?? [], true) || in_array($flag, ['1', 'true', 'yes'], true)) {
fwrite(STDERR, "Warning: TLS verification is disabled (--insecure or PM_INSECURE).\n");

return [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0];
}

$bundle = (string) ($env['PM_CA_BUNDLE'] ?? getenv('PM_CA_BUNDLE') ?: getenv('CURL_CA_BUNDLE') ?: '');

return $bundle !== '' && is_file($bundle) ? [CURLOPT_CAINFO => $bundle] : [];
}

/**
* Updating an existing asset needs a version name; say so instead of only printing the raw 422.
*/
function printVersionNameHint(string $body): void
{
if (stripos($body, 'version name') !== false) {
fwrite(STDERR, "Hint: this asset already exists, so an update needs --version-name \"short change summary\".\n");
}
}
11 changes: 10 additions & 1 deletion .agents/skills/upsert-script-php/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Auth: Bearer `PM_SYNC_TOKEN`, base `PM_BASE_URL` in package root `.env` (set by

`POST /api/1.0/deploy-script` — on **update**, required `version_name` → Version History `subject` (package-versions)

Body: `name` (title), `code` (full PHP), optional `description` and `script_category_name`.
Body: `name` (title), `code` (full PHP), optional `description`, `script_category_name`, and `script_executor_id` or `script_executor_title` (a `php` executor; the id wins).

### Executor

Without an executor, a new script goes to the first `php` executor on the instance. A plugin that runs its own classes in a script (`use ProcessMaker\Package\...`) needs the **plugin executor** (the one built with this package), so pass it: `--executor 13` (id) or `--executor "my-executor"` (title), or set `PM_SCRIPT_EXECUTOR` in `.env`. The option also moves an existing script to that executor on update. An update without it keeps the current executor. A missing executor or one that is not `php` returns 422.

Sidecars (same basename as the script): `{name}.description.txt`, `{name}.category.txt` (default category **Uncategorized** when the category file is absent).

Expand All @@ -37,6 +41,11 @@ XDEBUG_MODE=off php .agents/skills/upsert-script-php/scripts/get-script.php --na

Do not reimplement HTTP. Do not `git commit` unless asked.

## Local HTTPS and updates

- A local instance with a self-signed certificate fails with `SSL certificate problem`. Pass `--insecure` (or set `PM_INSECURE=1`) for local development only, or set `PM_CA_BUNDLE=/path/to/ca.pem` (or `CURL_CA_BUNDLE`) to keep verification on. Using `http://` for a local host also works.
- Updating an asset that already exists needs `--version-name "short change summary"`. Without it the API returns 422 and the CLI prints a hint.

## Compose

| Next step | Skill |
Expand Down
28 changes: 25 additions & 3 deletions .agents/skills/upsert-script-php/scripts/get-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

if ($name === null || $name === '') {
fwrite(STDERR, "Usage: php get-script.php path/to/script.php [--host URL] [--token TOKEN]\n");
fwrite(STDERR, "Usage: php get-script.php path/to/script.php [--host URL] [--token TOKEN] [--insecure]\n");
fwrite(STDERR, " php get-script.php --name script-title [--out path/to/script.php]\n");
exit(1);
}
Expand All @@ -56,7 +56,7 @@
$url = rtrim($host, '/') . ENDPOINT_PATH . '?name=' . rawurlencode($name);

$ch = curl_init($url);
curl_setopt_array($ch, [
curl_setopt_array($ch, tlsOptions() + [
CURLOPT_HTTPGET => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
Expand All @@ -69,7 +69,6 @@
$body = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($body === false) {
fwrite(STDERR, "Request failed: {$error}\n");
Expand Down Expand Up @@ -209,3 +208,26 @@ function loadDotEnv(string $path): array

return $vars;
}

/**
* TLS options for a local HTTPS instance with a self-signed or private CA.
*
* --insecure or PM_INSECURE=1 skips verification (local development only).
* PM_CA_BUNDLE or CURL_CA_BUNDLE points to a CA file and keeps verification on.
*
* @return array<int, mixed>
*/
function tlsOptions(): array
{
$env = loadDotEnv(dirname(__DIR__, 4) . '/.env');
$flag = strtolower((string) ($env['PM_INSECURE'] ?? getenv('PM_INSECURE') ?: ''));
if (in_array('--insecure', $GLOBALS['argv'] ?? [], true) || in_array($flag, ['1', 'true', 'yes'], true)) {
fwrite(STDERR, "Warning: TLS verification is disabled (--insecure or PM_INSECURE).\n");

return [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0];
}

$bundle = (string) ($env['PM_CA_BUNDLE'] ?? getenv('PM_CA_BUNDLE') ?: getenv('CURL_CA_BUNDLE') ?: '');

return $bundle !== '' && is_file($bundle) ? [CURLOPT_CAINFO => $bundle] : [];
}
Loading