codecraftai-taskplus 1.3.1__tar.gz → 1.4.1__tar.gz
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.
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/LICENSE.md +30 -21
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/PKG-INFO +1 -1
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/pyproject.toml +1 -1
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/execution.py +22 -2
- codecraftai_taskplus-1.4.1/source/packages/ccai/taskplus/model/flowengine.py +175 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/workflow.py +100 -1
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/createenvironment.py +17 -3
- codecraftai_taskplus-1.4.1/source/packages/ccai/taskplus/tasks/embeddedpython.py +78 -0
- codecraftai_taskplus-1.4.1/source/packages/ccai/taskplus/tasks/outputtext.py +27 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/runcommand.py +3 -2
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/shellscript.py +22 -7
- codecraftai_taskplus-1.3.1/source/packages/ccai/taskplus/model/flowengine.py +0 -106
- codecraftai_taskplus-1.3.1/source/packages/ccai/taskplus/tasks/embeddedpython.py +0 -49
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/README.md +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/__init__.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/__init__.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/cmdtree/__init__.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/cmdtree/workflow.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/taskpluscommand.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/entrypoints.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/initialize.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/__init__.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/flownode.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/task.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/taskgroup.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/py.typed +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/__init__.py +0 -0
- {codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/gitcheckout.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Code Craft AI - Source Available License
|
|
2
|
-
Version 1.
|
|
2
|
+
Version 1.1, November 2026
|
|
3
3
|
|
|
4
4
|
Copyright (C) 2026, Code Craft AI LLC
|
|
5
5
|
|
|
@@ -7,12 +7,12 @@ Everyone is permitted to copy and distribute verbatim copies of *This License* d
|
|
|
7
7
|
|
|
8
8
|
*This License* covers the Python Automation Kit, the full suite of software published by *Licensor* that consists of every `codecraftai-*` package, every `pychestrate` package, and the `pychestrate` server.
|
|
9
9
|
|
|
10
|
-
*The Software* is source available. Its source code is published so that anyone can read it, learn from it, and use it, but *This License* is not an open source license. *The Software* is free to use for *Non-Commercial Use*. *Commercial Use* is permitted in exchange for a *Usage Fee* that is based on a reasonable estimation of the income derived from *The Software*, as described in section 5. When a company migrates a product or service to *The Software* from another code base, the *
|
|
10
|
+
*The Software* is source available. Its source code is published so that anyone can read it, learn from it, and use it, but *This License* is not an open source license. *The Software* is free to use for *Non-Commercial Use*. *Commercial Use* is permitted in exchange for a *Usage Fee* that is based on a reasonable estimation of the income derived from *The Software*, as described in section 5. That estimation starts from *Gross Income*, not net profit, so spending on research and development or other operating expenses does not reduce it. When a company migrates a product or service to *The Software* from another code base, the *Gross Income* from that product or service is not counted toward the *Usage Fee* for two years, as described in section 5.4. For assurance of costs, a company can disclose its usage and estimated returns to *Licensor* and negotiate a fixed license cost, as described in section 5.10.
|
|
11
11
|
|
|
12
12
|
## 1. Definitions
|
|
13
13
|
|
|
14
14
|
### 1.1 *This License* or *The License*
|
|
15
|
-
**This License** or **The License** refers to version 1.
|
|
15
|
+
**This License** or **The License** refers to version 1.1 of the Code Craft AI - Source Available License.
|
|
16
16
|
|
|
17
17
|
### 1.2 Licensor
|
|
18
18
|
**Licensor** refers to Code Craft AI LLC.
|
|
@@ -42,14 +42,14 @@ Everyone is permitted to copy and distribute verbatim copies of *This License* d
|
|
|
42
42
|
### 1.9 Fiscal Year
|
|
43
43
|
**Fiscal Year** means the annual accounting period that *You* use for financial reporting.
|
|
44
44
|
|
|
45
|
-
### 1.10
|
|
46
|
-
**
|
|
45
|
+
### 1.10 Gross Income
|
|
46
|
+
**Gross Income** means, for each product or service in connection with which *You* make *Commercial Use* of *The Software*, the gross profit that *You* earn from that product or service during a *Fiscal Year*: the revenue from that product or service, less its cost of goods sold or cost of revenue, determined under the accounting principles that *You* regularly use for financial reporting. *Gross Income* is calculated before operating expenses, such as research and development, sales and marketing, and general and administrative expenses, and before interest and taxes. *Gross Income* is measured for the products and services that *The Software* is used for, not for *Your* business as a whole.
|
|
47
47
|
|
|
48
48
|
### 1.11 Contribution Estimate
|
|
49
|
-
**Contribution Estimate** means *Your* reasonable, good faith estimate of the portion of the *
|
|
49
|
+
**Contribution Estimate** means *Your* reasonable, good faith estimate of the portion of the *Gross Income* that *The Software* contributed to, expressed as a number from 0 to 1.
|
|
50
50
|
|
|
51
51
|
### 1.12 Derived Income
|
|
52
|
-
**Derived Income** means the portion of the *
|
|
52
|
+
**Derived Income** means the portion of the *Gross Income* for a *Fiscal Year* that is derived from *The Software*, calculated as described in section 5.2.
|
|
53
53
|
|
|
54
54
|
### 1.13 Usage Fee
|
|
55
55
|
**Usage Fee** means the yearly fee for *Commercial Use* that is set by the table in section 5.3.
|
|
@@ -58,7 +58,7 @@ Everyone is permitted to copy and distribute verbatim copies of *This License* d
|
|
|
58
58
|
**Migration** means moving the work for one of *Your* products or services from a code base other than *The Software*, such as another framework, another library, or *Your* own code, to *The Software*.
|
|
59
59
|
|
|
60
60
|
### 1.15 Migration Period
|
|
61
|
-
**Migration Period** means the two (2) year period, described in section 5.4, during which the *
|
|
61
|
+
**Migration Period** means the two (2) year period, described in section 5.4, during which the *Gross Income* from a product or service that *You* are migrating to *The Software* is not counted.
|
|
62
62
|
|
|
63
63
|
## 2. License Grant
|
|
64
64
|
|
|
@@ -96,11 +96,11 @@ For each *Fiscal Year* in which *You* make *Commercial Use* of *The Software*, *
|
|
|
96
96
|
### 5.2 Derived Income
|
|
97
97
|
The *Derived Income* for a *Fiscal Year* is calculated as follows:
|
|
98
98
|
|
|
99
|
-
(Contribution Estimate) * (
|
|
99
|
+
(Contribution Estimate) * (Gross Income) = (Derived Income)
|
|
100
100
|
|
|
101
|
-
If *You* make *Commercial Use* of *The Software* for more than one product or service, calculate the *Derived Income* for each product or service using its own *Contribution Estimate* and *
|
|
101
|
+
If *You* make *Commercial Use* of *The Software* for more than one product or service, calculate the *Derived Income* for each product or service using its own *Contribution Estimate* and *Gross Income*, and add the results together. The *Gross Income* from a product or service that is in its *Migration Period* is not counted, as described in section 5.4.
|
|
102
102
|
|
|
103
|
-
If the *
|
|
103
|
+
If the *Gross Income* from a product or service for a *Fiscal Year* is zero or less, then the *Derived Income* from that product or service for that *Fiscal Year* is zero.
|
|
104
104
|
|
|
105
105
|
### 5.3 Usage Fee
|
|
106
106
|
The *Usage Fee* for a *Fiscal Year* is set by the *Derived Income* for that *Fiscal Year*, as shown in the following table.
|
|
@@ -113,56 +113,65 @@ The *Usage Fee* for a *Fiscal Year* is set by the *Derived Income* for that *Fis
|
|
|
113
113
|
| More than 100,000,000, up to and including 1,000,000,000 | 250,000 |
|
|
114
114
|
| More than 1,000,000,000 | 500,000 |
|
|
115
115
|
|
|
116
|
-
All amounts in this section 5 are in United States dollars. If *You* report *
|
|
116
|
+
All amounts in this section 5 are in United States dollars. If *You* report *Gross Income* in a different currency, convert the *Derived Income* to United States dollars using the average exchange rate for the *Fiscal Year*.
|
|
117
117
|
|
|
118
118
|
### 5.4 Migration Allowance
|
|
119
|
-
When *You* migrate a product or service to *The Software*, the *
|
|
119
|
+
When *You* migrate a product or service to *The Software*, the *Gross Income* from that product or service is not counted when calculating the *Derived Income* during its *Migration Period* (the **Migration Allowance**).
|
|
120
120
|
|
|
121
121
|
The *Migration Period* for a product or service begins on the date that *You* first make *Commercial Use* of *The Software* for that product or service as part of its *Migration*, and ends two (2) years after that date.
|
|
122
122
|
|
|
123
123
|
The *Migration Allowance* applies to each product or service separately, and *You* may use it for every product or service that *You* migrate. Each product or service has only one *Migration Period*.
|
|
124
124
|
|
|
125
|
-
If a *Fiscal Year* is only partly within the *Migration Period* of a product or service, the *
|
|
125
|
+
If a *Fiscal Year* is only partly within the *Migration Period* of a product or service, the *Gross Income* from that product or service for that *Fiscal Year* is reduced in proportion to the number of days of that *Fiscal Year* that fall within its *Migration Period*.
|
|
126
126
|
|
|
127
|
-
For example, a company tests product A with *The Software* and pays a *Usage Fee* based on the *
|
|
127
|
+
For example, a company tests product A with *The Software* and pays a *Usage Fee* based on the *Gross Income* from product A. On March 1, 2027, the company begins moving the testing of product B from a different test framework to *The Software*. The company does not count the *Gross Income* from product B in its *Derived Income* from March 1, 2027 until March 1, 2029. Starting March 1, 2029, the *Gross Income* from product B is counted. If the company later migrates product C, the *Gross Income* from product C is not counted for two years from the start of its own *Migration*.
|
|
128
128
|
|
|
129
129
|
### 5.5 Contribution Estimate
|
|
130
130
|
*You* are responsible for making the *Contribution Estimate*. A *Contribution Estimate* must be reasonable and made in good faith. The *Contribution Estimate* for a product or service covers all of the *Components* that *You* *Use* for that product or service. When making the *Contribution Estimate*, *You* should consider how important *The Software* is to the *Commercial Activity*, how much of the *Commercial Activity* depends on *The Software*, and the effort and cost that *You* would otherwise need to spend to accomplish what *The Software* accomplishes for *You*.
|
|
131
131
|
|
|
132
132
|
The following table is a guide for making the *Contribution Estimate*. When *Your* *Commercial Use* of *The Software* matches an entry in the table, the *Contribution Estimate* in that entry is a reasonable *Contribution Estimate*. When *Your* *Commercial Use* does not match an entry in the table, make the *Contribution Estimate* by comparing *Your* *Commercial Use* with the entries in the table. When more than one entry matches the same *Commercial Activity*, use the entry with the highest *Contribution Estimate*.
|
|
133
133
|
|
|
134
|
+
Many products are not software, such as devices, machines, vehicles, and other physical goods, and software accounts for only part of what such a product is worth. For a product or service that is not software, *You* may reduce the *Contribution Estimate* in proportion to the share of the value of the shipped product that its software reasonably accounts for. To do so, multiply the *Contribution Estimate* from the table by that share, expressed as a number from 0 to 1. *You* must keep records that reasonably support that share, as described in section 5.8.
|
|
135
|
+
|
|
134
136
|
| Commercial Use of *The Software* | Contribution Estimate |
|
|
135
137
|
|----------------------------------|-----------------------|
|
|
136
138
|
| Quality Assurance (QA) and Continuous Integration (CI): *The Software* is used to test or validate the products or services of the *Commercial Activity*, or to run their build and test pipelines | 0.3 |
|
|
137
139
|
| Products Completely Based on *The Software*: the products or services of the *Commercial Activity* are built completely on *The Software* | 0.5 |
|
|
138
140
|
|
|
139
141
|
### 5.6 Examples
|
|
140
|
-
A company earns 1,000,000,000 in *
|
|
142
|
+
A company earns 1,000,000,000 in *Gross Income* from a product line during a *Fiscal Year*. The company uses *The Software* for the QA and CI of that product line, so the *Contribution Estimate* is 0.3.
|
|
141
143
|
|
|
142
144
|
0.3 * 1,000,000,000 = 300,000,000
|
|
143
145
|
|
|
144
146
|
The *Derived Income* of 300,000,000 is more than 100,000,000 and not more than 1,000,000,000, so the *Usage Fee* for that *Fiscal Year* is 250,000.
|
|
145
147
|
|
|
146
|
-
A company earns 4,000,000 in *
|
|
148
|
+
A company earns 4,000,000 in *Gross Income* from a product during a *Fiscal Year*. The product is built completely on *The Software*, so the *Contribution Estimate* is 0.5.
|
|
147
149
|
|
|
148
150
|
0.5 * 4,000,000 = 2,000,000
|
|
149
151
|
|
|
150
152
|
The *Derived Income* of 2,000,000 is more than 1,000,000 and not more than 10,000,000, so the *Usage Fee* for that *Fiscal Year* is 50,000.
|
|
151
153
|
|
|
152
|
-
A company earns 3,000,000 in *
|
|
154
|
+
A company earns 3,000,000 in *Gross Income* from a product line during a *Fiscal Year*. The company uses *The Software* for the QA and CI of that product line, so the *Contribution Estimate* is 0.3.
|
|
153
155
|
|
|
154
156
|
0.3 * 3,000,000 = 900,000
|
|
155
157
|
|
|
156
158
|
The *Derived Income* of 900,000 is 1,000,000 or less, so there is no *Usage Fee* for that *Fiscal Year*.
|
|
157
159
|
|
|
160
|
+
A company earns 50,000,000 in *Gross Income* from a line of medical devices during a *Fiscal Year*. The company uses *The Software* for the QA and CI of the devices, so the *Contribution Estimate* from the table is 0.3. The devices are not software, and the company reasonably estimates that their software accounts for one fifth (0.2) of the value of each shipped device, so the company reduces the *Contribution Estimate* to 0.06.
|
|
161
|
+
|
|
162
|
+
0.3 * 0.2 = 0.06
|
|
163
|
+
0.06 * 50,000,000 = 3,000,000
|
|
164
|
+
|
|
165
|
+
The *Derived Income* of 3,000,000 is more than 1,000,000 and not more than 10,000,000, so the *Usage Fee* for that *Fiscal Year* is 50,000. Without the reduction, the *Derived Income* would be 15,000,000 and the *Usage Fee* would be 100,000.
|
|
166
|
+
|
|
158
167
|
### 5.7 Reporting and Payment
|
|
159
|
-
Within one hundred twenty (120) days after the end of each *Fiscal Year* for which a *Usage Fee* is owed, *You* must pay the *Usage Fee* to *Licensor* and provide *Licensor* with a written statement that shows the *
|
|
168
|
+
Within one hundred twenty (120) days after the end of each *Fiscal Year* for which a *Usage Fee* is owed, *You* must pay the *Usage Fee* to *Licensor* and provide *Licensor* with a written statement that shows the *Gross Income*, the *Contribution Estimate*, the reasoning used to make the *Contribution Estimate*, the *Derived Income*, and the *Usage Fee*. *Usage Fees* are payable in United States dollars. If any *Gross Income* is not counted under section 5.4, the statement must also identify each product or service that is in a *Migration Period* and show the dates of its *Migration Period*. No statement is required for a *Fiscal Year* in which no *Usage Fee* is owed.
|
|
160
169
|
|
|
161
170
|
### 5.8 Records and Review
|
|
162
|
-
*You* must keep records that reasonably support each *Contribution Estimate*, each *
|
|
171
|
+
*You* must keep records that reasonably support each *Contribution Estimate*, including any share used to reduce it under section 5.5, each *Gross Income* figure, and the dates of any *Migration Period* for at least three (3) years after the end of the *Fiscal Year* that they apply to. No more than once in any twelve (12) month period, *Licensor* may ask in writing for the records that support a statement, and *You* must provide them within sixty (60) days of the request. *Licensor* will treat those records as confidential.
|
|
163
172
|
|
|
164
173
|
### 5.9 Disputes About the Usage Fee
|
|
165
|
-
If *Licensor* believes that a *Contribution Estimate*, a *
|
|
174
|
+
If *Licensor* believes that a *Contribution Estimate*, a *Gross Income* figure, or the dates of a *Migration Period* are not reasonable, *Licensor* will notify *You* in writing and explain why. *You* and *Licensor* will then negotiate in good faith for at least sixty (60) days to agree on a reasonable *Usage Fee*. If *You* and *Licensor* cannot agree, either party may resolve the dispute as described in section 8.
|
|
166
175
|
|
|
167
176
|
### 5.10 Fixed License Cost
|
|
168
177
|
For assurance of costs, *You* may disclose to *Licensor* how *You* *Use* *The Software* and the returns that *You* estimate *You* will derive from it, and negotiate a fixed license cost with *Licensor*. A fixed license cost, and any other terms that *You* and *Licensor* agree to, must be set out in a writing signed by both *You* and *Licensor* (a **Fixed License Agreement**).
|
{codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/execution.py
RENAMED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
of an individual workpacket.
|
|
6
6
|
|
|
7
7
|
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
|
|
9
|
+
.. deprecated::
|
|
10
|
+
This legacy function-based execution module is kept for compatibility and will be removed in
|
|
11
|
+
the next major version. Use :class:`ccai.taskplus.model.workflow.Workflow` and
|
|
12
|
+
:class:`ccai.taskplus.model.flowengine.FlowEngine` instead.
|
|
8
13
|
"""
|
|
9
14
|
|
|
10
15
|
__author__ = "Myron Walker"
|
|
@@ -15,6 +20,7 @@ __credits__ = []
|
|
|
15
20
|
from typing import Any, Dict, List
|
|
16
21
|
|
|
17
22
|
import os
|
|
23
|
+
import warnings
|
|
18
24
|
|
|
19
25
|
from ccai.xmodules.ximport import import_by_name
|
|
20
26
|
|
|
@@ -23,6 +29,12 @@ from ccai.errors.exceptions import ConfigurationError
|
|
|
23
29
|
from ccai.taskplus.model.task import Task
|
|
24
30
|
|
|
25
31
|
|
|
32
|
+
DEPRECATION_MESSAGE = (
|
|
33
|
+
"ccai.taskplus.execution is deprecated and will be removed in the next major version; "
|
|
34
|
+
"use ccai.taskplus.model.workflow.Workflow and ccai.taskplus.model.flowengine.FlowEngine instead."
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
26
38
|
class JumpContext:
|
|
27
39
|
def __init__(self) -> None:
|
|
28
40
|
self.on_failure_section = None
|
|
@@ -31,6 +43,8 @@ class JumpContext:
|
|
|
31
43
|
|
|
32
44
|
def execute_tasklist(logger, jump_context: JumpContext, parameters: dict, tasklist: List[Dict[str, Any]], ordinal_prefix: str=None, **kwargs):
|
|
33
45
|
|
|
46
|
+
warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2)
|
|
47
|
+
|
|
34
48
|
result_code = 0
|
|
35
49
|
|
|
36
50
|
for index, item in enumerate(tasklist):
|
|
@@ -104,7 +118,7 @@ def execute_tasklist(logger, jump_context: JumpContext, parameters: dict, taskli
|
|
|
104
118
|
tg_onfailure = tg_info.get("onfailure", None)
|
|
105
119
|
tg_onsuccess = tg_info.get("onsuccess", None)
|
|
106
120
|
|
|
107
|
-
tg_result = execute_tasklist(logger, jump_context, parameters, tg_items, ordinal_prefix=group_prefix)
|
|
121
|
+
tg_result = execute_tasklist(logger, jump_context, parameters, tg_items, ordinal_prefix=group_prefix, **kwargs)
|
|
108
122
|
if tg_result != 0:
|
|
109
123
|
result_code = 1
|
|
110
124
|
if tg_onfailure is not None:
|
|
@@ -120,6 +134,8 @@ def execute_tasklist(logger, jump_context: JumpContext, parameters: dict, taskli
|
|
|
120
134
|
|
|
121
135
|
def execute_workflow(logger, *, environment: dict, parameters: dict, workflow: list, **kwargs):
|
|
122
136
|
|
|
137
|
+
warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2)
|
|
138
|
+
|
|
123
139
|
# Publish the environment variables so they will take effect in the current
|
|
124
140
|
# process and any sub-processes lauched from this process
|
|
125
141
|
for key, val in environment.items():
|
|
@@ -127,6 +143,10 @@ def execute_workflow(logger, *, environment: dict, parameters: dict, workflow: l
|
|
|
127
143
|
|
|
128
144
|
jump_context = JumpContext()
|
|
129
145
|
|
|
130
|
-
|
|
146
|
+
# Task.execute requires the environment and the per-run flow state, so pass them to every task,
|
|
147
|
+
# including the tasks inside task groups.
|
|
148
|
+
flowstate = kwargs.pop("flowstate", {})
|
|
149
|
+
result_code = execute_tasklist(logger, jump_context, parameters, workflow, environment=environment,
|
|
150
|
+
flowstate=flowstate, **kwargs)
|
|
131
151
|
|
|
132
152
|
return result_code
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
__author__ = "Myron Walker"
|
|
3
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
4
|
+
__credits__ = []
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
12
|
+
|
|
13
|
+
from ccai.taskplus.model.flownode import FlowNode
|
|
14
|
+
from ccai.taskplus.model.task import Task
|
|
15
|
+
from ccai.taskplus.model.taskgroup import TaskGroup
|
|
16
|
+
from ccai.taskplus.model.workflow import Workflow, collect_node_names, full_node_name, resolve_jump_target
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class JumpContext:
|
|
20
|
+
def __init__(self):
|
|
21
|
+
# The full dotted name of the node an 'onfailure'/'onsuccess' jump is seeking, the
|
|
22
|
+
# task that jumped, and the full dotted names of every node in the flow.
|
|
23
|
+
self.seeking_node = None
|
|
24
|
+
self.seeking_from = None
|
|
25
|
+
self.node_names = []
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class FlowEngine:
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def evaluate_expression(self, if_expr: str, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any]) -> bool:
|
|
36
|
+
|
|
37
|
+
# ``flowstate`` is the per-run state threaded through ``process_flowitems``
|
|
38
|
+
# and updated by each task; an ``if:`` expression is evaluated against it
|
|
39
|
+
# (plus ``environment``/``parameters``) so conditional flow can reference
|
|
40
|
+
# accumulated state. (Previously this read the always-empty instance
|
|
41
|
+
# ``self._flowstate`` and was passed no per-run state at all.)
|
|
42
|
+
|
|
43
|
+
# YAML loads 'if: true' or 'if: 1' as a bool or a number rather than as
|
|
44
|
+
# expression text, so a literal value is taken for its truth value.
|
|
45
|
+
if isinstance(if_expr, (bool, int, float)):
|
|
46
|
+
eval_result = bool(if_expr)
|
|
47
|
+
elif isinstance(if_expr, str):
|
|
48
|
+
eval_result = eval(if_expr)
|
|
49
|
+
else:
|
|
50
|
+
errmsg = "An 'if' condition must be an expression string, a boolean or a number, got {} {!r}.".format(
|
|
51
|
+
type(if_expr).__name__, if_expr)
|
|
52
|
+
raise ConfigurationError(errmsg)
|
|
53
|
+
|
|
54
|
+
return eval_result
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def execute(self, workflow: Workflow) -> int:
|
|
58
|
+
|
|
59
|
+
result_code = 0
|
|
60
|
+
|
|
61
|
+
environment = workflow.environment
|
|
62
|
+
parameters = workflow.parameters
|
|
63
|
+
|
|
64
|
+
flowitems = workflow.flow
|
|
65
|
+
|
|
66
|
+
flowstate = {}
|
|
67
|
+
errors = []
|
|
68
|
+
jump_context = JumpContext()
|
|
69
|
+
jump_context.node_names = collect_node_names(flowitems)
|
|
70
|
+
|
|
71
|
+
# Publish the workflow 'environment' section so it takes effect in this process and in every
|
|
72
|
+
# sub-process the tasks launch, then restore the previous values once the flow has run.
|
|
73
|
+
previous_environment = {}
|
|
74
|
+
for env_name, env_value in environment.items():
|
|
75
|
+
previous_environment[env_name] = os.environ.get(env_name, None)
|
|
76
|
+
os.environ[env_name] = str(env_value)
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
self.process_flowitems(environment, parameters, flowstate, errors, flowitems, jump_context)
|
|
80
|
+
finally:
|
|
81
|
+
for env_name, prev_value in previous_environment.items():
|
|
82
|
+
if prev_value is None:
|
|
83
|
+
os.environ.pop(env_name, None)
|
|
84
|
+
else:
|
|
85
|
+
os.environ[env_name] = prev_value
|
|
86
|
+
|
|
87
|
+
if jump_context.seeking_node is not None:
|
|
88
|
+
# The jump target was never reached (unknown, or not after the task that jumped), so the
|
|
89
|
+
# rest of the flow was skipped; that must not be reported as success.
|
|
90
|
+
failure_info = {
|
|
91
|
+
"node": jump_context.seeking_from,
|
|
92
|
+
"unreached_target": jump_context.seeking_node,
|
|
93
|
+
}
|
|
94
|
+
errors.append(failure_info)
|
|
95
|
+
|
|
96
|
+
if len(errors) > 0:
|
|
97
|
+
result_code = 1
|
|
98
|
+
|
|
99
|
+
return result_code
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def process_flowitems(self, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any], errors: List,
|
|
103
|
+
flowitems: List[FlowNode], jump_context: JumpContext, name_prefix: str = ""):
|
|
104
|
+
|
|
105
|
+
for fitem in flowitems:
|
|
106
|
+
|
|
107
|
+
node_label = fitem.label
|
|
108
|
+
node_name = full_node_name(name_prefix, node_label)
|
|
109
|
+
|
|
110
|
+
# If we are seeking a specific node, skip any nodes that are not that node; descend into a
|
|
111
|
+
# task group that holds the node being sought (the group's 'if' does not apply to the jump).
|
|
112
|
+
if jump_context.seeking_node is not None:
|
|
113
|
+
if jump_context.seeking_node == node_name:
|
|
114
|
+
jump_context.seeking_node = None
|
|
115
|
+
jump_context.seeking_from = None
|
|
116
|
+
elif isinstance(fitem, TaskGroup) and jump_context.seeking_node.startswith(node_name + "."):
|
|
117
|
+
self.process_flowitems(environment, parameters, flowstate, errors, fitem.items,
|
|
118
|
+
jump_context, name_prefix=node_name)
|
|
119
|
+
continue
|
|
120
|
+
else:
|
|
121
|
+
continue
|
|
122
|
+
|
|
123
|
+
include_node = True
|
|
124
|
+
if fitem.if_expr is not None:
|
|
125
|
+
include_node = self.evaluate_expression(fitem.if_expr, environment, parameters, flowstate)
|
|
126
|
+
|
|
127
|
+
if include_node:
|
|
128
|
+
if isinstance(fitem, Task):
|
|
129
|
+
|
|
130
|
+
task_result = fitem.execute(environment, parameters, flowstate)
|
|
131
|
+
if task_result != 0:
|
|
132
|
+
if fitem.onfailure is not None:
|
|
133
|
+
# The failure is routed to a handler node -- treat it
|
|
134
|
+
# as handled and let the handler decide the outcome.
|
|
135
|
+
self._begin_jump(jump_context, node_name, fitem.onfailure)
|
|
136
|
+
else:
|
|
137
|
+
# An unhandled task failure must surface so that
|
|
138
|
+
# execute() returns a non-zero code (CI gating).
|
|
139
|
+
failure_info = {
|
|
140
|
+
"node": node_label,
|
|
141
|
+
"result_code": task_result,
|
|
142
|
+
}
|
|
143
|
+
errors.append(failure_info)
|
|
144
|
+
elif fitem.onsuccess is not None:
|
|
145
|
+
self._begin_jump(jump_context, node_name, fitem.onsuccess)
|
|
146
|
+
|
|
147
|
+
elif isinstance(fitem, TaskGroup):
|
|
148
|
+
|
|
149
|
+
group_items = fitem.items
|
|
150
|
+
|
|
151
|
+
self.process_flowitems(environment, parameters, flowstate, errors, group_items,
|
|
152
|
+
jump_context, name_prefix=node_name)
|
|
153
|
+
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _begin_jump(self, jump_context: JumpContext, source_name: str, target: str):
|
|
158
|
+
"""
|
|
159
|
+
Starts seeking the node an ``onfailure`` / ``onsuccess`` target names. A task
|
|
160
|
+
inside a task group is targeted by its full dotted name (``group.task``); a
|
|
161
|
+
sibling inside the same group can also be named by its label. A target that
|
|
162
|
+
names no node is sought as given, so it stays pending and fails the run.
|
|
163
|
+
|
|
164
|
+
:param jump_context: The jump state of the run.
|
|
165
|
+
:param source_name: The full dotted name of the task that jumps.
|
|
166
|
+
:param target: The ``onfailure`` / ``onsuccess`` value of the task.
|
|
167
|
+
"""
|
|
168
|
+
resolved_name = resolve_jump_target(jump_context.node_names, source_name, target)
|
|
169
|
+
if resolved_name is None:
|
|
170
|
+
resolved_name = target
|
|
171
|
+
|
|
172
|
+
jump_context.seeking_node = resolved_name
|
|
173
|
+
jump_context.seeking_from = source_name
|
|
174
|
+
return
|
|
175
|
+
|
|
@@ -4,7 +4,7 @@ __author__ = "Myron Walker"
|
|
|
4
4
|
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
5
5
|
__credits__ = []
|
|
6
6
|
|
|
7
|
-
from typing import Any, Dict, List
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
import logging
|
|
@@ -29,6 +29,76 @@ from ccai.taskplus.model.taskgroup import TaskGroup
|
|
|
29
29
|
logger = logging.getLogger()
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def full_node_name(name_prefix: str, label: str) -> str:
|
|
33
|
+
"""
|
|
34
|
+
Builds the full dotted name of a flow node: the labels of its enclosing task
|
|
35
|
+
groups and its own label joined with ``.`` (a top-level node's full name is
|
|
36
|
+
its label).
|
|
37
|
+
|
|
38
|
+
:param name_prefix: The full dotted name of the enclosing task group, or ``""``
|
|
39
|
+
for a top-level node.
|
|
40
|
+
:param label: The label of the node.
|
|
41
|
+
|
|
42
|
+
:returns: The full dotted name of the node.
|
|
43
|
+
"""
|
|
44
|
+
rtnval = label
|
|
45
|
+
if len(name_prefix) > 0:
|
|
46
|
+
rtnval = f"{name_prefix}.{label}"
|
|
47
|
+
return rtnval
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def collect_node_names(flow_items: List[FlowNode], name_prefix: str = "") -> List[str]:
|
|
51
|
+
"""
|
|
52
|
+
Collects the full dotted names of every node in a flow, including the nodes
|
|
53
|
+
inside task groups.
|
|
54
|
+
|
|
55
|
+
:param flow_items: The flow nodes to walk.
|
|
56
|
+
:param name_prefix: The full dotted name of the task group that holds ``flow_items``.
|
|
57
|
+
|
|
58
|
+
:returns: The full dotted names in flow order.
|
|
59
|
+
"""
|
|
60
|
+
rtnval = []
|
|
61
|
+
|
|
62
|
+
for fitem in flow_items:
|
|
63
|
+
node_name = full_node_name(name_prefix, fitem.label)
|
|
64
|
+
rtnval.append(node_name)
|
|
65
|
+
|
|
66
|
+
if isinstance(fitem, TaskGroup):
|
|
67
|
+
rtnval.extend(collect_node_names(fitem.items, name_prefix=node_name))
|
|
68
|
+
|
|
69
|
+
return rtnval
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def resolve_jump_target(node_names: List[str], source_name: str, target: str) -> Optional[str]:
|
|
73
|
+
"""
|
|
74
|
+
Resolves an ``onfailure`` / ``onsuccess`` target to the full dotted name of a
|
|
75
|
+
flow node. The target is looked up relative to the task groups that enclose
|
|
76
|
+
the source task, innermost first, ending with the top level; so a top-level
|
|
77
|
+
node or a task inside a group is found by its full dotted name
|
|
78
|
+
(``group.task``) from anywhere, and a sibling inside the same group is also
|
|
79
|
+
found by its own label.
|
|
80
|
+
|
|
81
|
+
:param node_names: The full dotted names of every node in the flow.
|
|
82
|
+
:param source_name: The full dotted name of the task that jumps.
|
|
83
|
+
:param target: The ``onfailure`` / ``onsuccess`` value of the task.
|
|
84
|
+
|
|
85
|
+
:returns: The full dotted name of the target node, or ``None`` if no node matches.
|
|
86
|
+
"""
|
|
87
|
+
rtnval = None
|
|
88
|
+
|
|
89
|
+
scope_parts = source_name.split(".")[:-1]
|
|
90
|
+
while True:
|
|
91
|
+
candidate = full_node_name(".".join(scope_parts), target)
|
|
92
|
+
if candidate in node_names:
|
|
93
|
+
rtnval = candidate
|
|
94
|
+
break
|
|
95
|
+
if len(scope_parts) == 0:
|
|
96
|
+
break
|
|
97
|
+
scope_parts.pop()
|
|
98
|
+
|
|
99
|
+
return rtnval
|
|
100
|
+
|
|
101
|
+
|
|
32
102
|
class Workflow:
|
|
33
103
|
|
|
34
104
|
def __init__(self, environment: Dict[str, str], parameters: Dict[str, Any], flow: List[FlowNode]):
|
|
@@ -74,10 +144,39 @@ class Workflow:
|
|
|
74
144
|
|
|
75
145
|
flow_items = cls._process_flow_info_items(fnode_info_items)
|
|
76
146
|
|
|
147
|
+
cls._validate_jump_targets(flow_items, collect_node_names(flow_items))
|
|
148
|
+
|
|
77
149
|
workflow = Workflow(environment, parameters, flow_items)
|
|
78
150
|
|
|
79
151
|
return workflow
|
|
80
152
|
|
|
153
|
+
@classmethod
|
|
154
|
+
def _validate_jump_targets(cls, flow_items: List[FlowNode], node_names: List[str], name_prefix: str = ""):
|
|
155
|
+
"""
|
|
156
|
+
Checks that every ``onfailure`` / ``onsuccess`` target names a node of the flow.
|
|
157
|
+
|
|
158
|
+
:param flow_items: The flow nodes to check.
|
|
159
|
+
:param node_names: The full dotted names of every node in the flow.
|
|
160
|
+
:param name_prefix: The full dotted name of the task group that holds ``flow_items``.
|
|
161
|
+
|
|
162
|
+
:raises ConfigurationError: If a target does not resolve to a node of the flow.
|
|
163
|
+
"""
|
|
164
|
+
for fitem in flow_items:
|
|
165
|
+
node_name = full_node_name(name_prefix, fitem.label)
|
|
166
|
+
|
|
167
|
+
if isinstance(fitem, Task):
|
|
168
|
+
for jump_field, target in (("onfailure", fitem.onfailure), ("onsuccess", fitem.onsuccess)):
|
|
169
|
+
if target is not None and resolve_jump_target(node_names, node_name, target) is None:
|
|
170
|
+
errmsg = ("The {} target {!r} of task {!r} does not name a node of the flow; a task "
|
|
171
|
+
"inside a task group is named by its full dotted name (group.task).").format(
|
|
172
|
+
jump_field, target, node_name)
|
|
173
|
+
raise ConfigurationError(errmsg)
|
|
174
|
+
|
|
175
|
+
elif isinstance(fitem, TaskGroup):
|
|
176
|
+
cls._validate_jump_targets(fitem.items, node_names, name_prefix=node_name)
|
|
177
|
+
|
|
178
|
+
return
|
|
179
|
+
|
|
81
180
|
@classmethod
|
|
82
181
|
def _process_flow_info_items(cls, fnode_info_items: List[Dict[str, Any]], ordinal_prefix: str="") -> List[FlowNode]:
|
|
83
182
|
|
|
@@ -18,6 +18,7 @@ import os
|
|
|
18
18
|
import subprocess
|
|
19
19
|
|
|
20
20
|
from ccai.taskplus.model.task import Task
|
|
21
|
+
from ccai.taskplus.tasks.outputtext import decode_output_text
|
|
21
22
|
|
|
22
23
|
class CreateEnvironment(Task):
|
|
23
24
|
"""
|
|
@@ -70,10 +71,23 @@ class CreateEnvironment(Task):
|
|
|
70
71
|
exit_code = proc.wait()
|
|
71
72
|
|
|
72
73
|
if exit_code == 0:
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
try:
|
|
75
|
+
var_val = stdout.decode().strip()
|
|
76
|
+
os.environ[var_name] = var_val
|
|
77
|
+
except UnicodeDecodeError as decode_err:
|
|
78
|
+
# A value that does not decode cleanly is not set; it is reported as a failed
|
|
79
|
+
# variable like a failing command, rather than aborting the whole workflow.
|
|
80
|
+
errmsg_lines = [
|
|
81
|
+
"Error creating environment variable '{}': the output is not valid UTF-8 ({}).".format(
|
|
82
|
+
var_name, decode_err),
|
|
83
|
+
"COMMAND: {}".format(var_command),
|
|
84
|
+
"STDOUT: {}".format(decode_output_text(stdout))
|
|
85
|
+
]
|
|
86
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
87
|
+
self._logger.error(errmsg)
|
|
88
|
+
status_code = 1
|
|
75
89
|
else:
|
|
76
|
-
stderr_text = stderr
|
|
90
|
+
stderr_text = decode_output_text(stderr)
|
|
77
91
|
errmsg_lines = [
|
|
78
92
|
"Error creating environment variable '{}' with:".format(var_name),
|
|
79
93
|
"COMMAND: {}".format(var_command),
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: shellscript
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A module that provides the EmbeddedPython task class which implements
|
|
5
|
+
the execution of inline python based tasks in a workpacket.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.taskplus.model.task import Task
|
|
20
|
+
|
|
21
|
+
class EmbeddedPython(Task):
|
|
22
|
+
"""
|
|
23
|
+
A task class that is used to setup the running of an embedded python script
|
|
24
|
+
in the context of the automation worker.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, ordinal: str, label: str, task_info: dict, logger):
|
|
28
|
+
super(EmbeddedPython, self).__init__(ordinal, label, task_info, logger)
|
|
29
|
+
self._script = task_info["script"]
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def script(self) -> List[str]:
|
|
34
|
+
return self._script
|
|
35
|
+
|
|
36
|
+
def perform_task(self, environment: Dict[str, str], parameters: Optional[Dict[str, Any]], flowstate: Dict[str, Any]) -> int:
|
|
37
|
+
|
|
38
|
+
script_content = os.linesep.join(self._script)
|
|
39
|
+
|
|
40
|
+
exit_status = 0
|
|
41
|
+
|
|
42
|
+
# Execute the inline python script in a single namespace that holds the module globals
|
|
43
|
+
# and the task arguments. Separate globals and locals dictionaries would run the script
|
|
44
|
+
# like a class body, so functions defined by the script could not see its own imports
|
|
45
|
+
# and variables.
|
|
46
|
+
script_namespace = dict(globals())
|
|
47
|
+
script_namespace["self"] = self
|
|
48
|
+
script_namespace["environment"] = environment
|
|
49
|
+
script_namespace["parameters"] = parameters
|
|
50
|
+
script_namespace["flowstate"] = flowstate
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
script_code = compile(script_content, "<embedded-python %s>" % self._label, "exec")
|
|
54
|
+
exec(script_code, script_namespace)
|
|
55
|
+
except SystemExit as sexit:
|
|
56
|
+
# A workflow step is the application boundary for its script: 'sys.exit()' ends the
|
|
57
|
+
# script, never the process hosting the workflow. No code or 0 is success, a non-zero
|
|
58
|
+
# code is the task's exit status and a message is a failure (exit status 1) that is
|
|
59
|
+
# recorded in the task log, as the interpreter would print it. ConfigurationError and
|
|
60
|
+
# SemanticError are not SystemExit and keep propagating.
|
|
61
|
+
exit_code = sexit.code
|
|
62
|
+
if exit_code is None or exit_code == 0:
|
|
63
|
+
exit_status = 0
|
|
64
|
+
elif isinstance(exit_code, int):
|
|
65
|
+
exit_status = int(exit_code)
|
|
66
|
+
self._logger.error("The embedded python script of task %r (%s) exited with status %d." % (
|
|
67
|
+
self._label, self._ordinal, exit_code))
|
|
68
|
+
else:
|
|
69
|
+
exit_status = 1
|
|
70
|
+
self._logger.error("The embedded python script of task %r (%s) exited with: %s" % (
|
|
71
|
+
self._label, self._ordinal, exit_code))
|
|
72
|
+
except Exception:
|
|
73
|
+
# The task reports a failing script through its exit status; log the traceback so
|
|
74
|
+
# the cause of the failure is visible in the task log.
|
|
75
|
+
self._logger.exception("The embedded python script of task %r (%s) failed." % (self._label, self._ordinal))
|
|
76
|
+
exit_status = 1
|
|
77
|
+
|
|
78
|
+
return exit_status
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: outputtext
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A module that provides the helper used by the command based tasks to turn
|
|
5
|
+
the captured output of a sub-process into text for the task log.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def decode_output_text(output: bytes) -> str:
|
|
16
|
+
"""
|
|
17
|
+
Decodes the captured output of a sub-process for logging. Bytes that are not
|
|
18
|
+
valid UTF-8 (binary output, file names or localized messages in another code
|
|
19
|
+
page) are replaced rather than raising, so the exit status of the command is
|
|
20
|
+
still reported.
|
|
21
|
+
|
|
22
|
+
:param output: The bytes captured from the stdout or stderr of a sub-process.
|
|
23
|
+
|
|
24
|
+
:returns: The decoded text.
|
|
25
|
+
"""
|
|
26
|
+
rtnval = output.decode("utf-8", errors="replace")
|
|
27
|
+
return rtnval
|
|
@@ -20,6 +20,7 @@ import subprocess
|
|
|
20
20
|
from ccai.xmodules.xformatting import indent_lines
|
|
21
21
|
|
|
22
22
|
from ccai.taskplus.model.task import Task
|
|
23
|
+
from ccai.taskplus.tasks.outputtext import decode_output_text
|
|
23
24
|
|
|
24
25
|
class RunCommand(Task):
|
|
25
26
|
"""
|
|
@@ -48,8 +49,8 @@ class RunCommand(Task):
|
|
|
48
49
|
stdout, stderr = proc.communicate()
|
|
49
50
|
exit_code = proc.wait()
|
|
50
51
|
|
|
51
|
-
stdout = stdout
|
|
52
|
-
stderr = stderr
|
|
52
|
+
stdout = decode_output_text(stdout)
|
|
53
|
+
stderr = decode_output_text(stderr)
|
|
53
54
|
|
|
54
55
|
log_msg_lines = [
|
|
55
56
|
"RESULT CODE: %d" % exit_code,
|
|
@@ -16,6 +16,7 @@ __credits__ = []
|
|
|
16
16
|
from typing import Any, Dict, Optional
|
|
17
17
|
|
|
18
18
|
import os
|
|
19
|
+
import shlex
|
|
19
20
|
import stat
|
|
20
21
|
import subprocess
|
|
21
22
|
|
|
@@ -23,6 +24,7 @@ from ccai.thisapp.paths import get_temporary_file
|
|
|
23
24
|
from ccai.xmodules.xformatting import indent_lines
|
|
24
25
|
|
|
25
26
|
from ccai.taskplus.model.task import Task
|
|
27
|
+
from ccai.taskplus.tasks.outputtext import decode_output_text
|
|
26
28
|
|
|
27
29
|
class ShellScript(Task):
|
|
28
30
|
"""
|
|
@@ -43,7 +45,11 @@ class ShellScript(Task):
|
|
|
43
45
|
|
|
44
46
|
def perform_task(self, environment: Dict[str, str], parameters: Optional[Dict[str, Any]], flowstate: Dict[str, Any]) -> int:
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
# The 'script' entry is either a list of lines or a YAML block string that is used as-is.
|
|
49
|
+
if isinstance(self._script, str):
|
|
50
|
+
script_content = self._script
|
|
51
|
+
else:
|
|
52
|
+
script_content = os.linesep.join(self._script)
|
|
47
53
|
|
|
48
54
|
# The platform shell only runs script files it recognizes, so the suffix has to match the shell.
|
|
49
55
|
if os.name == "nt":
|
|
@@ -60,13 +66,22 @@ class ShellScript(Task):
|
|
|
60
66
|
|
|
61
67
|
os.chmod(tempfile, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
|
|
62
68
|
|
|
63
|
-
# Hand the script path to the shell as a single string so it is not re-quoted on Windows
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
# Hand the script path to the shell as a single string so it is not re-quoted on Windows, but
|
|
70
|
+
# quote it for that shell so an output directory with a space or other metacharacter still works.
|
|
71
|
+
if os.name == "nt":
|
|
72
|
+
script_command = subprocess.list2cmdline([tempfile])
|
|
73
|
+
else:
|
|
74
|
+
script_command = shlex.quote(tempfile)
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
proc = subprocess.Popen(script_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
78
|
+
stdout, stderr = proc.communicate()
|
|
79
|
+
exit_code = proc.wait()
|
|
80
|
+
finally:
|
|
81
|
+
os.remove(tempfile)
|
|
67
82
|
|
|
68
|
-
stdout_text = stdout
|
|
69
|
-
stderr_text = stderr
|
|
83
|
+
stdout_text = decode_output_text(stdout)
|
|
84
|
+
stderr_text = decode_output_text(stderr)
|
|
70
85
|
|
|
71
86
|
log_msg_script = [
|
|
72
87
|
"RESULT CODE: %d" % exit_code,
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
__author__ = "Myron Walker"
|
|
3
|
-
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
4
|
-
__credits__ = []
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
from typing import Any, Dict, List
|
|
8
|
-
|
|
9
|
-
from ccai.taskplus.model.flownode import FlowNode
|
|
10
|
-
from ccai.taskplus.model.task import Task
|
|
11
|
-
from ccai.taskplus.model.taskgroup import TaskGroup
|
|
12
|
-
from ccai.taskplus.model.workflow import Workflow
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class JumpContext:
|
|
16
|
-
def __init__(self):
|
|
17
|
-
self.seeking_node = None
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class FlowEngine:
|
|
22
|
-
|
|
23
|
-
def __init__(self):
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def evaluate_expression(self, if_expr: str, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any]) -> bool:
|
|
28
|
-
|
|
29
|
-
# ``flowstate`` is the per-run state threaded through ``process_flowitems``
|
|
30
|
-
# and updated by each task; an ``if:`` expression is evaluated against it
|
|
31
|
-
# (plus ``environment``/``parameters``) so conditional flow can reference
|
|
32
|
-
# accumulated state. (Previously this read the always-empty instance
|
|
33
|
-
# ``self._flowstate`` and was passed no per-run state at all.)
|
|
34
|
-
eval_result = eval(if_expr)
|
|
35
|
-
|
|
36
|
-
return eval_result
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def execute(self, workflow: Workflow) -> int:
|
|
40
|
-
|
|
41
|
-
result_code = 0
|
|
42
|
-
|
|
43
|
-
environment = workflow.environment
|
|
44
|
-
parameters = workflow.parameters
|
|
45
|
-
|
|
46
|
-
flowitems = workflow.flow
|
|
47
|
-
|
|
48
|
-
flowstate = {}
|
|
49
|
-
errors = []
|
|
50
|
-
jump_context = JumpContext()
|
|
51
|
-
|
|
52
|
-
self.process_flowitems(environment, parameters, flowstate, errors, flowitems, jump_context)
|
|
53
|
-
|
|
54
|
-
if len(errors) > 0:
|
|
55
|
-
result_code = 1
|
|
56
|
-
|
|
57
|
-
return result_code
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def process_flowitems(self, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any], errors: List,
|
|
61
|
-
flowitems: List[FlowNode], jump_context: JumpContext):
|
|
62
|
-
|
|
63
|
-
for fitem in flowitems:
|
|
64
|
-
|
|
65
|
-
node_label = fitem.label
|
|
66
|
-
|
|
67
|
-
# If we are seeking a specific node, skip any nodes that are not that node
|
|
68
|
-
if jump_context.seeking_node is not None:
|
|
69
|
-
if jump_context.seeking_node != node_label:
|
|
70
|
-
continue
|
|
71
|
-
else:
|
|
72
|
-
jump_context.seeking_node = None
|
|
73
|
-
|
|
74
|
-
include_node = True
|
|
75
|
-
if fitem.if_expr is not None:
|
|
76
|
-
include_node = self.evaluate_expression(fitem.if_expr, environment, parameters, flowstate)
|
|
77
|
-
|
|
78
|
-
if include_node:
|
|
79
|
-
if isinstance(fitem, Task):
|
|
80
|
-
|
|
81
|
-
task_result = fitem.execute(environment, parameters, flowstate)
|
|
82
|
-
if task_result != 0:
|
|
83
|
-
if fitem.onfailure is not None:
|
|
84
|
-
# The failure is routed to a handler node -- treat it
|
|
85
|
-
# as handled and let the handler decide the outcome.
|
|
86
|
-
jump_context.seeking_node = fitem.onfailure
|
|
87
|
-
else:
|
|
88
|
-
# An unhandled task failure must surface so that
|
|
89
|
-
# execute() returns a non-zero code (CI gating).
|
|
90
|
-
failure_info = {
|
|
91
|
-
"node": node_label,
|
|
92
|
-
"result_code": task_result,
|
|
93
|
-
}
|
|
94
|
-
errors.append(failure_info)
|
|
95
|
-
elif fitem.onsuccess is not None:
|
|
96
|
-
jump_context.seeking_node = fitem.onsuccess
|
|
97
|
-
|
|
98
|
-
elif isinstance(fitem, TaskGroup):
|
|
99
|
-
|
|
100
|
-
group_items = fitem.items
|
|
101
|
-
|
|
102
|
-
self.process_flowitems(environment, parameters, flowstate, errors, group_items,
|
|
103
|
-
jump_context)
|
|
104
|
-
|
|
105
|
-
return
|
|
106
|
-
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
.. module:: shellscript
|
|
3
|
-
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
-
:synopsis: A module that provides the EmbeddedPython task class which implements
|
|
5
|
-
the execution of inline python based tasks in a workpacket.
|
|
6
|
-
|
|
7
|
-
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
__author__ = "Myron Walker"
|
|
11
|
-
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
-
__credits__ = []
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
from typing import Any, Dict, List, Optional
|
|
16
|
-
|
|
17
|
-
import os
|
|
18
|
-
|
|
19
|
-
from ccai.taskplus.model.task import Task
|
|
20
|
-
|
|
21
|
-
class EmbeddedPython(Task):
|
|
22
|
-
"""
|
|
23
|
-
A task class that is used to setup the running of an embedded python script
|
|
24
|
-
in the context of the automation worker.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
def __init__(self, ordinal: str, label: str, task_info: dict, logger):
|
|
28
|
-
super(EmbeddedPython, self).__init__(ordinal, label, task_info, logger)
|
|
29
|
-
self._script = task_info["script"]
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def script(self) -> List[str]:
|
|
34
|
-
return self._script
|
|
35
|
-
|
|
36
|
-
def perform_task(self, environment: Dict[str, str], parameters: Optional[Dict[str, Any]], flowstate: Dict[str, Any]) -> int:
|
|
37
|
-
|
|
38
|
-
script_content = os.linesep.join(self._script)
|
|
39
|
-
|
|
40
|
-
exit_status = 0
|
|
41
|
-
|
|
42
|
-
try:
|
|
43
|
-
# Execute the inline python script in the context of the current
|
|
44
|
-
# globals and locals.
|
|
45
|
-
exec(script_content, globals(), locals())
|
|
46
|
-
except Exception:
|
|
47
|
-
exit_status = 1
|
|
48
|
-
|
|
49
|
-
return exit_status
|
|
File without changes
|
{codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{codecraftai_taskplus-1.3.1 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|