@chosengeneration/light-code 0.156.0 → 0.157.0

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/dist/server.cjs CHANGED
@@ -46401,6 +46401,7 @@ var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
46401
46401
  // Shared CI under the user's name: starting or stopping a build, and replaying one with a local
46402
46402
  // Jenkinsfile, which runs whatever that file says with the job's credentials.
46403
46403
  "jenkins_start_build",
46404
+ "jenkins_write_job",
46404
46405
  "jenkins_stop_build",
46405
46406
  "jenkins_try_jenkinsfile",
46406
46407
  // Production schedules: an event (force-start, kill, hold, ice, status) or a changed definition.
@@ -52502,6 +52503,7 @@ var NEVER_AVAILABLE_TO_SCHEDULES = [
52502
52503
  "install_python_packages",
52503
52504
  // CI actions nobody would see happen: a build started, aborted, or replayed with a changed script.
52504
52505
  "jenkins_start_build",
52506
+ "jenkins_write_job",
52505
52507
  "jenkins_stop_build",
52506
52508
  "jenkins_try_jenkinsfile",
52507
52509
  // A production scheduler changed with nobody watching.
@@ -72597,6 +72599,253 @@ The merge succeeded, but tag ${params3.tag} was not created: ${error51 instanceo
72597
72599
  };
72598
72600
  }
72599
72601
 
72602
+ // ../../packages/core/dist/atlassian/jenkinsConfig.js
72603
+ var TAGS = {
72604
+ string: "hudson.model.StringParameterDefinition",
72605
+ text: "hudson.model.TextParameterDefinition",
72606
+ boolean: "hudson.model.BooleanParameterDefinition",
72607
+ choice: "hudson.model.ChoiceParameterDefinition"
72608
+ };
72609
+ function escapeXml(text2) {
72610
+ return text2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
72611
+ }
72612
+ function unescapeXml(text2) {
72613
+ return text2.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
72614
+ }
72615
+ function children(xml, from, to) {
72616
+ const out = [];
72617
+ const tag = /<(\/?)([A-Za-z_][\w.\-:$]*)([^>]*?)(\/?)>|<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!\[CDATA\[[\s\S]*?\]\]>/g;
72618
+ tag.lastIndex = from;
72619
+ let depth = 0;
72620
+ let open;
72621
+ for (let match = tag.exec(xml); match !== null && match.index < to; match = tag.exec(xml)) {
72622
+ if (match[2] === void 0)
72623
+ continue;
72624
+ const closing = match[1] === "/";
72625
+ const selfClosing = match[4] === "/";
72626
+ const end = match.index + match[0].length;
72627
+ if (closing) {
72628
+ depth -= 1;
72629
+ if (depth === 0 && open !== void 0) {
72630
+ out.push({ tag: open.tag, start: open.start, innerStart: open.innerStart, innerEnd: match.index, end });
72631
+ open = void 0;
72632
+ }
72633
+ } else if (selfClosing) {
72634
+ if (depth === 0)
72635
+ out.push({ tag: match[2], start: match.index, innerStart: end, innerEnd: end, end });
72636
+ } else {
72637
+ if (depth === 0)
72638
+ open = { tag: match[2], start: match.index, innerStart: end };
72639
+ depth += 1;
72640
+ }
72641
+ }
72642
+ return out;
72643
+ }
72644
+ function rootOf(xml) {
72645
+ const root = children(xml, 0, xml.length)[0];
72646
+ if (root === void 0)
72647
+ throw new Error("The job configuration is not XML Jenkins would accept (no root element).");
72648
+ return root;
72649
+ }
72650
+ function childNamed(xml, parent, tag) {
72651
+ return children(xml, parent.innerStart, parent.innerEnd).find((child) => child.tag === tag);
72652
+ }
72653
+ function textOf(xml, parent, tag) {
72654
+ const child = childNamed(xml, parent, tag);
72655
+ return child === void 0 ? void 0 : unescapeXml(xml.slice(child.innerStart, child.innerEnd).trim());
72656
+ }
72657
+ function lineIndent(xml, at) {
72658
+ const lineStart = xml.lastIndexOf("\n", at - 1) + 1;
72659
+ return /^[ \t]*/.exec(xml.slice(lineStart, at))?.[0] ?? "";
72660
+ }
72661
+ function parseParameter(xml, element) {
72662
+ const type = Object.entries(TAGS).find(([, tag]) => tag === element.tag)?.[0] ?? void 0;
72663
+ const choicesElement = childNamed(xml, element, "choices");
72664
+ const choices = choicesElement === void 0 ? void 0 : [...xml.slice(choicesElement.innerStart, choicesElement.innerEnd).matchAll(/<string>([\s\S]*?)<\/string>/g)].map((match) => unescapeXml(match[1] ?? ""));
72665
+ const description = textOf(xml, element, "description");
72666
+ const defaultValue = textOf(xml, element, "defaultValue");
72667
+ return {
72668
+ element,
72669
+ name: textOf(xml, element, "name") ?? "",
72670
+ ...type !== void 0 ? { type } : {},
72671
+ ...description !== void 0 ? { description } : {},
72672
+ ...defaultValue !== void 0 ? { default: defaultValue } : {},
72673
+ ...choices !== void 0 ? { choices } : {}
72674
+ };
72675
+ }
72676
+ function renderParameter(input, indent2) {
72677
+ const inner = `${indent2} `;
72678
+ const lines2 = [`${indent2}<${TAGS[input.type]}>`, `${inner}<name>${escapeXml(input.name)}</name>`, `${inner}<description>${escapeXml(input.description ?? "")}</description>`];
72679
+ if (input.type === "choice") {
72680
+ const choices = [...input.choices ?? []];
72681
+ if (choices.length === 0)
72682
+ throw new Error(`The choice parameter "${input.name}" needs at least one choice.`);
72683
+ if (input.default !== void 0) {
72684
+ const at = choices.indexOf(input.default);
72685
+ if (at < 0)
72686
+ throw new Error(`The default "${input.default}" is not one of the choices of "${input.name}" (${choices.join(", ")}).`);
72687
+ choices.splice(at, 1);
72688
+ choices.unshift(input.default);
72689
+ }
72690
+ lines2.push(`${inner}<choices class="java.util.Arrays$ArrayList">`, `${inner} <a class="string-array">`);
72691
+ for (const choice of choices)
72692
+ lines2.push(`${inner} <string>${escapeXml(choice)}</string>`);
72693
+ lines2.push(`${inner} </a>`, `${inner}</choices>`);
72694
+ } else if (input.type === "boolean") {
72695
+ lines2.push(`${inner}<defaultValue>${input.default === "true" ? "true" : "false"}</defaultValue>`);
72696
+ } else {
72697
+ lines2.push(`${inner}<defaultValue>${escapeXml(input.default ?? "")}</defaultValue>`);
72698
+ if (input.type === "string")
72699
+ lines2.push(`${inner}<trim>false</trim>`);
72700
+ }
72701
+ lines2.push(`${indent2}</${TAGS[input.type]}>`);
72702
+ return lines2.join("\n");
72703
+ }
72704
+ function jobParameters(xml) {
72705
+ const definitions = findDefinitions(xml);
72706
+ if (definitions === void 0)
72707
+ return [];
72708
+ return children(xml, definitions.innerStart, definitions.innerEnd).map((element) => {
72709
+ const parsed = parseParameter(xml, element);
72710
+ return {
72711
+ name: parsed.name,
72712
+ type: parsed.type ?? element.tag,
72713
+ ...parsed.default !== void 0 ? { default: parsed.default } : {},
72714
+ ...parsed.choices !== void 0 ? { choices: parsed.choices } : {}
72715
+ };
72716
+ });
72717
+ }
72718
+ function findDefinitions(xml) {
72719
+ const root = rootOf(xml);
72720
+ const properties = childNamed(xml, root, "properties");
72721
+ if (properties === void 0)
72722
+ return void 0;
72723
+ const property = childNamed(xml, properties, "hudson.model.ParametersDefinitionProperty");
72724
+ if (property === void 0)
72725
+ return void 0;
72726
+ return childNamed(xml, property, "parameterDefinitions");
72727
+ }
72728
+ function ensureDefinitions(xml) {
72729
+ const found2 = findDefinitions(xml);
72730
+ if (found2 !== void 0 && found2.innerStart === found2.innerEnd && xml.slice(found2.start, found2.end).endsWith("/>")) {
72731
+ const indent3 = lineIndent(xml, found2.start);
72732
+ return xml.slice(0, found2.start) + `<parameterDefinitions>
72733
+ ${indent3}</parameterDefinitions>` + xml.slice(found2.end);
72734
+ }
72735
+ if (found2 !== void 0)
72736
+ return xml;
72737
+ const root = rootOf(xml);
72738
+ const properties = childNamed(xml, root, "properties");
72739
+ const block2 = (indent3) => [`${indent3}<hudson.model.ParametersDefinitionProperty>`, `${indent3} <parameterDefinitions>`, `${indent3} </parameterDefinitions>`, `${indent3}</hudson.model.ParametersDefinitionProperty>`].join("\n");
72740
+ if (properties === void 0) {
72741
+ const indent3 = " ";
72742
+ const insert = `${indent3}<properties>
72743
+ ${block2(`${indent3} `)}
72744
+ ${indent3}</properties>
72745
+ `;
72746
+ return xml.slice(0, root.innerEnd) + insert + xml.slice(root.innerEnd);
72747
+ }
72748
+ const indent2 = lineIndent(xml, properties.start);
72749
+ if (properties.innerStart === properties.innerEnd && xml.slice(properties.start, properties.end).endsWith("/>")) {
72750
+ const replacement = `<properties>
72751
+ ${block2(`${indent2} `)}
72752
+ ${indent2}</properties>`;
72753
+ return xml.slice(0, properties.start) + replacement + xml.slice(properties.end);
72754
+ }
72755
+ const existing = childNamed(xml, properties, "hudson.model.ParametersDefinitionProperty");
72756
+ if (existing !== void 0) {
72757
+ const inner = `${lineIndent(xml, existing.start)} `;
72758
+ const list2 = `
72759
+ ${inner}<parameterDefinitions>
72760
+ ${inner}</parameterDefinitions>
72761
+ ${lineIndent(xml, existing.start)}`;
72762
+ if (existing.innerStart === existing.innerEnd) {
72763
+ const tag = "hudson.model.ParametersDefinitionProperty";
72764
+ return xml.slice(0, existing.start) + `<${tag}>${list2}</${tag}>` + xml.slice(existing.end);
72765
+ }
72766
+ return xml.slice(0, existing.innerStart) + list2 + xml.slice(existing.innerStart);
72767
+ }
72768
+ return xml.slice(0, properties.innerStart) + `
72769
+ ${block2(`${indent2} `)}` + xml.slice(properties.innerStart);
72770
+ }
72771
+ function applyJobChanges(original, changes) {
72772
+ let xml = original;
72773
+ const notes = [];
72774
+ for (const edit of changes.edits ?? []) {
72775
+ if (edit.find.length === 0)
72776
+ throw new Error("An edit has nothing to find.");
72777
+ const first = xml.indexOf(edit.find);
72778
+ if (first < 0)
72779
+ throw new Error(`Not found in the job configuration, so nothing was changed: ${JSON.stringify(edit.find.slice(0, 120))}`);
72780
+ if (xml.indexOf(edit.find, first + edit.find.length) >= 0) {
72781
+ throw new Error(`Found more than once in the job configuration - include more around it so it is unique: ${JSON.stringify(edit.find.slice(0, 120))}`);
72782
+ }
72783
+ xml = xml.slice(0, first) + edit.replace + xml.slice(first + edit.find.length);
72784
+ notes.push("edited the configuration text");
72785
+ }
72786
+ if (changes.description !== void 0) {
72787
+ const root = rootOf(xml);
72788
+ const description = childNamed(xml, root, "description");
72789
+ const value = escapeXml(changes.description);
72790
+ if (description === void 0) {
72791
+ xml = xml.slice(0, root.innerStart) + `
72792
+ <description>${value}</description>` + xml.slice(root.innerStart);
72793
+ } else {
72794
+ xml = xml.slice(0, description.start) + `<description>${value}</description>` + xml.slice(description.end);
72795
+ }
72796
+ notes.push("set the description");
72797
+ }
72798
+ const remove = changes.parameters?.remove ?? [];
72799
+ const set2 = changes.parameters?.set ?? [];
72800
+ if (remove.length > 0 || set2.length > 0) {
72801
+ xml = ensureDefinitions(xml);
72802
+ for (const name of remove) {
72803
+ const definitions = findDefinitions(xml);
72804
+ const found2 = definitions === void 0 ? void 0 : children(xml, definitions.innerStart, definitions.innerEnd).find((element) => parseParameter(xml, element).name === name);
72805
+ if (found2 === void 0)
72806
+ throw new Error(`The job has no parameter "${name}" to remove.`);
72807
+ const lineStart = xml.lastIndexOf("\n", found2.start - 1);
72808
+ xml = xml.slice(0, lineStart >= 0 ? lineStart : found2.start) + xml.slice(found2.end);
72809
+ notes.push(`removed parameter ${name}`);
72810
+ }
72811
+ for (const input of set2) {
72812
+ if (input.name.trim().length === 0)
72813
+ throw new Error("A parameter needs a name.");
72814
+ const definitions = findDefinitions(xml);
72815
+ if (definitions === void 0)
72816
+ throw new Error("Could not find where the job keeps its parameters.");
72817
+ const existingElement = children(xml, definitions.innerStart, definitions.innerEnd).find((element) => parseParameter(xml, element).name === input.name);
72818
+ const existing = existingElement === void 0 ? void 0 : parseParameter(xml, existingElement);
72819
+ if (existing !== void 0 && existing.type === void 0 && input.type === void 0) {
72820
+ throw new Error(`The parameter "${input.name}" is of a kind this tool does not rewrite (${existing.element.tag}). Give a type to replace it, or change it with edits.`);
72821
+ }
72822
+ const type = input.type ?? existing?.type ?? "string";
72823
+ const defaultValue = input.default !== void 0 ? String(input.default) : existing?.default ?? (type === "choice" ? existing?.choices?.[0] : void 0);
72824
+ const merged = {
72825
+ name: input.name,
72826
+ type,
72827
+ description: input.description ?? existing?.description,
72828
+ default: defaultValue,
72829
+ choices: input.choices ?? existing?.choices
72830
+ };
72831
+ if (existingElement !== void 0) {
72832
+ const rendered = renderParameter(merged, lineIndent(xml, existingElement.start));
72833
+ xml = xml.slice(0, existingElement.start) + rendered.trimStart() + xml.slice(existingElement.end);
72834
+ notes.push(`changed parameter ${input.name}`);
72835
+ } else {
72836
+ const indent2 = `${lineIndent(xml, definitions.start)} `;
72837
+ const closeIndent = lineIndent(xml, definitions.innerEnd);
72838
+ const before = xml.slice(0, definitions.innerEnd).replace(/[ \t]*$/, "");
72839
+ const glue = before.endsWith("\n") ? "" : "\n";
72840
+ xml = `${before}${glue}${renderParameter(merged, indent2)}
72841
+ ${closeIndent}${xml.slice(definitions.innerEnd)}`;
72842
+ notes.push(`added parameter ${input.name}`);
72843
+ }
72844
+ }
72845
+ }
72846
+ return { xml, notes };
72847
+ }
72848
+
72600
72849
  // ../../packages/core/dist/atlassian/jenkins.js
72601
72850
  function jobPath(job, base) {
72602
72851
  let text2 = job.trim();
@@ -72844,11 +73093,13 @@ ${text2.slice(-2e4)}`);
72844
73093
  * current Jenkins; an older or stricter one answers 403 mentioning the crumb, and gets one retry.
72845
73094
  */
72846
73095
  async post(doing, pathAndQuery, form, signal) {
72847
- const body = new URLSearchParams(form).toString();
73096
+ return this.postBody(doing, pathAndQuery, new URLSearchParams(form).toString(), "application/x-www-form-urlencoded", signal);
73097
+ }
73098
+ async postBody(doing, pathAndQuery, body, contentType2, signal) {
72848
73099
  const send2 = () => this.rest.send(doing, pathAndQuery, {
72849
73100
  method: "POST",
72850
73101
  headers: {
72851
- "Content-Type": "application/x-www-form-urlencoded",
73102
+ "Content-Type": contentType2,
72852
73103
  ...this.crumb !== void 0 ? { [this.crumb.field]: this.crumb.value } : {}
72853
73104
  },
72854
73105
  body
@@ -72888,6 +73139,33 @@ ${text2.slice(-2e4)}`);
72888
73139
  async stopBuild(job, build2, signal) {
72889
73140
  await this.post(`stopping ${job} #${String(build2)}`, `${jobPath(job, this.base)}/${buildRef(build2)}/stop`, {}, signal);
72890
73141
  }
73142
+ /** A job's config.xml, as Jenkins holds it now. */
73143
+ async configXml(job, signal) {
73144
+ return this.rest.text(`reading the configuration of ${job}`, `${jobPath(job, this.base)}/config.xml`, signal);
73145
+ }
73146
+ /** Whether a job (or folder) of this name exists. */
73147
+ async exists(job, signal) {
73148
+ try {
73149
+ await this.rest.json(`looking for ${job}`, `${jobPath(job, this.base)}/api/json?tree=name`, { method: "GET" }, signal);
73150
+ return true;
73151
+ } catch (error51) {
73152
+ if (error51 instanceof AtlassianError && error51.status === 404)
73153
+ return false;
73154
+ throw error51;
73155
+ }
73156
+ }
73157
+ /** Creates a job from a whole config.xml, in the folder its name gives (`folder/sub/new-job`). */
73158
+ async createJob(job, xml, signal) {
73159
+ const path62 = jobPath(job, this.base);
73160
+ const cut = path62.lastIndexOf("/job/");
73161
+ const parent = path62.slice(0, cut);
73162
+ const name = decodeURIComponent(path62.slice(cut + "/job/".length));
73163
+ await this.postBody(`creating ${job}`, `${parent}/createItem?${new URLSearchParams({ name }).toString()}`, xml, "application/xml", signal);
73164
+ }
73165
+ /** Replaces a job's config.xml. */
73166
+ async saveConfig(job, xml, signal) {
73167
+ await this.postBody(`saving the configuration of ${job}`, `${jobPath(job, this.base)}/config.xml`, xml, "application/xml", signal);
73168
+ }
72891
73169
  /** The declarative linter. Read-only on the server; answers in plain text. */
72892
73170
  async validateJenkinsfile(text2, signal) {
72893
73171
  const response = await this.post("validating a Jenkinsfile", "/pipeline-model-converter/validate", { jenkinsfile: text2 }, signal);
@@ -73331,6 +73609,111 @@ ${log.slice(-6e3)}`);
73331
73609
  return tail === void 0 ? "" : `End of the log:
73332
73610
  ${tail.text}`;
73333
73611
  }
73612
+ var parameterInput = external_exports.object({
73613
+ name: external_exports.string().min(1),
73614
+ type: external_exports.enum(["string", "text", "boolean", "choice"]).optional().describe("Default string for a new parameter; an existing one keeps its type."),
73615
+ description: external_exports.string().optional(),
73616
+ default: external_exports.union([external_exports.string(), external_exports.boolean()]).optional().describe("The default value; for a choice, which choice comes first."),
73617
+ choices: external_exports.array(external_exports.string()).optional().describe("For a choice parameter: every choice.")
73618
+ });
73619
+ function createJenkinsWriteJobTool(options) {
73620
+ const schema8 = external_exports.object({
73621
+ action: external_exports.enum(["create", "copy", "update"]).describe(`create: a new job from a whole config (or an existing job's config given as from). copy: a new job copied from "from", optionally changed. update: change an existing job.`),
73622
+ job: external_exports.string().describe("The job to create (copy, create) or change (update), as folder/name. For create and copy it must not exist yet."),
73623
+ from: external_exports.string().optional().describe("copy: the existing job to copy, as folder/name or its URL."),
73624
+ config: external_exports.string().optional().describe("create: the whole config.xml. Prefer copy from a similar job - a config written from scratch is easy to get subtly wrong."),
73625
+ parameters: external_exports.object({
73626
+ set: external_exports.array(parameterInput).optional().describe("Add these parameters, or change those of the same name."),
73627
+ remove: external_exports.array(external_exports.string()).optional().describe("Parameter names to remove.")
73628
+ }).optional(),
73629
+ description: external_exports.string().optional().describe("The job's description."),
73630
+ edits: external_exports.array(external_exports.object({ find: external_exports.string().min(1), replace: external_exports.string() })).optional().describe("Exact text changes to the config.xml - for anything else (script path, branch, schedule, agent label). Each find must occur exactly once; read the job with jenkins_job and include enough around it to be unique.")
73631
+ });
73632
+ const shown2 = /* @__PURE__ */ new Map();
73633
+ const keyOf = (params3) => JSON.stringify(params3);
73634
+ const plan2 = async (client, params3) => {
73635
+ const target = params3.job.trim();
73636
+ jobPath(target, client.base);
73637
+ const changes = {
73638
+ ...params3.parameters !== void 0 ? { parameters: params3.parameters } : {},
73639
+ ...params3.description !== void 0 ? { description: params3.description } : {},
73640
+ ...params3.edits !== void 0 ? { edits: params3.edits } : {}
73641
+ };
73642
+ if (params3.action === "update") {
73643
+ const before = await client.configXml(target);
73644
+ const changed2 = applyJobChanges(before, changes);
73645
+ if (changed2.xml === before)
73646
+ throw new AtlassianError("Nothing would change: give parameters, a description or edits.");
73647
+ return { before, after: changed2.xml, notes: changed2.notes, target };
73648
+ }
73649
+ if (await client.exists(target)) {
73650
+ throw new AtlassianError(`"${target}" already exists. Use action update to change it, or pick another name - a job is never replaced by creating or copying over it.`);
73651
+ }
73652
+ if (params3.action === "copy") {
73653
+ if (params3.from === void 0 || params3.from.trim().length === 0)
73654
+ throw new AtlassianError('copy needs "from": the job to copy.');
73655
+ const source = await client.configXml(params3.from.trim());
73656
+ const changed2 = applyJobChanges(source, changes);
73657
+ return { before: source, after: changed2.xml, notes: [`copied from ${params3.from.trim()}`, ...changed2.notes], target };
73658
+ }
73659
+ if (params3.config === void 0 || params3.config.trim().length === 0) {
73660
+ throw new AtlassianError('create needs "config", the whole config.xml - or use copy from a similar job.');
73661
+ }
73662
+ const changed = applyJobChanges(params3.config, changes);
73663
+ return { before: "", after: changed.xml, notes: ["a new job", ...changed.notes], target };
73664
+ };
73665
+ const tool = {
73666
+ name: "jenkins_write_job",
73667
+ group: "command",
73668
+ description: `Create a Jenkins job, copy an existing job into a new one, or change a job's configuration - most often its parameters (add, change default/choices/description, remove), and anything else by exact text edits of its config.xml. To make a job "like X but with new parameters", use copy with from: X and parameters.set. Never deletes a job and never replaces an existing one by creating over it. Always shown to the user first as a diff of the configuration Jenkins will be sent; it cannot be set to always allow.`,
73669
+ parametersSchema: schema8,
73670
+ async preview(params3) {
73671
+ try {
73672
+ const client = await options.client();
73673
+ const result = await plan2(client, params3);
73674
+ shown2.set(keyOf(params3), { before: result.before, after: result.after });
73675
+ const parameters = jobParameters(result.after);
73676
+ return {
73677
+ kind: "diff",
73678
+ path: `${client.base}${jobPath(result.target, client.base)}/config.xml`,
73679
+ before: result.before,
73680
+ after: result.after,
73681
+ note: [
73682
+ `${params3.action === "update" ? "Change" : "Create"} Jenkins job ${result.target}: ${result.notes.join(", ")}`,
73683
+ parameters.length > 0 ? `Parameters after: ${parameters.map((each) => `${each.name} (${each.type}${each.default !== void 0 ? ` = ${each.default}` : ""})`).join(", ")}` : "No parameters"
73684
+ ].join(" \xB7 ")
73685
+ };
73686
+ } catch (error51) {
73687
+ return { kind: "text", text: `${error51 instanceof Error ? error51.message : String(error51)} - this will be refused.` };
73688
+ }
73689
+ },
73690
+ async execute(params3) {
73691
+ try {
73692
+ const client = await options.client();
73693
+ const approved = shown2.get(keyOf(params3));
73694
+ const now = await plan2(client, params3);
73695
+ if (approved !== void 0 && approved.before !== now.before) {
73696
+ return {
73697
+ content: `${params3.action === "update" ? params3.job : params3.from ?? params3.job} changed on Jenkins after this was shown, so nothing was saved. Ask again to see the change against the current configuration.`,
73698
+ isError: true
73699
+ };
73700
+ }
73701
+ const xml = approved?.after ?? now.after;
73702
+ if (params3.action === "update")
73703
+ await client.saveConfig(now.target, xml);
73704
+ else
73705
+ await client.createJob(now.target, xml);
73706
+ shown2.delete(keyOf(params3));
73707
+ const link = `${client.base}${jobPath(now.target, client.base)}/`;
73708
+ return { content: `${params3.action === "update" ? "Saved" : "Created"} ${now.target}: ${now.notes.join(", ")}.
73709
+ Link: ${link}` };
73710
+ } catch (error51) {
73711
+ return errorResult2(error51);
73712
+ }
73713
+ }
73714
+ };
73715
+ return tool;
73716
+ }
73334
73717
  function createJenkinsTools(options) {
73335
73718
  return [
73336
73719
  createJenkinsFindJobsTool(options),
@@ -73341,7 +73724,8 @@ function createJenkinsTools(options) {
73341
73724
  createJenkinsStartBuildTool(options),
73342
73725
  createJenkinsStopBuildTool(options),
73343
73726
  createJenkinsCheckJenkinsfileTool(options),
73344
- createJenkinsTryJenkinsfileTool(options)
73727
+ createJenkinsTryJenkinsfileTool(options),
73728
+ createJenkinsWriteJobTool(options)
73345
73729
  ];
73346
73730
  }
73347
73731
 
@@ -76240,8 +76624,8 @@ function parseInline(source) {
76240
76624
  out.push({ kind: "code", text: (match[2] ?? "").replace(/^ (.*) $/, "$1") });
76241
76625
  } else if (match[4] !== void 0) {
76242
76626
  const href = match[4];
76243
- const children = parseInline(match[3] ?? "");
76244
- out.push(isSafeHref(href) ? { kind: "link", href, children } : { kind: "text", text: match[0] });
76627
+ const children2 = parseInline(match[3] ?? "");
76628
+ out.push(isSafeHref(href) ? { kind: "link", href, children: children2 } : { kind: "text", text: match[0] });
76245
76629
  } else if (match[5] !== void 0) {
76246
76630
  out.push({ kind: "strong", children: parseInline(match[6] ?? "") });
76247
76631
  } else if (match[7] !== void 0) {
@@ -91229,7 +91613,16 @@ comment or move fails after the fields were saved, the result says exactly which
91229
91613
  "queue",
91230
91614
  "agent offline",
91231
91615
  "api token",
91232
- "sso"
91616
+ "sso",
91617
+ "create job",
91618
+ "new job",
91619
+ "clone job",
91620
+ "copy job",
91621
+ "modify job",
91622
+ "job parameters",
91623
+ "add parameter",
91624
+ "job config",
91625
+ "config.xml"
91233
91626
  ],
91234
91627
  body: `
91235
91628
  **Settings \u2192 DevOps \u2192 Jenkins**: the site address, an **API token**, your **Jenkins user id**, and
@@ -91266,7 +91659,15 @@ an access token as a Bearer token, leave the user id empty and paste that token
91266
91659
  end of its log. Needs a pipeline job that has run at least once and the Replay permission. Run
91267
91660
  \`jenkins_check_jenkinsfile\` first; it is instant and catches syntax and unknown steps.
91268
91661
 
91269
- There is no tool that changes a job's configuration.
91662
+ - \`jenkins_write_job\` \u2014 **create a job, copy one into a new job, or change a job**. "A job like
91663
+ platform/api but with a HOTFIX branch parameter" is a copy with new parameters. Parameters are set by
91664
+ name, type (string, text, boolean, choice), default, description and choices, or removed; anything
91665
+ else (script path, branch, schedule, agent label) is an exact edit of the job's config.xml. The
91666
+ approval shows the diff of the configuration Jenkins will be sent - against the job copied, or the job
91667
+ as Jenkins holds it now - and it **cannot be set to always allow**. It never deletes a job, never
91668
+ creates or copies over an existing one, and refuses to save if the job was edited on Jenkins after
91669
+ you were shown the change. Ticking **My access is read-only** removes it with the other acting tools.
91670
+ Needs the Job/Create or Job/Configure permission on your Jenkins.
91270
91671
  `
91271
91672
  },
91272
91673
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chosengeneration/light-code",
3
- "version": "0.156.0",
3
+ "version": "0.157.0",
4
4
  "description": "A minimal agentic coding assistant, served to your browser from a local Node server",
5
5
  "license": "MIT",
6
6
  "type": "module",